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

Commit

Permalink
dmctl: try read master addr from env (#1722) (#1726)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored May 27, 2021
1 parent 748d5b6 commit 5f32ce1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/upgrade-via-tiup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
fromVer:
dmVer: 'v1.0.6'
toVer:
dmVer: 'nightly'
dmVer: 'nightly'

jobs:
from_v1:
Expand All @@ -26,12 +26,12 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: 1.13

- name: Check out code
uses: actions/checkout@v2
with:
path: go/src/github.com/pingcap/dm

- name: Setup containers
working-directory: ${{ env.working-directory }}
run: |
Expand Down Expand Up @@ -69,13 +69,13 @@ jobs:
matrix:
previous_v2: ["v2.0.0", "v2.0.1", "v2.0.3"]

steps:
steps:

- name: Set up Go 1.13
uses: actions/setup-go@v2
with:
go-version: 1.13

- name: Check out code
uses: actions/checkout@v2
with:
Expand All @@ -85,7 +85,7 @@ jobs:
if: ${{ github.ref != 'refs/heads/master' }}
working-directory: ${{ env.working-directory }}
run: make build nolint=true

- name: Package files
if: ${{ github.ref != 'refs/heads/master' }}
run: |
Expand Down
7 changes: 6 additions & 1 deletion dm/ctl/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"flag"
"fmt"
"net"
"os"
"strings"
"time"

Expand Down Expand Up @@ -149,8 +150,12 @@ func (c *Config) Parse(arguments []string) (finish bool, err error) {
return false, errors.Errorf("'%s' is an invalid flag", c.FlagSet.Arg(0))
}

// try get master Addr from env "DM_MASTER_ADDR" if this flag is empty.
if c.MasterAddr == "" {
return false, errors.Errorf("--master-addr not provided, use `dmtcl --help` to see help messages")
c.MasterAddr = os.Getenv("DM_MASTER_ADDR")
}
if c.MasterAddr == "" {
return false, errors.Errorf("--master-addr not provided, this parameter is required when interacting with the dm-master, you can also use environment variable 'DM_MASTER_ADDR' to specify the value. Use `dmtcl --help` to see more help messages")
}

return false, errors.Trace(c.adjust())
Expand Down
6 changes: 6 additions & 0 deletions tests/dmctl_command/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ function run() {
# query status with command mode
$PWD/bin/dmctl.test DEVEL --master-addr=:$MASTER_PORT query-status >$WORK_DIR/query-status.log

# use DM_MASTER_ADDR env
export DM_MASTER_ADDR="127.0.0.1:$MASTER_PORT"
run_dm_ctl_with_retry $WORK_DIR "" \
"query-status test" \
"worker1" 1

running_task=$(grep -r Running $WORK_DIR/query-status.log | wc -l | xargs)

if [ "$running_task" != 1 ]; then
Expand Down
11 changes: 7 additions & 4 deletions tests/tiup/upgrade-from-v2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,20 @@ function migrate_in_previous_v2() {

tiup dmctl:$PRE_VER --master-addr=master1:8261 pause-task $TASK_NAME

run_dmctl_with_retry $CUR_VER "query-status" "Running" 2 "Paused" 1
run_dmctl_with_retry $PRE_VER "query-status" "Running" 2 "Paused" 1
}

function upgrade_to_current_v2() {
if [[ "$CUR_VER" == "nightly" && "$ref" == "refs/pull"* ]]; then
patch_nightly_with_tiup_mirror
fi
tiup update dmctl:$CUR_VER
tiup dm upgrade --yes $CLUSTER_NAME $CUR_VER
# uninstall previous dmctl, otherwise dmctl:nightly still use PRE_VER.
# FIXME: It may be a bug in tiup mirror.
tiup uninstall dmctl --all
}

function migrate_in_v2 {
function migrate_in_v2() {
run_dmctl_with_retry $CUR_VER "query-status" "Running" 2 "Paused" 1
run_dmctl_with_retry $CUR_VER "show-ddl-locks" "\"result\": true" 1 "\"task\": \"$TASK_PESS_NAME\"" 1 "\"task\": \"$TASK_OPTI_NAME\"" 1

Expand All @@ -79,7 +81,8 @@ function migrate_in_v2 {
echo "check locks"
run_dmctl_with_retry $CUR_VER "show-ddl-locks" "no DDL lock exists" 1

tiup dmctl:$CUR_VER --master-addr=master1:8261 stop-task $TASK_NAME
export DM_MASTER_ADDR="master1:8261"
tiup dmctl:$CUR_VER stop-task $TASK_NAME
}

function destroy_v2_by_tiup() {
Expand Down

0 comments on commit 5f32ce1

Please sign in to comment.