Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

README, docker: add quick start #181

Merged
merged 7 commits into from
Mar 7, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ backupmeta
*.ngo
*.coverprofile
coverage.txt
docker/data/
docker/logs/
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,44 @@ Notice BR supports building with Go version `Go >= 1.13`

When BR is built successfully, you can find binary in the `bin` directory.

## Get started in 2 minutes!
kennytm marked this conversation as resolved.
Show resolved Hide resolved

```sh
# Start TiDB cluster
docker-compose -f docker-compose.yaml rm -s -v && \
docker-compose -f docker-compose.yaml build && \
docker-compose -f docker-compose.yaml up --remove-orphans

# Attch to control container runs BR
kennytm marked this conversation as resolved.
Show resolved Hide resolved
docker exec -it br_control_1 bash

# Load testing data to TiDB
cd /go/src/github.com/pingcap/go-ycsb && \
make && \
bin/go-ycsb load mysql -p workload=core \
-p mysql.host=tidb -p mysql.port=4000 -p mysql.user=root \
-p recordcount=100000 -p threadcount=100

# How many rows do we get?
mysql -uroot -htidb -P4000 -E -e "SELECT COUNT(*) FROM test.usertable"
kennytm marked this conversation as resolved.
Show resolved Hide resolved

# Build BR and backup!
cd /go/src/github.com/pingcap/br && \
make release && \
bin/br backup full --pd pd0:2379 --storage "local:///data/backup/full" \
--log-file "/logs/br_backup.log"

# Let's drop database.
mysql -uroot -htidb -P4000 -E -e "DROP DATABASE test; SHOW DATABASES;"

# Restore!
bin/br restore full --pd pd0:2379 --storage "local:///data/backup/full" \
--log-file "/logs/br_restore.log"

# How many rows do we get again?
mysql -uroot -htidb -P4000 -E -e "SELECT COUNT(*) FROM test.usertable"
```

## Contributing

Contributions are welcomed and greatly appreciated. See [CONTRIBUTING](./CONTRIBUTING.md)
Expand Down
15 changes: 9 additions & 6 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,19 @@ func Init(cmd *cobra.Command) (err error) {
err = e
return
}
tidbLogCfg := logutil.LogConfig{}
if len(slowLogFilename) != 0 {
slowCfg := logutil.LogConfig{SlowQueryFile: slowLogFilename}
e = logutil.InitLogger(&slowCfg)
if e != nil {
err = e
return
}
tidbLogCfg.SlowQueryFile = slowLogFilename
} else {
// Hack! Discard slow log by setting log level to PanicLevel
logutil.SlowQueryLogger.SetLevel(logrus.PanicLevel)
// Disable annoying TiDB Log.
tidbLogCfg.Level = "fatal"
kennytm marked this conversation as resolved.
Show resolved Hide resolved
}
e = logutil.InitLogger(&tidbLogCfg)
if e != nil {
err = e
return
}

// Initialize the pprof server.
Expand Down
194 changes: 194 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
---
# Source: tidb-docker-compose/templates/docker-compose.yml
version: '2.1'

services:
control:
image: control:latest
build:
context: .
dockerfile: ./docker/Dockerfile
volumes:
- ./docker/data:/data
- ./docker/logs:/logs
command: -c "/usr/bin/tail -f /dev/null"
depends_on:
- "tidb"
restart: on-failure

pd0:
image: pingcap/pd:latest
ports:
- "2379"
volumes:
- ./docker/config/pd.toml:/pd.toml:ro
- ./docker/data:/data
- ./docker/logs:/logs
command:
- --name=pd0
- --client-urls=http://0.0.0.0:2379
- --peer-urls=http://0.0.0.0:2380
- --advertise-client-urls=http://pd0:2379
- --advertise-peer-urls=http://pd0:2380
- --initial-cluster=pd0=http://pd0:2380
- --data-dir=/data/pd0
- --config=/pd.toml
- --log-file=/logs/pd0.log
# sysctls:
# net.core.somaxconn: 32768
# ulimits:
# nofile:
# soft: 1000000
# hard: 1000000
restart: on-failure

tikv0:
image: pingcap/tikv:latest
volumes:
- ./docker/config/tikv.toml:/tikv.toml:ro
- ./docker/data:/data
- ./docker/logs:/logs
command:
- --addr=0.0.0.0:20160
- --advertise-addr=tikv0:20160
- --data-dir=/data/tikv0
- --pd=pd0:2379
- --config=/tikv.toml
- --log-file=/logs/tikv0.log
depends_on:
- "pd0"
# sysctls:
# net.core.somaxconn: 32768
# ulimits:
# nofile:
# soft: 1000000
# hard: 1000000
restart: on-failure

tikv1:
image: pingcap/tikv:latest
volumes:
- ./docker/config/tikv.toml:/tikv.toml:ro
- ./docker/data:/data
- ./docker/logs:/logs
command:
- --addr=0.0.0.0:20160
- --advertise-addr=tikv1:20160
- --data-dir=/data/tikv1
- --pd=pd0:2379
- --config=/tikv.toml
- --log-file=/logs/tikv1.log
depends_on:
- "pd0"
# sysctls:
# net.core.somaxconn: 32768
# ulimits:
# nofile:
# soft: 1000000
# hard: 1000000
restart: on-failure

tikv2:
image: pingcap/tikv:latest
volumes:
- ./docker/config/tikv.toml:/tikv.toml:ro
- ./docker/data:/data
- ./docker/logs:/logs
command:
- --addr=0.0.0.0:20160
- --advertise-addr=tikv2:20160
- --data-dir=/data/tikv2
- --pd=pd0:2379
- --config=/tikv.toml
- --log-file=/logs/tikv2.log
depends_on:
- "pd0"
# sysctls:
# net.core.somaxconn: 32768
# ulimits:
# nofile:
# soft: 1000000
# hard: 1000000
restart: on-failure

tikv3:
image: pingcap/tikv:latest
volumes:
- ./docker/config/tikv.toml:/tikv.toml:ro
- ./docker/data:/data
- ./docker/logs:/logs
command:
- --addr=0.0.0.0:20160
- --advertise-addr=tikv3:20160
- --data-dir=/data/tikv3
- --pd=pd0:2379
- --config=/tikv.toml
- --log-file=/logs/tikv3.log
depends_on:
- "pd0"
# sysctls:
# net.core.somaxconn: 32768
# ulimits:
# nofile:
# soft: 1000000
# hard: 1000000
restart: on-failure

tikv4:
image: pingcap/tikv:latest
volumes:
- ./docker/config/tikv.toml:/tikv.toml:ro
- ./docker/data:/data
- ./docker/logs:/logs
command:
- --addr=0.0.0.0:20160
- --advertise-addr=tikv4:20160
- --data-dir=/data/tikv4
- --pd=pd0:2379
- --config=/tikv.toml
- --log-file=/logs/tikv4.log
depends_on:
- "pd0"
# sysctls:
# net.core.somaxconn: 32768
# ulimits:
# nofile:
# soft: 1000000
# hard: 1000000
restart: on-failure

tidb:
image: pingcap/tidb:latest
ports:
- "4000:4000"
- "10080:10080"
volumes:
- ./docker/config/tidb.toml:/tidb.toml:ro
- ./docker/logs:/logs
command:
- --store=tikv
- --path=pd0:2379
- --config=/tidb.toml
- --log-file=/logs/tidb.log
- --advertise-address=tidb
depends_on:
- "tikv0"
- "tikv1"
- "tikv2"
- "tikv3"
- "tikv4"
# sysctls:
# net.core.somaxconn: 32768
# ulimits:
# nofile:
# soft: 1000000
# hard: 1000000
restart: on-failure

tidb-vision:
image: pingcap/tidb-vision:latest
environment:
PD_ENDPOINT: pd0:2379
ports:
- "8010:8010"
restart: on-failure
17 changes: 17 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM golang:1.13.8-buster

RUN apt-get update && apt-get install -y --no-install-recommends \
git \
curl \
vim \
less \
default-mysql-client \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /go/src/github.com/pingcap/br
COPY . .

# For loading data to TiDB
RUN git clone https://github.com/pingcap/go-ycsb.git /go/src/github.com/pingcap/go-ycsb
kennytm marked this conversation as resolved.
Show resolved Hide resolved

ENTRYPOINT ["/bin/bash"]
81 changes: 81 additions & 0 deletions docker/config/pd.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# PD Configuration.

name = "pd"
data-dir = "default.pd"

client-urls = "http://127.0.0.1:2379"
# if not set, use ${client-urls}
advertise-client-urls = ""

peer-urls = "http://127.0.0.1:2380"
# if not set, use ${peer-urls}
advertise-peer-urls = ""

initial-cluster = "pd=http://127.0.0.1:2380"
initial-cluster-state = "new"

lease = 3
tso-save-interval = "3s"

[security]
# Path of file that contains list of trusted SSL CAs. if set, following four settings shouldn't be empty
cacert-path = ""
# Path of file that contains X509 certificate in PEM format.
cert-path = ""
# Path of file that contains X509 key in PEM format.
key-path = ""

[log]
level = "info"

# log format, one of json, text, console
#format = "text"

# disable automatic timestamps in output
#disable-timestamp = false

# file logging
[log.file]
#filename = ""
# max log file size in MB
#max-size = 300
# max log file keep days
#max-days = 28
# maximum number of old log files to retain
#max-backups = 7
# rotate log by day
#log-rotate = true

[schedule]
max-merge-region-size = 0
max-merge-region-key = 0
split-merge-interval = "1h"
max-snapshot-count = 3
max-pending-peer-count = 16
max-store-down-time = "30m"
leader-schedule-limit = 4
region-schedule-limit = 4
replica-schedule-limit = 8
merge-schedule-limit = 8
tolerant-size-ratio = 5.0

# customized schedulers, the format is as below
# if empty, it will use balance-leader, balance-region, hot-region as default
# [[schedule.schedulers]]
# type = "evict-leader"
# args = ["1"]

[replication]
# The number of replicas for each region.
max-replicas = 3
# The label keys specified the location of a store.
# The placement priorities is implied by the order of label keys.
# For example, ["zone", "rack"] means that we should place replicas to
# different zones first, then to different racks if we don't have enough zones.
location-labels = []

[label-property]
# Do not assign region leaders to stores that have these tags.
# [[label-property.reject-leader]]
# key = "zone"
# value = "cn1
Loading