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

Commit

Permalink
master: support unlock-ddl-lock after stop-task (#1605) (#1612)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Apr 20, 2021
1 parent 48ceea6 commit 0568756
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
21 changes: 11 additions & 10 deletions dm/master/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,17 +758,18 @@ func (s *Server) UnlockDDLLock(ctx context.Context, req *pb.UnlockDDLLockRequest
return resp, nil
}
subtasks := s.scheduler.GetSubTaskCfgsByTask(task)
if len(subtasks) == 0 {
resp.Msg = "task (" + task + ") which extracted from lock-ID is not found in DM"
return resp, nil
}

for _, subtask := range subtasks {
if subtask.ShardMode != config.ShardPessimistic {
resp.Msg = "`unlock-ddl-lock` is only supported in pessimistic shard mode currently"
return resp, nil
if len(subtasks) > 0 {
// subtasks should have same ShardMode
for _, subtask := range subtasks {
if subtask.ShardMode == config.ShardOptimistic {
resp.Msg = "`unlock-ddl-lock` is only supported in pessimistic shard mode currently"
return resp, nil
}
break
}
break
} else {
// task is deleted so worker is not watching etcd, automatically set --force-remove
req.ForceRemove = true
}

// TODO: add `unlock-ddl-lock` support for Optimist later.
Expand Down
2 changes: 1 addition & 1 deletion tests/sequence_sharding_optimistic/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ run() {

run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"unlock-ddl-lock non-exist-task-\`test_db\`.\`test_table\`" \
"task (non-exist-task) which extracted from lock-ID is not found in DM" 1
"lock with ID non-exist-task-\`test_db\`.\`test_table\` not found" 1

run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"unlock-ddl-lock $task_name-\`shard_db\`.\`shard_table\`" \
Expand Down
3 changes: 3 additions & 0 deletions tests/sequence_sharding_removemeta/data/db1.increment2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use sharding_seq;
alter table t1 add column f int;
alter table t2 add column f int;
17 changes: 17 additions & 0 deletions tests/sequence_sharding_removemeta/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ function run() {
"no DDL lock exists" 1
# use sync_diff_inspector to check full data
check_sync_diff $WORK_DIR $cur/conf/diff_config.toml

run_sql_file $cur/data/db1.increment2.sql $MYSQL_HOST1 $MYSQL_PORT1 $MYSQL_PASSWORD1

# test unlock-ddl-lock could work after stop-task
ddl="ALTER TABLE \`sharding_target3\`.\`t_target\` ADD COLUMN \`f\` INT"
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"show-ddl-locks" \
"\"ID\": \"$lock_id\"" 1 \
"$ddl" 1
dmctl_stop_task $task_name

run_dm_ctl $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"unlock-ddl-lock $lock_id" \
"\"result\": true" 1
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"show-ddl-locks" \
"no DDL lock exists" 1
}

cleanup_data sharding_target3
Expand Down

0 comments on commit 0568756

Please sign in to comment.