-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: husharp <[email protected]>
- Loading branch information
Showing
21 changed files
with
974 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright 2023 TiKV Project Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
ROOT_PATH := ../../.. | ||
GO_TOOLS_BIN_PATH := $(ROOT_PATH)/.tools/bin | ||
PATH := $(GO_TOOLS_BIN_PATH):$(PATH) | ||
SHELL := env PATH='$(PATH)' GOBIN='$(GO_TOOLS_BIN_PATH)' $(shell which bash) | ||
|
||
check: static deploy test clean | ||
|
||
static: install-tools | ||
@ echo "gofmt ..." | ||
@ gofmt -s -l -d . 2>&1 | awk '{ print } END { if (NR > 0) { exit 1 } }' | ||
@ echo "golangci-lint ..." | ||
@ golangci-lint run -c $(ROOT_PATH)/.golangci.yml --verbose ./... --allow-parallel-runners | ||
@ echo "revive ..." | ||
@ revive -formatter friendly -config $(ROOT_PATH)/revive.toml ./... | ||
|
||
tidy: | ||
@ go mod tidy | ||
git diff go.mod go.sum | cat | ||
git diff --quiet go.mod go.sum | ||
|
||
deploy: clean | ||
./download_binaries.sh | ||
rm -rf ./log | ||
mkdir log | ||
./deploy.sh log | ||
|
||
redeploy: | ||
./deploy.sh log | ||
|
||
clean: | ||
killall tidb-server 2>/dev/null || true | ||
killall tikv-server 2>/dev/null || true | ||
killall pd-server 2>/dev/null || true | ||
rm -rf log | ||
rm -rf third_bin | ||
rm -rf tmp | ||
rm -rf bin | ||
|
||
test: | ||
CGO_ENABLED=1 go test ./... -v -tags deadlock -race -cover || { exit 1; } | ||
|
||
install-tools: | ||
cd $(ROOT_PATH) && $(MAKE) install-tools |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/bin/bash | ||
# tools to run a TiDB cluster | ||
# parameter 1: work directory | ||
set -eu | ||
WORK_DIR=$1 | ||
|
||
export PD_PEER_ADDR="127.0.0.1:2382" | ||
export PD_ADDR="127.0.0.1:2381" | ||
|
||
export TIDB_IP="127.0.0.1" | ||
export TIDB_PORT="4000" | ||
export TIDB_ADDR="127.0.0.1:4000" | ||
|
||
export TIDB_STATUS_ADDR="127.0.0.1:10080" | ||
export TIKV_ADDR="127.0.0.1:2016" | ||
export TIKV_STATUS_ADDR="127.0.0.1:2018" | ||
|
||
start_pd() { | ||
echo "Starting PD..." | ||
|
||
cat >"$WORK_DIR/pd.toml" <<EOF | ||
[replication] | ||
# The number of replicas for each region. | ||
max-replicas = 1 | ||
EOF | ||
|
||
./bin/pd-server --version | ||
mkdir -p "$WORK_DIR/pd" | ||
./bin/pd-server \ | ||
--client-urls "http://$PD_ADDR" \ | ||
--peer-urls "http://$PD_PEER_ADDR" \ | ||
--log-file "$WORK_DIR/pd.log" \ | ||
--config "$WORK_DIR/pd.toml" \ | ||
--data-dir "$WORK_DIR/pd" & | ||
# wait until PD is online... | ||
i=0 | ||
while ! curl "http://$PD_ADDR/pd/api/v1/version"; do | ||
i=$((i + 1)) | ||
if [ "$i" -gt 20 ]; then | ||
echo 'Failed to start PD' | ||
return 1 | ||
fi | ||
sleep 3 | ||
done | ||
echo 'pd start successful' | ||
} | ||
|
||
start_tikv() { | ||
echo "Starting TiKV..." | ||
mkdir -p "$WORK_DIR/tikv" | ||
./bin/tikv-server \ | ||
--pd "$PD_ADDR" \ | ||
-A "$TIKV_ADDR" \ | ||
--status-addr "$TIKV_STATUS_ADDR" \ | ||
--log-file "$WORK_DIR/tikv.log" \ | ||
--log-level info \ | ||
-s "$WORK_DIR/tikv" & | ||
while ! curl "http://$PD_ADDR/pd/api/v1/cluster/status" | tee /dev/stderr | grep '"is_initialized": true'; do | ||
echo "http://$PD_ADDR/pd/api/v1/cluster/status" | ||
i=$((i + 1)) | ||
if [ "$i" -gt 20 ]; then | ||
echo 'Failed to initialize TiKV cluster' | ||
return 1 | ||
fi | ||
sleep 5 | ||
done | ||
} | ||
|
||
start_tidb() { | ||
echo "Starting TiDB..." | ||
./bin/tidb-server \ | ||
-P 4000 \ | ||
--status 10080 \ | ||
--advertise-address="127.0.0.1" \ | ||
--store tikv \ | ||
--path "$PD_ADDR" \ | ||
--log-slow-query="$WORK_DIR/tidb_slow_query.log" \ | ||
--log-file "$WORK_DIR/tidb.log" & | ||
|
||
i=0 | ||
while ! curl "http://$TIDB_IP:10080/status"; do | ||
i=$((i + 1)) | ||
if [ "$i" -gt 50 ]; then | ||
echo 'Failed to start TiDB' | ||
return 1 | ||
fi | ||
sleep 3 | ||
done | ||
} | ||
|
||
killall tidb-server 2>/dev/null || true | ||
killall tikv-server 2>/dev/null || true | ||
killall pd-server 2>/dev/null || true | ||
|
||
start_pd | ||
start_tikv | ||
start_tidb | ||
|
||
mysql -uroot -h127.0.0.1 -P4000 --default-character-set utf8 -e "CREATE USER 'test'@'%' IDENTIFIED BY '123456';" || true | ||
mysql -uroot -h127.0.0.1 -P4000 --default-character-set utf8 -e "GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' WITH GRANT OPTION;" || true |
Oops, something went wrong.