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

*: show an unsynced message for workers which didn't get any shard DDL #1638

Merged
merged 8 commits into from
May 6, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
39 changes: 39 additions & 0 deletions dm/master/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,45 @@ func (s *Server) QueryStatus(ctx context.Context, req *pb.QueryStatusListRequest

resps := s.getStatusFromWorkers(ctx, sources, req.Name, queryRelayWorker)

// adjust unsynced field in sync status, task-name -> set(target-table)
// because if a DM-worker doesn't receive any shard DDL, it doesn't even know it's unsynced for itself
unsyncedMap := make(map[string]map[string]struct{})
for _, resp := range resps {
for _, subtaskStatus := range resp.SubTaskStatus {
syncStatus := subtaskStatus.GetSync()
if syncStatus == nil {
continue
}
for _, group := range syncStatus.UnresolvedGroups {
if _, ok := unsyncedMap[subtaskStatus.Name]; !ok {
unsyncedMap[subtaskStatus.Name] = make(map[string]struct{})
}
unsyncedMap[subtaskStatus.Name][group.Target] = struct{}{}
}
}
}
for _, resp := range resps {
for _, subtaskStatus := range resp.SubTaskStatus {
syncStatus := subtaskStatus.GetSync()
if syncStatus == nil {
continue
}
found := make(map[string]struct{}, len(syncStatus.UnresolvedGroups))
for _, group := range syncStatus.UnresolvedGroups {
found[group.Target] = struct{}{}
}
for target := range unsyncedMap[subtaskStatus.Name] {
if _, ok := found[target]; ok {
continue
}
syncStatus.UnresolvedGroups = append(syncStatus.UnresolvedGroups, &pb.ShardingGroup{
Target: target,
Unsynced: []string{"this DM-worker doesn't receive any shard DDL of this group"},
})
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weak advice: can we use a separate function for this part and add a unit test for it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


workerRespMap := make(map[string][]*pb.QueryStatusResponse, len(sources))
for _, workerResp := range resps {
workerRespMap[workerResp.SourceStatus.Source] = append(workerRespMap[workerResp.SourceStatus.Source], workerResp)
Expand Down
4 changes: 3 additions & 1 deletion dm/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,10 @@ func (w *Worker) QueryStatus(ctx context.Context, name string) ([]*pb.SubTaskSta
w.dbMutex.Lock()
if w.db == nil {
var err error
w.db, err = conn.DefaultDBProvider.Apply(w.cfg.From)
w.l.Info("will open a connection to get master status", zap.Any("upstream config", w.cfg.From))
w.db, err = conn.DefaultDBProvider.Apply(w.cfg.DecryptPassword().From)
if err != nil {
w.l.Error("can't open a connection to get master status", zap.Error(err))
w.dbMutex.Unlock()
return subtaskStatus, relayStatus, err
}
Expand Down
7 changes: 7 additions & 0 deletions tests/sequence_sharding_removemeta/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ function run() {
"show-ddl-locks" \
"\"ID\": \"$lock_id\"" 1 \
"$ddl" 1
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status $TEST_NAME" \
"this DM-worker doesn't receive any shard DDL of this group" 0 \
"\"masterBinlog\": \"\"" 0
check_metric $MASTER_PORT 'dm_master_ddl_state_number{task="sequence_sharding_removemeta",type="Un-synced"}' 3 0 2

dmctl_stop_task $task_name
Expand All @@ -70,6 +74,9 @@ function run() {
"show-ddl-locks" \
"\"ID\": \"$lock_id\"" 1 \
"$ddl" 1
run_dm_ctl_with_retry $WORK_DIR "127.0.0.1:$MASTER_PORT" \
"query-status $TEST_NAME" \
"this DM-worker doesn't receive any shard DDL of this group" 1

check_metric $MASTER_PORT 'dm_master_ddl_state_number{task="sequence_sharding_removemeta",type="Un-synced"}' 3 0 2
dmctl_stop_task $task_name
Expand Down