diff --git a/api/middleware/middleware_test.go b/api/middleware/middleware_test.go index d27c15b68c..1e2c50b41e 100644 --- a/api/middleware/middleware_test.go +++ b/api/middleware/middleware_test.go @@ -51,25 +51,24 @@ func TestLogMiddlewareMasksCredentialQuery(t *testing.T) { LogMiddleware()(c) restore() - require.Len(t, observed.All(), 1) - query := observed.All()[0].ContextMap()["query"].(string) - require.NotContains(t, query, "secret-value") - require.NotContains(t, query, "bare-key-material") - require.NotContains(t, query, "fragment-secret-value") - if mode == cerrors.RedactLogDisable { + entries := observed.All() + require.Len(t, entries, 1) + query := entries[0].ContextMap()["query"].(string) + switch mode { + case cerrors.RedactLogDisable: require.Contains(t, query, "key=xxxxx") - require.Contains(t, query, "region=west") require.Contains(t, query, "keyspace=xxxxx") + require.Contains(t, query, "region=west") require.Contains(t, query, "#token=xxxxx") + case cerrors.RedactLogMarker: + require.Equal(t, "‹key=xxxxx&keyspace=xxxxx®ion=west&token=xxxxx#token=xxxxx›", query) + case cerrors.RedactLogEnable: + require.Equal(t, "?", query) } } } func TestForwardToServer(t *testing.T) { - core, observed := observer.New(zapcore.InfoLevel) - restore := plog.ReplaceGlobals(zap.New(core), nil) - defer restore() - // Setup mock target server targetServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Verify received headers @@ -99,17 +98,6 @@ func TestForwardToServer(t *testing.T) { require.Equal(t, http.StatusOK, w.Code) require.Equal(t, "test-value", w.Header().Get("X-Test-Header")) require.Equal(t, "test response", w.Body.String()) - var loggedURL string - for _, entry := range observed.All() { - if entry.Message == "forwarding request to another server" { - loggedURL = entry.ContextMap()["url"].(string) - break - } - } - require.NotEmpty(t, loggedURL) - require.Contains(t, loggedURL, "region=west") - require.NotContains(t, loggedURL, "forward-secret-value") - require.Contains(t, loggedURL, "token=xxxxx") } func TestForwardToServerExceedMaxForwardTimes(t *testing.T) { diff --git a/api/v1/api.go b/api/v1/api.go index fd5765b225..1f35de7acd 100644 --- a/api/v1/api.go +++ b/api/v1/api.go @@ -115,7 +115,9 @@ func (o *OpenAPIV1) createChangefeed(c *gin.Context) { c.Request.Body = io.NopCloser(bytes.NewBuffer(jsonData)) c.Request.ContentLength = int64(len(jsonData)) - log.Info("create changefeed api v1", zap.String("changefeedID", changefeedConfig.ID)) + log.Info("create changefeed api v1", + zap.String("keyspace", changefeedConfig.Keyspace), + zap.String("changefeedID", changefeedConfig.ID)) o.v2.CreateChangefeed(c) } @@ -136,7 +138,9 @@ func (o *OpenAPIV1) updateChangefeed(c *gin.Context) { c.Request.Body = io.NopCloser(bytes.NewBuffer(jsonData)) c.Request.ContentLength = int64(len(jsonData)) - log.Info("update changefeed api v1", zap.String("changefeedID", changefeedConfig.ID)) + log.Info("update changefeed api v1", + zap.String("keyspace", changefeedConfig.Keyspace), + zap.String("changefeedID", changefeedConfig.ID)) o.v2.UpdateChangefeed(c) } diff --git a/api/v2/changefeed.go b/api/v2/changefeed.go index ca58c9ac43..6ecebeade7 100644 --- a/api/v2/changefeed.go +++ b/api/v2/changefeed.go @@ -248,7 +248,9 @@ func (h *OpenAPIV2) CreateChangefeed(c *gin.Context) { ) if undoErr != nil { log.Warn("undo ensure changefeed start ts safety failed when creating the changefeed", - zap.String("changefeedID", changefeedID.Name()), zap.Uint64("startTs", cfg.StartTs), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), + zap.Uint64("startTs", cfg.StartTs), zap.String("gcServiceID", createGcServiceID), zap.Error(undoErr)) } @@ -341,6 +343,7 @@ func (h *OpenAPIV2) CreateChangefeed(c *gin.Context) { } log.Info("create changefeed successfully", + zap.String("keyspace", info.ChangefeedID.Keyspace()), zap.String("changefeedID", info.ChangefeedID.Name()), zap.String("state", string(info.State)), zap.String("changefeedInfo", info.String()), @@ -819,7 +822,10 @@ func (h *OpenAPIV2) ResumeChangefeed(c *gin.Context) { log.Info("resume changefeed config is empty, using defaults") } else { if err = json.Unmarshal(body, cfg); err != nil { - log.Error("failed to bind resume changefeed config", zap.Error(err), zap.String("body", string(body))) + log.Error("failed to bind resume changefeed config", + zap.String("contentType", c.ContentType()), + zap.Int("bodyLength", len(body)), + zap.Error(err)) _ = c.Error(errors.WrapError(errors.ErrAPIInvalidParam, err)) return } @@ -919,7 +925,9 @@ func (h *OpenAPIV2) ResumeChangefeed(c *gin.Context) { ) if undoErr != nil { log.Warn("undo ensure changefeed start ts safety failed when resuming the changefeed", - zap.String("changefeedID", cfInfo.ChangefeedID.Name()), zap.Uint64("startTs", newCheckpointTs), + zap.String("keyspace", cfInfo.ChangefeedID.Keyspace()), + zap.String("changefeedID", cfInfo.ChangefeedID.Name()), + zap.Uint64("startTs", newCheckpointTs), zap.String("gcServiceID", resumeGcServiceID), zap.Error(undoErr)) } @@ -972,6 +980,7 @@ func (h *OpenAPIV2) ResumeChangefeed(c *gin.Context) { } c.Errors = nil log.Info("resume changefeed successfully", + zap.String("keyspace", cfInfo.ChangefeedID.Keyspace()), zap.String("changefeedID", cfInfo.ChangefeedID.Name()), zap.String("state", string(cfInfo.State)), zap.String("changefeedInfo", cfInfo.String()), @@ -1652,7 +1661,10 @@ func (h *OpenAPIV2) getDispatcherCount(c *gin.Context) { maintainer, ok := maintainerManager.GetMaintainerForChangefeed(changefeedID) if !ok { - log.Error("maintainer not found for changefeed in this node", zap.String("GID", changefeedID.Id.String()), zap.String("changefeed", changefeedID.String())) + log.Error("maintainer not found for changefeed in this node", + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeedID", changefeedID.Name()), + zap.String("GID", changefeedID.Id.String())) _ = c.Error(errors.ErrMaintainerNotFounded) return } diff --git a/coordinator/changefeed/backoff.go b/coordinator/changefeed/backoff.go index 4ad2245a57..f47f5a9a21 100644 --- a/coordinator/changefeed/backoff.go +++ b/coordinator/changefeed/backoff.go @@ -120,7 +120,8 @@ func (m *Backoff) checkFailedStatus(status *heartbeatpb.MaintainerStatus) (bool, m.checkpointTs = status.CheckpointTs } log.Error("changefeed maintainer report a fast fail error", - zap.Stringer("changefeed", m.id), + zap.String("keyspace", m.id.Keyspace()), + zap.String("changefeed", m.id.Name()), zap.Uint64("checkpointTs", m.checkpointTs), zap.String("node", err.Node), zap.String("code", err.Code), @@ -172,13 +173,15 @@ func (m *Backoff) CheckStatus(status *heartbeatpb.MaintainerStatus) (bool, confi if m.isRestarting.Load() { // FIXME: What does ignore the error mean? log.Info("changefeed is already in restarting progress, ignore the error", + zap.String("keyspace", m.id.Keyspace()), zap.String("changefeed", m.id.Name()), zap.Any("err", status.Err[len(status.Err)-1].Message), ) } log.Error("changefeed maintainer report an error", - zap.Stringer("changefeed", m.id), + zap.String("keyspace", m.id.Keyspace()), + zap.String("changefeed", m.id.Name()), zap.Uint64("checkpointTs", m.checkpointTs), zap.String("node", status.Err[len(status.Err)-1].Node), zap.String("code", status.Err[len(status.Err)-1].Code), @@ -232,7 +235,8 @@ func (m *Backoff) HandleError(errs []*heartbeatpb.RunningError) (bool, *heartbea log.Error("The changefeed won't be restarted as it has been experiencing failures for "+ "an extended duration", zap.Duration("maxElapsedTime", m.errBackoff.MaxElapsedTime), - zap.Stringer("changefeed", m.id), + zap.String("keyspace", m.id.Keyspace()), + zap.String("changefeed", m.id.Name()), zap.Uint64("checkpointTs", m.checkpointTs), zap.Time("nextRetryTime", m.nextRetryTime.Load()), ) @@ -240,7 +244,8 @@ func (m *Backoff) HandleError(errs []*heartbeatpb.RunningError) (bool, *heartbea } // if any error is occurred , we should set the changefeed state to warning and stop the changefeed log.Warn("changefeed meets an error, will be stopped", - zap.Stringer("changefeed", m.id), + zap.String("keyspace", m.id.Keyspace()), + zap.String("changefeed", m.id.Name()), zap.Uint64("checkpointTs", m.checkpointTs), zap.Time("nextRetryTime", m.nextRetryTime.Load()), zap.Any("error", errs)) diff --git a/coordinator/changefeed/changefeed.go b/coordinator/changefeed/changefeed.go index e8d7759431..b3a274c29f 100644 --- a/coordinator/changefeed/changefeed.go +++ b/coordinator/changefeed/changefeed.go @@ -56,10 +56,14 @@ func NewChangefeed(cfID common.ChangeFeedID, isNew bool, ) *Changefeed { if info == nil { - log.Panic("changefeed info is nil", zap.Stringer("changefeedID", cfID)) + log.Panic("changefeed info is nil", + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name())) } if info.Config == nil { - log.Panic("changefeed config is nil", zap.Stringer("changefeedID", cfID)) + log.Panic("changefeed config is nil", + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name())) } sinkType, _ := config.ParseSinkURI(info.SinkURI) res := &Changefeed{ @@ -84,8 +88,8 @@ func NewChangefeed(cfID common.ChangeFeedID, } log.Info("changefeed instance created", - zap.String("id", cfID.String()), zap.Uint64("checkpointTs", checkpointTs), + zap.String("id", cfID.String()), zap.String("state", string(info.State)), zap.String("info", info.String())) return res @@ -107,7 +111,9 @@ func (c *Changefeed) SetInfo(info *config.ChangeFeedInfo) { return } if info == nil { - log.Panic("changefeed info is nil", zap.Stringer("changefeedID", c.ID)) + log.Panic("changefeed info is nil", + zap.String("keyspace", c.ID.Keyspace()), + zap.String("changefeed", c.ID.Name())) } if c.info == nil { c.info = atomic.NewPointer(info) @@ -193,7 +199,8 @@ func (c *Changefeed) UpdateStatus(newStatus *heartbeatpb.MaintainerStatus) (bool // Record accepted progress before returning without CheckStatus. c.backoff.checkpointTs = newStatus.CheckpointTs log.Info("Received changefeed status with bootstrapDone", - zap.Stringer("changefeed", c.ID), + zap.String("keyspace", c.ID.Keyspace()), + zap.String("changefeed", c.ID.Name()), zap.Bool("bootstrapDone", newStatus.BootstrapDone)) return true, config.StateNormal, nil } diff --git a/coordinator/changefeed/changefeed_db.go b/coordinator/changefeed/changefeed_db.go index d3d262e7a0..0261fe90bc 100644 --- a/coordinator/changefeed/changefeed_db.go +++ b/coordinator/changefeed/changefeed_db.go @@ -102,8 +102,9 @@ func (db *ChangefeedDB) AddReplicatingMaintainer(task *Changefeed, nodeID node.I task.SetNodeID(nodeID) log.Info("add an replicating maintainer", - zap.String("nodeID", nodeID.String()), - zap.String("changefeed", task.ID.String())) + zap.String("keyspace", task.ID.Keyspace()), + zap.String("changefeed", task.ID.Name()), + zap.String("nodeID", nodeID.String())) db.changefeeds[task.ID] = task db.changefeedDisplayNames[task.ID.DisplayName] = task.ID @@ -132,7 +133,9 @@ func (db *ChangefeedDB) StopByChangefeedID(cfID common.ChangeFeedID, remove bool } if remove { - log.Info("remove changefeed", zap.String("changefeed", cf.ID.String())) + log.Info("remove changefeed", + zap.String("keyspace", cf.ID.Keyspace()), + zap.String("changefeed", cf.ID.Name())) delete(db.changefeeds, cfID) delete(db.changefeedDisplayNames, cf.ID.DisplayName) delete(db.stopped, cfID) @@ -147,7 +150,9 @@ func (db *ChangefeedDB) StopByChangefeedID(cfID common.ChangeFeedID, remove bool ) } } else { - log.Info("stop changefeed", zap.String("changefeed", cfID.String())) + log.Info("stop changefeed", + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name())) db.stopped[cfID] = cf } @@ -215,7 +220,8 @@ func (db *ChangefeedDB) BindChangefeedToNode(old, new node.ID, task *Changefeed) defer db.lock.Unlock() log.Info("bind changefeed to node", - zap.String("changefeed", task.ID.String()), + zap.String("keyspace", task.ID.Keyspace()), + zap.String("changefeed", task.ID.Name()), zap.String("oldNode", old.String()), zap.String("node", new.String())) db.BindReplicaToNodeWithoutLock(old, new, task) @@ -227,7 +233,8 @@ func (db *ChangefeedDB) MarkMaintainerReplicating(task *Changefeed) { defer db.lock.Unlock() log.Info("marking changefeed replicating", - zap.String("changefeed", task.ID.String())) + zap.String("keyspace", task.ID.Keyspace()), + zap.String("changefeed", task.ID.Name())) db.MarkReplicatingWithoutLock(task) task.StartFinished() } @@ -291,7 +298,8 @@ func (db *ChangefeedDB) MoveToSchedulingQueue( cf.SetIsNew(overwriteCheckpointTs || (info != nil && util.GetOrZero(info.BootstrapPending))) db.AddAbsentWithoutLock(cf) log.Info("move a changefeed to scheduling queue, it will be scheduled later", - zap.Stringer("changefeed", id), + zap.String("keyspace", id.Keyspace()), + zap.String("changefeed", id.Name()), zap.Uint64("checkpointTs", cf.GetStatus().CheckpointTs), zap.Bool("overwriteCheckpointTs", overwriteCheckpointTs), zap.Time("nextScheduleTime", cf.backoff.nextRetryTime.Load()), @@ -309,7 +317,8 @@ func (db *ChangefeedDB) MarkMaintainerAbsent(cf *Changefeed) { defer db.lock.Unlock() log.Info("marking changefeed absent", - zap.String("changefeed", cf.ID.String()), + zap.String("keyspace", cf.ID.Keyspace()), + zap.String("changefeed", cf.ID.Name()), zap.String("node", cf.GetNodeID().String())) db.MarkAbsentWithoutLock(cf) } @@ -382,7 +391,9 @@ func (db *ChangefeedDB) ReplaceStoppedChangefeed(cf *config.ChangeFeedInfo) { oldCf := db.stopped[cf.ChangefeedID] if oldCf == nil { - log.Warn("changefeed is not stopped, can not be updated", zap.String("changefeed", cf.ChangefeedID.String())) + log.Warn("changefeed is not stopped, can not be updated", + zap.String("keyspace", cf.ChangefeedID.Keyspace()), + zap.String("changefeed", cf.ChangefeedID.Name())) return } // todo: not create a new changefeed here? diff --git a/coordinator/controller.go b/coordinator/controller.go index bb87c29493..a3a2c608f0 100644 --- a/coordinator/controller.go +++ b/coordinator/controller.go @@ -510,7 +510,8 @@ func (c *Controller) RequestResolvedTsFromLogCoordinator(ctx context.Context, ch })); err != nil { log.Warn("failed to request resolved ts from log coordinator", zap.Stringer("target", id), - zap.String("changefeed", changefeedID.DisplayName.String()), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Error(err)) } } @@ -524,7 +525,8 @@ func (c *Controller) RequestResolvedTsFromLogCoordinator(ctx context.Context, ch select { case <-waitTimer.C: log.Warn("timeout waiting for log coordinator resolved ts", - zap.String("changefeed", changefeedDisplayName.String()), + zap.String("keyspace", changefeedDisplayName.Keyspace), + zap.String("changefeed", changefeedDisplayName.Name), zap.Uint64("oldTs", oldTs)) return case <-ticker.C: @@ -755,16 +757,18 @@ func (c *Controller) handleSingleMaintainerStatus( // owner, while continuing to reject all other stale-epoch reports. if acceptMoveOriginCheckpoint && handoffCheckpointAdvanced { log.Info("advance checkpoint from stopping maintainer", - zap.Stringer("changefeedID", cfID), - zap.Stringer("nodeID", from), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.Uint64("checkpointTs", status.CheckpointTs), + zap.Stringer("nodeID", from), zap.Uint64("statusMaintainerEpoch", status.MaintainerEpoch), zap.Uint64("currentMaintainerEpoch", cf.GetInfo().Epoch)) return newChangefeedChange(cf, cf.GetInfo().State, ChangeTs, nil) } log.Warn("drop stale maintainer status", - zap.Stringer("changefeed", cfID), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.Stringer("node", from), zap.Uint64("statusMaintainerEpoch", status.MaintainerEpoch), zap.Uint64("currentMaintainerEpoch", cf.GetInfo().Epoch)) @@ -795,7 +799,9 @@ func (c *Controller) markChangefeedBootstrapped(cf *changefeed.Changefeed, from updated, err := c.backend.FinishInit(ctx, cf.ID, epoch) if err != nil { log.Warn("failed to persist initial bootstrap completion, will retry", - zap.Stringer("changefeedID", cf.ID), zap.Error(err)) + zap.String("keyspace", cf.ID.Keyspace()), + zap.String("changefeed", cf.ID.Name()), + zap.Error(err)) return false } if updated == nil { @@ -818,7 +824,8 @@ func (c *Controller) handleNonExistentChangefeed( if op := c.operatorController.GetOperator(cfID); op == nil { log.Warn("no changefeed found and no operator for it, removing from maintainer", - zap.Stringer("changefeed", cfID), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.Stringer("sourceNode", from), zap.String("status", common.FormatMaintainerStatus(status))) @@ -846,7 +853,8 @@ func (c *Controller) validateMaintainerNode( if nodeID != from { log.Warn("remote changefeed maintainer nodeID mismatch with local record", - zap.Stringer("changefeed", cfID), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.Stringer("localNode", nodeID), zap.Stringer("remoteNode", from)) return false @@ -874,7 +882,8 @@ func (c *Controller) updateChangefeedStatus( if changed { changeType = ChangeStateAndTs log.Info("changefeed status changed", - zap.Stringer("changefeed", cfID), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.String("state", string(state)), zap.Stringer("error", err)) } @@ -904,7 +913,10 @@ func (c *Controller) finishBootstrap(ctx context.Context, runningChangefeeds map cfInfo, _, err := c.GetChangefeed(ctx, id.DisplayName) if err != nil { - log.Error("get changefeed failed", zap.Any("changefeed", id), zap.Error(err)) + log.Error("get changefeed failed", + zap.String("keyspace", id.Keyspace()), + zap.String("changefeed", id.Name()), + zap.Error(err)) continue } @@ -936,7 +948,8 @@ func (c *Controller) finishBootstrap(ctx context.Context, runningChangefeeds map } } else { log.Info("changefeed maintainer already running in other server", - zap.String("changefeed", cfID.String()), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.String("node", rm.nodeID.String()), zap.String("status", common.FormatMaintainerStatus(rm.status))) cf := changefeed.NewChangefeed(cfID, cfMeta.Info, rm.status.CheckpointTs, false) @@ -955,9 +968,10 @@ func (c *Controller) finishBootstrap(ctx context.Context, runningChangefeeds map } c.stopStaleBootstrapMaintainers(cfID, staleMaintainers, remove) log.Info("stop changefeed when bootstrapping", - zap.String("changefeed", cfID.String()), - zap.Int("progress", int(cfMeta.Status.Progress)), - zap.Uint64("checkpointTs", cfMeta.Status.CheckpointTs)) + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), + zap.Uint64("checkpointTs", cfMeta.Status.CheckpointTs), + zap.Int("progress", int(cfMeta.Status.Progress))) default: c.stopStaleBootstrapMaintainers(cfID, staleMaintainers, false) } @@ -967,6 +981,7 @@ func (c *Controller) finishBootstrap(ctx context.Context, runningChangefeeds map for id, remotes := range runningChangefeeds { for _, rm := range remotes { log.Warn("maintainer not found in local, remove it", + zap.String("keyspace", id.Keyspace()), zap.String("changefeed", id.Name()), zap.String("node", rm.nodeID.String()), ) @@ -1028,7 +1043,8 @@ func selectBootstrapMaintainer( } if len(matches) > 1 { log.Panic("maintainer runs on multiple node", - zap.Stringer("changefeedID", cfID), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.Stringer("oldNode", matches[0].nodeID), zap.Stringer("newNode", matches[1].nodeID), zap.Uint64("currentMaintainerEpoch", currentEpoch), @@ -1050,7 +1066,8 @@ func (c *Controller) stopStaleBootstrapMaintainers( ) { for _, stale := range staleMaintainers { log.Warn("ignore running maintainer with stale epoch when bootstrapping", - zap.String("changefeed", cfID.String()), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.String("node", stale.nodeID.String()), zap.Uint64("statusMaintainerEpoch", stale.status.MaintainerEpoch), zap.String("status", common.FormatMaintainerStatus(stale.status))) @@ -1110,7 +1127,9 @@ func (c *Controller) CreateChangefeed(ctx context.Context, info *config.ChangeFe case <-ctx.Done(): return errors.Trace(ctx.Err()) case <-ticker.C: - log.Warn("changefeed is in scheduling, wait a moment", zap.String("changefeed", info.ChangefeedID.DisplayName.String())) + log.Warn("changefeed is in scheduling, wait a moment", + zap.String("keyspace", info.ChangefeedID.Keyspace()), + zap.String("changefeed", info.ChangefeedID.Name())) count++ } } @@ -1224,7 +1243,9 @@ func (c *Controller) ResumeChangefeed( fmt.Sprintf("can only resume changefeed when it is stopped, failed, or finished, but current state is %s", state), ) log.Warn("refuse to resume the changefeed", - zap.Stringer("changefeedID", id), zap.Any("state", state)) + zap.String("keyspace", id.Keyspace()), + zap.String("changefeed", id.Name()), + zap.Any("state", state)) return err } @@ -1425,7 +1446,9 @@ func (c *Controller) updateChangefeedEpoch( ) error { cf := c.changefeedDB.GetByID(id) if cf == nil { - log.Warn("changefeed not found, skip updating epoch", zap.String("changefeed", id.String())) + log.Warn("changefeed not found, skip updating epoch", + zap.String("keyspace", id.Keyspace()), + zap.String("changefeed", id.Name())) return nil } epoch := pdutil.GenerateChangefeedEpoch(ctx, c.pdClient) diff --git a/coordinator/coordinator.go b/coordinator/coordinator.go index 69257692b7..cb0ea1478c 100644 --- a/coordinator/coordinator.go +++ b/coordinator/coordinator.go @@ -255,19 +255,23 @@ func (c *coordinator) handleStateChange( defer c.controller.apiLock.Unlock() cf := c.controller.getChangefeed(event.changefeedID) if cf == nil { - log.Warn("changefeed not found", zap.String("changefeed", event.changefeedID.String())) + log.Warn("changefeed not found", + zap.String("keyspace", event.changefeedID.Keyspace()), + zap.String("changefeed", event.changefeedID.Name())) return nil } currentInfo := cf.GetInfo() if currentInfo == nil { log.Warn("changefeed info is nil, skip state change", - zap.String("changefeed", event.changefeedID.String()), + zap.String("keyspace", event.changefeedID.Keyspace()), + zap.String("changefeed", event.changefeedID.Name()), zap.String("state", string(event.state))) return nil } if isUnchangedRuntimeState(currentInfo, event.state, event.err) { log.Debug("skip persisting unchanged changefeed runtime state", - zap.String("changefeed", event.changefeedID.String()), + zap.String("keyspace", event.changefeedID.Keyspace()), + zap.String("changefeed", event.changefeedID.Name()), zap.String("state", string(event.state))) return nil } @@ -337,7 +341,8 @@ func (c *coordinator) checkStaleCheckpointTs(ctx context.Context, changefeed *ch case <-ctx.Done(): log.Warn("Failed to send state change event to stateChangedCh since context timeout, "+ "there may be a lot of state need to be handled. Try next time", - zap.String("changefeed", id.String()), + zap.String("keyspace", id.Keyspace()), + zap.String("changefeed", id.Name()), zap.Error(context.Cause(ctx))) case c.changefeedChangeCh <- []*changefeedChange{change}: } @@ -413,7 +418,8 @@ func (c *coordinator) RemoveChangefeed(ctx context.Context, id common.ChangeFeed // next periodic GC reconcile tick gets a chance to clean it up. if err := c.tryDeleteGlobalGCSafepoint(ctx); err != nil { log.Warn("failed to delete global gc safepoint after removing last changefeed", - zap.String("changefeed", id.String()), + zap.String("keyspace", id.Keyspace()), + zap.String("changefeed", id.Name()), zap.Error(err)) } return checkpointTs, nil diff --git a/coordinator/gccleaner/cleaner.go b/coordinator/gccleaner/cleaner.go index 9f80990208..0fbceadb98 100644 --- a/coordinator/gccleaner/cleaner.go +++ b/coordinator/gccleaner/cleaner.go @@ -112,8 +112,9 @@ func (c *Cleaner) Add(changefeedID common.ChangeFeedID, keyspaceID uint32, tag s entry.resumingAtEpoch = c.updateEpoch default: log.Warn("unknown gc service tag, skip", - zap.String("gcServiceTag", tag), - zap.String("changefeed", changefeedID.String())) + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), + zap.String("gcServiceTag", tag)) } } @@ -229,8 +230,9 @@ func (c *Cleaner) requeue(tasks []task) { entry.resumingAtEpoch = c.updateEpoch default: log.Warn("unknown gc service tag, skip", - zap.String("gcServiceTag", task.tag), - zap.String("changefeed", task.changefeedID.String())) + zap.String("keyspace", task.changefeedID.Keyspace()), + zap.String("changefeed", task.changefeedID.Name()), + zap.String("gcServiceTag", task.tag)) } } } diff --git a/coordinator/operator/operator_add.go b/coordinator/operator/operator_add.go index 11db925623..014eca22f7 100644 --- a/coordinator/operator/operator_add.go +++ b/coordinator/operator/operator_add.go @@ -76,7 +76,8 @@ func (m *AddMaintainerOperator) Check(from node.ID, status *heartbeatpb.Maintain status.State == heartbeatpb.ComponentState_Working && status.BootstrapDone { log.Info("maintainer report working status", - zap.String("changefeed", m.cf.ID.String())) + zap.String("keyspace", m.cf.ID.Keyspace()), + zap.String("changefeed", m.cf.ID.Name())) m.finished.Store(true) } } diff --git a/coordinator/operator/operator_controller.go b/coordinator/operator/operator_controller.go index 07b5b920cf..c90cc7ff35 100644 --- a/coordinator/operator/operator_controller.go +++ b/coordinator/operator/operator_controller.go @@ -144,7 +144,8 @@ func (oc *Controller) AddOperator(op operator.Operator[common.ChangeFeedID, *hea log.Warn("add operator failed, cannot bump changefeed epoch", zap.String("role", oc.role), zap.String("operator", op.String()), - zap.Stringer("changefeed", op.ID()), + zap.String("keyspace", op.ID().Keyspace()), + zap.String("changefeed", op.ID().Name()), zap.Error(err)) return false } @@ -317,9 +318,11 @@ func (oc *Controller) stopChangefeed( } } - var originNode node.ID - var originEpoch uint64 - var useOriginEpoch bool + var ( + originNode node.ID + originEpoch uint64 + useOriginEpoch bool + ) if !hasMaintainerEpoch { originNode, originEpoch, useOriginEpoch = oc.moveOriginStopTargetLocked(cfID) } @@ -331,9 +334,10 @@ func (oc *Controller) stopChangefeed( } if scheduledNode == "" { log.Info("changefeed is not scheduled, try stop maintainer using coordinator node", + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.String("role", oc.role), - zap.Bool("removed", removed), - zap.String("changefeed", cfID.Name())) + zap.Bool("removed", removed)) scheduledNode = oc.selfNode.ID } @@ -371,8 +375,9 @@ func (oc *Controller) pushStopChangefeedOperator( if ok { if oldStop.changefeedRemoved { log.Info("changefeed is in removing progress, skip the stop operator", - zap.String("role", oc.role), - zap.String("changefeed", cfID.Name())) + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), + zap.String("role", oc.role)) return oldStop } if !remove { @@ -384,8 +389,9 @@ func (oc *Controller) pushStopChangefeedOperator( } } log.Info("changefeed is stopped, replace the old one", - zap.String("role", oc.role), + zap.String("keyspace", cfID.Keyspace()), zap.String("changefeed", cfID.Name()), + zap.String("role", oc.role), zap.String("operator", old.OP.String())) old.OP.OnTaskRemoved() old.OP.PostFinish() diff --git a/coordinator/operator/operator_move.go b/coordinator/operator/operator_move.go index 06ebfbed0c..a2cad9c2c9 100644 --- a/coordinator/operator/operator_move.go +++ b/coordinator/operator/operator_move.go @@ -85,7 +85,8 @@ func (m *MoveMaintainerOperator) Check(from node.ID, status *heartbeatpb.Maintai common.MaintainerEpochMatches(status.MaintainerEpoch, m.originMaintainerEpoch) && status.State != heartbeatpb.ComponentState_Working { log.Info("changefeed removed from origin node", - zap.String("changefeed", m.changefeed.ID.String())) + zap.String("keyspace", m.changefeed.ID.Keyspace()), + zap.String("changefeed", m.changefeed.ID.Name())) m.state = moveMaintainerStateOriginStopped } if m.state == moveMaintainerStateAddTarget && @@ -94,8 +95,9 @@ func (m *MoveMaintainerOperator) Check(from node.ID, status *heartbeatpb.Maintai status.State == heartbeatpb.ComponentState_Working && status.BootstrapDone { log.Info("changefeed added to dest node", - zap.String("dest", m.target.String()), - zap.String("changefeed", m.changefeed.ID.String())) + zap.String("keyspace", m.changefeed.ID.Keyspace()), + zap.String("changefeed", m.changefeed.ID.Name()), + zap.String("dest", m.target.String())) m.state = moveMaintainerStateDoneSuccess } } @@ -163,8 +165,9 @@ func (m *MoveMaintainerOperator) OnNodeRemove(n node.ID) { } if n == m.origin { log.Info("origin node is stopped", - zap.String("origin", m.origin.String()), - zap.String("changefeed", m.changefeed.ID.String())) + zap.String("keyspace", m.changefeed.ID.Keyspace()), + zap.String("changefeed", m.changefeed.ID.Name()), + zap.String("origin", m.origin.String())) switch m.state { case moveMaintainerStateRemoveOrigin: m.state = moveMaintainerStateOriginStopped @@ -182,9 +185,10 @@ func (m *MoveMaintainerOperator) onTargetNodeRemovedLocked() { return } log.Info("destination node removed before origin maintainer stopped", + zap.String("keyspace", m.changefeed.ID.Keyspace()), + zap.String("changefeed", m.changefeed.ID.Name()), zap.String("dest", m.target.String()), - zap.String("origin", m.origin.String()), - zap.String("changefeed", m.changefeed.ID.String())) + zap.String("origin", m.origin.String())) // Keep removing the old origin maintainer first. The new owner can only // be added back to origin after the old epoch reports stopped. m.target = m.origin @@ -194,9 +198,10 @@ func (m *MoveMaintainerOperator) onTargetNodeRemovedLocked() { return } log.Info("destination node removed after origin maintainer stopped", + zap.String("keyspace", m.changefeed.ID.Keyspace()), + zap.String("changefeed", m.changefeed.ID.Name()), zap.String("dest", m.target.String()), - zap.String("origin", m.origin.String()), - zap.String("changefeed", m.changefeed.ID.String())) + zap.String("origin", m.origin.String())) if m.originRemoved { m.finishAsAbsentLocked() return @@ -219,7 +224,8 @@ func (m *MoveMaintainerOperator) enterAddTargetLocked() { // finishAsAbsentLocked finishes the move without PostFinish side effects. func (m *MoveMaintainerOperator) finishAsAbsentLocked() { log.Info("move maintainer operator aborted, mark changefeed absent", - zap.String("changefeed", m.changefeed.ID.String()), + zap.String("keyspace", m.changefeed.ID.Keyspace()), + zap.String("changefeed", m.changefeed.ID.Name()), zap.String("origin", m.origin.String()), zap.String("target", m.target.String())) m.db.MarkMaintainerAbsent(m.changefeed) @@ -284,7 +290,8 @@ func (m *MoveMaintainerOperator) OnTaskRemoved() { defer m.lck.Unlock() log.Info("changefeed removed, mark move changefeed operator finished", - zap.String("changefeed", m.changefeed.ID.String())) + zap.String("keyspace", m.changefeed.ID.Keyspace()), + zap.String("changefeed", m.changefeed.ID.Name())) m.state = moveMaintainerStateDoneNoPostFinish } @@ -309,7 +316,8 @@ func (m *MoveMaintainerOperator) PostFinish() { } log.Info("move changefeed operator finished", - zap.String("changefeed", m.changefeed.ID.String())) + zap.String("keyspace", m.changefeed.ID.Keyspace()), + zap.String("changefeed", m.changefeed.ID.Name())) m.db.MarkMaintainerReplicating(m.changefeed) } diff --git a/coordinator/operator/operator_stop.go b/coordinator/operator/operator_stop.go index 8264ac384a..722a1e6cba 100644 --- a/coordinator/operator/operator_stop.go +++ b/coordinator/operator/operator_stop.go @@ -97,7 +97,8 @@ func (m *StopChangefeedOperator) Schedule() *messaging.TargetMessage { func (m *StopChangefeedOperator) OnNodeRemove(n node.ID) { if n == m.nodeID { log.Info("node is stopped during stop maintainer, schedule stop command to coordinator node", - zap.Stringer("changefeed", m.cfID), + zap.String("keyspace", m.cfID.Keyspace()), + zap.String("changefeed", m.cfID.Name()), zap.Stringer("node", n)) m.nodeID = m.coordinatorNodeID } @@ -122,7 +123,8 @@ func (m *StopChangefeedOperator) OnTaskRemoved() { func (m *StopChangefeedOperator) Start() { log.Info("start remove maintainer operator", - zap.Stringer("changefeed", m.cfID)) + zap.String("keyspace", m.cfID.Keyspace()), + zap.String("changefeed", m.cfID.Name())) } func (m *StopChangefeedOperator) PostFinish() { @@ -136,7 +138,8 @@ func (m *StopChangefeedOperator) PostFinish() { if m.changefeedRemoved { if err := m.backend.DeleteChangefeed(context.Background(), m.cfID); err != nil { log.Warn("failed to delete changefeed", - zap.Stringer("changefeed", m.cfID), + zap.String("keyspace", m.cfID.Keyspace()), + zap.String("changefeed", m.cfID.Name()), zap.Error(err)) } } else { @@ -146,12 +149,15 @@ func (m *StopChangefeedOperator) PostFinish() { config.ProgressNone, ); err != nil { log.Warn("failed to set changefeed progress", - zap.Stringer("changefeed", m.cfID), + zap.String("keyspace", m.cfID.Keyspace()), + zap.String("changefeed", m.cfID.Name()), zap.Error(err), ) } } - log.Info("stop maintainer operator finished", zap.Stringer("changefeed", m.cfID)) + log.Info("stop maintainer operator finished", + zap.String("keyspace", m.cfID.Keyspace()), + zap.String("changefeed", m.cfID.Name())) } func (m *StopChangefeedOperator) String() string { diff --git a/docs/agents/logging.md b/docs/agents/logging.md index 45d52618f5..f590349907 100644 --- a/docs/agents/logging.md +++ b/docs/agents/logging.md @@ -12,8 +12,11 @@ Read this before adding, removing, or rewriting logs. - `DEBUG`: bounded, low-frequency diagnostics with clear troubleshooting value. - Do not add `DEBUG` logs by default. Delete low-value logs instead of moving them to `DEBUG`. - Keep `message` stable and concise: summarize what happened, why it happened, and what the system will do next. -- Put object details in stable camelCase `zap` fields such as `changefeedID`, `nodeID`, `dispatcherID`, `regionID`, `subscriptionID`, and `requestID`. +- Put object details in stable camelCase `zap` fields. For changefeed-scoped logs always use two fields: `keyspace` (keyspace name) and `changefeedID` (changefeed name). Never encode `keyspace/name` as a single value, and never name the changefeed field `changefeed`. +- One concept has one field name. Identifiers end with `ID`; timestamps end with `Ts`. Use `tableID` for the numeric table ID and `tableSpan` for the formatted key range, never `table` for either. Use `ddlQuery` for DDL text and `zap.Error(err)` for errors. Do not put a formatted range in a field named `span`, `subSpan`, or `dispatcherSpan`; when one log carries both the dispatcher's and the subscription's range, name them `tableSpan` and `subscriptionTableSpan`. Summarize other structured values in explicit fields instead of passing objects to `zap.Any`. +- Order fields the same way everywhere: `keyspace`, `changefeedID`, `dispatcherID`, `subscriptionID`, `tableID`, `tableSpan`, `regionID`, then `startTs`, `commitTs`, `checkpointTs`, `resolvedTs`, then payload fields such as `ddlQuery`, `state`, `result`, `duration`, `count`, with `error` last. - Message strings should not include function names and should avoid `-` (use spaces instead). +- Do not unit-test log messages, fields, or formatting. Tests may only assert that sensitive values are masked. - Avoid per-object or per-iteration logs, duplicated logs on the same error path, large objects, raw payloads, and long error dumps in default logs. - Use metrics for counts, scale, frequency, and trends; use windowed summaries or representative samples for high-cardinality events. - Before adding, keeping, or rewriting a log, verify that it answers a real diagnostic question, identifies the object, reason, action, and impact, and will not grow linearly with object count or retry/loop frequency. diff --git a/downstreamadapter/dispatcher/basic_dispatcher.go b/downstreamadapter/dispatcher/basic_dispatcher.go index 0941ad8dbd..24c61ee42e 100644 --- a/downstreamadapter/dispatcher/basic_dispatcher.go +++ b/downstreamadapter/dispatcher/basic_dispatcher.go @@ -29,6 +29,7 @@ import ( "github.com/pingcap/ticdc/pkg/config" "github.com/pingcap/ticdc/pkg/errors" "github.com/pingcap/ticdc/pkg/routing" + "github.com/pingcap/ticdc/pkg/util" "github.com/pingcap/tidb/pkg/parser/mysql" tidbTypes "github.com/pingcap/tidb/pkg/types" "go.uber.org/atomic" @@ -340,7 +341,7 @@ func (d *BasicDispatcher) InitializeTableSchemaStore(schemaInfo []*heartbeatpb.S // Because we only need to calculate the tableNames or TableIds in the sink // when the event dispatcher manager have table trigger event dispatcher if !d.IsTableTriggerDispatcher() { - log.Error("InitializeTableSchemaStore should only be received by table trigger dispatcher", zap.Any("dispatcherID", d.id)) + log.Error("InitializeTableSchemaStore should only be received by table trigger dispatcher", zap.Stringer("dispatcherID", d.id)) return false, errors.ErrChangefeedInitTableTriggerDispatcherFailed. GenWithStackByArgs("InitializeTableSchemaStore should only be received by table trigger dispatcher") } @@ -365,7 +366,7 @@ func (d *BasicDispatcher) AddBlockEventToSink(event commonEvent.BlockEvent) erro // If NotSync is true, it means the DDL should not be sent to downstream. // So we just call PassBlockEventToSink to update the table progress and call the postFlush func. if ddl.NotSync { - log.Info("ignore DDL by NotSync", zap.Stringer("dispatcherID", d.id), zap.String("ddl", ddl.GetDDLQuery())) + log.Info("ignore DDL by NotSync", zap.Stringer("dispatcherID", d.id), zap.String("ddlQuery", util.RedactValue(ddl.GetDDLQuery()))) d.PassBlockEventToSink(event) return nil } @@ -535,7 +536,8 @@ func (d *BasicDispatcher) GetCheckpointTs() uint64 { // updateDispatcherStatusToWorking updates the dispatcher status to working and adds it to status dynamic stream func (d *BasicDispatcher) updateDispatcherStatusToWorking() { log.Info("update dispatcher status to working", - zap.Stringer("changefeedID", d.sharedInfo.changefeedID), + zap.String("keyspace", d.sharedInfo.changefeedID.Keyspace()), + zap.String("changefeed", d.sharedInfo.changefeedID.Name()), zap.Stringer("dispatcherID", d.id), zap.Uint64("checkpointTs", d.GetCheckpointTs()), zap.Uint64("resolvedTs", d.GetResolvedTs()), @@ -563,7 +565,8 @@ func (d *BasicDispatcher) HandleError(err error) { case d.sharedInfo.errCh <- err: default: log.Error("error channel is full, discard error", - zap.Stringer("changefeedID", d.sharedInfo.changefeedID), + zap.String("keyspace", d.sharedInfo.changefeedID.Keyspace()), + zap.String("changefeed", d.sharedInfo.changefeedID.Name()), zap.Stringer("dispatcherID", d.id), zap.Error(err)) } @@ -609,11 +612,11 @@ func (d *BasicDispatcher) handleEvents(dispatcherEvents []DispatcherEvent, wakeC // Pre-check, make sure the event is not stale if event.GetCommitTs() < d.GetResolvedTs() { log.Warn("Received a stale event, should ignore it", + zap.Stringer("dispatcherID", d.id), zap.Uint64("dispatcherResolvedTs", d.GetResolvedTs()), zap.Uint64("eventCommitTs", event.GetCommitTs()), zap.Uint64("seq", event.GetSeq()), - zap.Int("eventType", event.GetType()), - zap.Stringer("dispatcherID", d.id)) + zap.Int("eventType", event.GetType())) continue } @@ -686,9 +689,11 @@ func (d *BasicDispatcher) handleEvents(dispatcherEvents []DispatcherEvent, wakeC } log.Info("dispatcher receive ddl event", + zap.String("keyspace", d.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.GetChangefeedID().Name()), zap.Stringer("dispatcherID", d.id), - zap.String("query", ddl.Query), - zap.Int64("table", ddl.GetTableID()), + zap.Int64("tableID", ddl.GetTableID()), + zap.Uint64("startTs", ddl.GetStartTs()), zap.Uint64("commitTs", event.GetCommitTs()), zap.Uint64("seq", event.GetSeq())) now := time.Now() @@ -726,9 +731,9 @@ func (d *BasicDispatcher) handleEvents(dispatcherEvents []DispatcherEvent, wakeC zap.Any("event", event)) default: log.Panic("Unexpected event type", - zap.Int("eventType", event.GetType()), zap.Stringer("dispatcherID", d.id), - zap.Uint64("commitTs", event.GetCommitTs())) + zap.Uint64("commitTs", event.GetCommitTs()), + zap.Int("eventType", event.GetType())) } } // resolvedTs and dml events can be in the same batch, @@ -795,9 +800,9 @@ func (d *BasicDispatcher) HandleDispatcherStatus(dispatcherStatus *heartbeatpb.D if pendingEvent == nil && action.CommitTs > d.GetResolvedTs() { // we have not received the block event, and the action is for the future event, so just ignore log.Debug("pending event is nil, and the action's commit is larger than dispatchers resolvedTs", + zap.Stringer("dispatcherID", d.id), zap.Uint64("resolvedTs", d.GetResolvedTs()), - zap.Uint64("actionCommitTs", action.CommitTs), - zap.Stringer("dispatcherID", d.id)) + zap.Uint64("actionCommitTs", action.CommitTs)) // we have not received the block event, and the action is for the future event, so just ignore return false } @@ -843,6 +848,7 @@ func (d *BasicDispatcher) HandleDispatcherStatus(dispatcherStatus *heartbeatpb.D zap.Stringer("dispatcherID", d.id), zap.Int("action", int(action.Action)), zap.Uint64("commitTs", action.CommitTs), + zap.Int("action", int(action.Action)), zap.Bool("isSyncPoint", action.IsSyncPoint)) d.blockEventStatus.updateBlockStage(heartbeatpb.BlockStage_WAITING) return false @@ -851,9 +857,9 @@ func (d *BasicDispatcher) HandleDispatcherStatus(dispatcherStatus *heartbeatpb.D ts, ok := d.blockEventStatus.getEventCommitTs() if ok && action.CommitTs > ts { log.Debug("pending event's commitTs is smaller than the action's commitTs, just ignore it", + zap.Stringer("dispatcherID", d.id), zap.Uint64("pendingEventCommitTs", ts), - zap.Uint64("actionCommitTs", action.CommitTs), - zap.Stringer("dispatcherID", d.id)) + zap.Uint64("actionCommitTs", action.CommitTs)) return false } } @@ -1352,7 +1358,8 @@ func (d *BasicDispatcher) TryClose() (w heartbeatpb.Watermark, ok bool) { d.tableSchemaStore.Clear() } log.Info("dispatcher component has stopped and is ready for cleanup", - zap.Stringer("changefeedID", d.sharedInfo.changefeedID), + zap.String("keyspace", d.sharedInfo.changefeedID.Keyspace()), + zap.String("changefeed", d.sharedInfo.changefeedID.Name()), zap.Stringer("dispatcherID", d.id), zap.Int64("mode", d.mode), zap.Uint64("checkpointTs", d.GetCheckpointTs()), @@ -1378,15 +1385,19 @@ func (d *BasicDispatcher) TryClose() (w heartbeatpb.Watermark, ok bool) { // It removes the dispatcher from status dynamic stream to stop receiving status info from maintainer. func (d *BasicDispatcher) removeDispatcher() { + resendTaskCount := len(d.resendTaskMap.Keys()) log.Info("remove dispatcher", - zap.Stringer("changefeedID", d.sharedInfo.changefeedID), + zap.String("keyspace", d.sharedInfo.changefeedID.Keyspace()), + zap.String("changefeed", d.sharedInfo.changefeedID.Name()), zap.Stringer("dispatcherID", d.id), - zap.Int64("mode", d.mode)) + zap.Int64("mode", d.mode), + zap.Int("resendTaskCount", resendTaskCount)) dispatcherStatusDS := GetDispatcherStatusDynamicStream() err := dispatcherStatusDS.RemovePath(d.id) if err != nil { - log.Error("remove dispatcher from dynamic stream failed", - zap.Stringer("changefeedID", d.sharedInfo.changefeedID), + log.Error("remove dispatcher failed", + zap.String("keyspace", d.sharedInfo.changefeedID.Keyspace()), + zap.String("changefeed", d.sharedInfo.changefeedID.Name()), zap.Stringer("dispatcherID", d.id), zap.Uint64("checkpointTs", d.GetCheckpointTs()), zap.Uint64("resolvedTs", d.GetResolvedTs()), @@ -1397,8 +1408,5 @@ func (d *BasicDispatcher) removeDispatcher() { identifiers := d.resendTaskMap.Keys() for _, identifier := range identifiers { d.cancelResendTask(identifier) - log.Info("cancel resend task before remove dispatcher", - zap.Any("identifier", identifier), - zap.Stringer("dispatcherID", d.id)) } } diff --git a/downstreamadapter/dispatcher/event_dispatcher.go b/downstreamadapter/dispatcher/event_dispatcher.go index f3c5718377..58ac015351 100644 --- a/downstreamadapter/dispatcher/event_dispatcher.go +++ b/downstreamadapter/dispatcher/event_dispatcher.go @@ -207,7 +207,8 @@ func (d *EventDispatcher) EmitBootstrap(ctx context.Context, shouldStop func() b tableInfo, err := schemaStore.GetTableInfo(ctx, meta, table, ts) if err != nil { log.Warn("get table info failed, just ignore", - zap.Stringer("changefeed", d.sharedInfo.changefeedID), + zap.String("keyspace", d.sharedInfo.changefeedID.Keyspace()), + zap.String("changefeed", d.sharedInfo.changefeedID.Name()), zap.Error(err)) continue } @@ -215,7 +216,8 @@ func (d *EventDispatcher) EmitBootstrap(ctx context.Context, shouldStop func() b } log.Info("start to send bootstrap messages", - zap.Stringer("changefeed", d.sharedInfo.changefeedID), + zap.String("keyspace", d.sharedInfo.changefeedID.Keyspace()), + zap.String("changefeed", d.sharedInfo.changefeedID.Name()), zap.Int("tables", len(currentTables))) for idx, table := range currentTables { if table.IsView() { @@ -231,7 +233,8 @@ func (d *EventDispatcher) EmitBootstrap(ctx context.Context, shouldStop func() b return false } log.Error("send bootstrap message failed", - zap.Stringer("changefeed", d.sharedInfo.changefeedID), + zap.String("keyspace", d.sharedInfo.changefeedID.Keyspace()), + zap.String("changefeed", d.sharedInfo.changefeedID.Name()), zap.Int("tables", len(currentTables)), zap.Int("emitted", idx+1), zap.Duration("duration", time.Since(start)), @@ -245,7 +248,8 @@ func (d *EventDispatcher) EmitBootstrap(ctx context.Context, shouldStop func() b } storeBootstrapState(&d.BootstrapState, BootstrapFinished) log.Info("send bootstrap messages finished", - zap.Stringer("changefeed", d.sharedInfo.changefeedID), + zap.String("keyspace", d.sharedInfo.changefeedID.Keyspace()), + zap.String("changefeed", d.sharedInfo.changefeedID.Name()), zap.Int("tables", len(currentTables)), zap.Duration("cost", time.Since(start))) return true diff --git a/downstreamadapter/dispatcher/helper.go b/downstreamadapter/dispatcher/helper.go index 3188ccaf32..33daaf67be 100644 --- a/downstreamadapter/dispatcher/helper.go +++ b/downstreamadapter/dispatcher/helper.go @@ -546,8 +546,9 @@ func addToStatusDynamicStream(d Dispatcher) { dispatcherStatusDS := GetDispatcherStatusDynamicStream() err := dispatcherStatusDS.AddPath(d.GetId(), d) if err != nil { - log.Error("add dispatcher to dynamic stream failed", - zap.Stringer("changefeedID", d.GetChangefeedID()), + log.Error("add dispatcher failed", + zap.String("keyspace", d.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.GetChangefeedID().Name()), zap.Stringer("dispatcherID", d.GetId()), zap.Error(err)) } diff --git a/downstreamadapter/dispatchermanager/dispatcher_manager.go b/downstreamadapter/dispatchermanager/dispatcher_manager.go index 17a5e0de5c..d09f4f25f1 100644 --- a/downstreamadapter/dispatchermanager/dispatcher_manager.go +++ b/downstreamadapter/dispatchermanager/dispatcher_manager.go @@ -314,7 +314,8 @@ func NewDispatcherManager( if ignoreUpdateOnlyColumnsRuleCount > 0 { _, downstreamType := config.ParseSinkURI(manager.config.SinkURI) log.Warn("ignore update only columns is configured but does not take effect for this sink", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.String("sinkType", downstreamType), zap.Int("eventFilterRuleCount", ignoreUpdateOnlyColumnsRuleCount)) } @@ -421,7 +422,8 @@ func NewDispatcherManager( }() log.Info("dispatcher manager initialized", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Stringer("maintainerID", maintainerID), zap.Uint64("startTs", startTs), zap.Uint64("sinkQuota", manager.sinkQuota), @@ -499,10 +501,12 @@ func (e *DispatcherManager) NewTableTriggerEventDispatcher(id *heartbeatpb.Dispa return errors.ErrChangefeedInitTableTriggerDispatcherFailed. FastGenByArgs("table trigger event dispatcher was not created") } - log.Info("table trigger event dispatcher created", - zap.Stringer("changefeedID", e.changefeedID), + log.Info("add dispatcher done", + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Stringer("dispatcherID", tableTriggerDispatcher.GetId()), zap.Uint64("startTs", tableTriggerDispatcher.GetStartTs()), + zap.String("kind", "tableTrigger"), ) return nil } @@ -570,7 +574,8 @@ func (e *DispatcherManager) getTableRecoveryInfoFromMysqlSink(tableIds, startTsL return nil, nil, nil, err } log.Info("get table recovery info for dispatchers", - zap.Stringer("changefeedID", e.changefeedID), + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Any("receiveStartTs", startTsList), zap.Any("realStartTs", newStartTsList), zap.Bool("removeDDLTs", removeDDLTs), @@ -682,16 +687,18 @@ func (e *DispatcherManager) newEventDispatchers(infos map[common.DispatcherID]di e.metricEventDispatcherCount.Inc() } - log.Info("new dispatcher created", - zap.Stringer("changefeedID", e.changefeedID), + log.Info("add dispatcher done", + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Stringer("dispatcherID", id), zap.Int64("tableID", tableSpans[idx].TableID), zap.Int64("startTs", newStartTsList[idx]), zap.Bool("skipDMLAsStartTs", skipDMLAsStartTs)) } e.metricCreateDispatcherDuration.Observe(time.Since(start).Seconds() / float64(len(dispatcherIds))) - log.Info("batch create new dispatchers", - zap.Stringer("changefeedID", e.changefeedID), + log.Info("add dispatchers done", + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Int("count", len(dispatcherIds)), zap.Duration("duration", time.Since(start)), ) @@ -706,7 +713,8 @@ func (e *DispatcherManager) handleError(ctx context.Context, err error) { case e.sharedInfo.GetErrCh() <- err: default: log.Error("error channel is full, discard error", - zap.Stringer("changefeedID", e.changefeedID), + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Error(err), ) } @@ -722,7 +730,8 @@ func (e *DispatcherManager) collectErrors(ctx context.Context) { case err := <-e.sharedInfo.GetErrCh(): if !errors.Is(errors.Cause(err), context.Canceled) { log.Error("Event Dispatcher Manager Meets Error", - zap.Stringer("changefeedID", e.changefeedID), + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Error(err), ) @@ -1042,10 +1051,11 @@ func (e *DispatcherManager) mergeEventDispatcher(dispatcherIDs []common.Dispatch &e.redoGlobalTs, ) - log.Info("new dispatcher created(merge dispatcher)", - zap.Stringer("changefeedID", e.changefeedID), + log.Info("add dispatcher done", + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Stringer("dispatcherID", mergedDispatcherID), - zap.Int64("tableID", mergedSpan.TableID)) + zap.String("kind", "merge")) e.writePathMu.Lock() if e.writePathClosed.Load() { @@ -1096,7 +1106,8 @@ func (e *DispatcherManager) LocalFence() { func (e *DispatcherManager) close() { log.Info("closing event dispatcher manager", - zap.Stringer("changefeedID", e.changefeedID)) + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name())) e.stopWritePath(false) e.finishClose() @@ -1112,7 +1123,8 @@ func (e *DispatcherManager) stopWritePath(cancelFirst bool) { e.writePathMu.Unlock() log.Info("stopping dispatcher manager write path", - zap.Stringer("changefeedID", e.changefeedID)) + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name())) if cancelFirst && e.cancel != nil { e.cancel() @@ -1121,18 +1133,21 @@ func (e *DispatcherManager) stopWritePath(cancelFirst bool) { if e.IsRedoEnabled() && e.redoSink != nil { closeAllDispatchers(e.changefeedID, e.redoDispatcherMap, e.redoSink.SinkType()) log.Info("closed all redo dispatchers", - zap.Stringer("changefeedID", e.changefeedID)) + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name())) if heartbeatCollector, ok := appcontext.TryGetService[*HeartBeatCollector](appcontext.HeartbeatCollector); ok { err := heartbeatCollector.RemoveRedoMessage(e.changefeedID) if err != nil { log.Error("remove redo message failed", - zap.Stringer("changefeedID", e.changefeedID), + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Error(err), ) } } else { log.Warn("heartbeat collector is not available when stopping redo write path", - zap.Stringer("changefeedID", e.changefeedID), + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), ) } } @@ -1141,19 +1156,22 @@ func (e *DispatcherManager) stopWritePath(cancelFirst bool) { closeAllDispatchers(e.changefeedID, e.dispatcherMap, e.sink.SinkType()) } log.Info("closed all event dispatchers", - zap.Stringer("changefeedID", e.changefeedID)) + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name())) if heartbeatCollector, ok := appcontext.TryGetService[*HeartBeatCollector](appcontext.HeartbeatCollector); ok { err := heartbeatCollector.RemoveDispatcherManager(e.changefeedID) if err != nil { log.Error("remove dispatcher manager from heartbeat collector failed", - zap.Stringer("changefeedID", e.changefeedID), + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Error(err), ) } } else { log.Warn("heartbeat collector is not available when stopping dispatcher manager write path", - zap.Stringer("changefeedID", e.changefeedID), + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), ) } @@ -1173,7 +1191,9 @@ func (e *DispatcherManager) stopWritePath(cancelFirst bool) { e.sharedInfo.Close() } - log.Info("shared info closed", zap.Stringer("changefeedID", e.changefeedID)) + log.Info("shared info closed", + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name())) if e.IsRedoEnabled() && e.redoSink != nil { e.redoSink.Close() @@ -1181,7 +1201,9 @@ func (e *DispatcherManager) stopWritePath(cancelFirst bool) { if e.sink != nil { e.sink.Close() } - log.Info("sink closed", zap.Stringer("changefeedID", e.changefeedID)) + log.Info("sink closed", + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name())) } func (e *DispatcherManager) addCheckpointTs(checkpointTs uint64) { @@ -1214,7 +1236,8 @@ func (e *DispatcherManager) finishClose() { e.tryScheduleRemoveChangefeedCleanup() log.Info("event dispatcher manager closed", - zap.Stringer("changefeedID", e.changefeedID)) + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name())) } func (e *DispatcherManager) tryScheduleRemoveChangefeedCleanup() { @@ -1233,7 +1256,8 @@ func (e *DispatcherManager) tryScheduleRemoveChangefeedCleanup() { if err := e.runRemoveChangefeedCleanup(); err != nil { log.Warn("failed to cleanup removed changefeed", - zap.Stringer("changefeedID", e.changefeedID), + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Error(err)) return } @@ -1276,10 +1300,6 @@ func (e *DispatcherManager) cleanEventDispatcher(id common.DispatcherID, schemaI } else { e.metricEventDispatcherCount.Dec() } - log.Info("event dispatcher completely stopped, and delete it from event dispatcher manager", - zap.Stringer("changefeedID", e.changefeedID), - zap.Stringer("dispatcherID", id), - ) } func (e *DispatcherManager) cleanMetrics() { diff --git a/downstreamadapter/dispatchermanager/dispatcher_manager_helper.go b/downstreamadapter/dispatchermanager/dispatcher_manager_helper.go index 025ba77d1b..fc0789364e 100644 --- a/downstreamadapter/dispatchermanager/dispatcher_manager_helper.go +++ b/downstreamadapter/dispatchermanager/dispatcher_manager_helper.go @@ -54,7 +54,8 @@ func getDispatcherStatus(id common.DispatcherID, dispatcherItem dispatcher.Dispa if needCompleteStatus { if dispatcherItem.GetComponentStatus() == heartbeatpb.ComponentState_Initializing { log.Debug("dispatcher is initializing", - zap.Stringer("changefeedID", dispatcherItem.GetChangefeedID()), + zap.String("keyspace", dispatcherItem.GetChangefeedID().Keyspace()), + zap.String("changefeed", dispatcherItem.GetChangefeedID().Name()), zap.Stringer("dispatcherID", id), zap.Any("componentStatus", dispatcherItem.GetComponentStatus()), ) @@ -113,7 +114,8 @@ func prepareMergeDispatcher[T dispatcher.Dispatcher](changefeedID common.ChangeF ) bool { if len(dispatcherIDs) < 2 { log.Error("merge dispatcher failed, invalid dispatcherIDs", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Any("dispatcherIDs", dispatcherIDs)) return false } @@ -140,23 +142,28 @@ func createMergedSpan[T dispatcher.Dispatcher](changefeedID common.ChangeFeedID, dispatcherIDs []common.DispatcherID, dispatcherMap *DispatcherMap[T], ) (*heartbeatpb.TableSpan, uint64, int64) { - var prevTableSpan *heartbeatpb.TableSpan - var startKey []byte - var endKey []byte - var schemaID int64 - var fakeStartTs uint64 = math.MaxUint64 // we calculate the fake startTs as the min-checkpointTs of these dispatchers + var ( + prevTableSpan *heartbeatpb.TableSpan + startKey []byte + endKey []byte + schemaID int64 + // The fake startTs is calculated as the min checkpointTs of these dispatchers. + fakeStartTs uint64 = math.MaxUint64 + ) for idx, id := range dispatcherIDs { dispatcherItem, ok := dispatcherMap.Get(id) if !ok { log.Error("merge dispatcher failed, the dispatcher is not found", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Any("dispatcherID", id)) return nil, 0, 0 } if dispatcherItem.GetComponentStatus() != heartbeatpb.ComponentState_Working { log.Error("merge dispatcher failed, the dispatcher is not working", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Any("dispatcherID", id), zap.Int64("mode", dispatcherItem.GetMode()), zap.Any("componentStatus", dispatcherItem.GetComponentStatus())) @@ -173,7 +180,8 @@ func createMergedSpan[T dispatcher.Dispatcher](changefeedID common.ChangeFeedID, currentTableSpan := dispatcherItem.GetTableSpan() if !common.IsTableSpanConsecutive(prevTableSpan, currentTableSpan) { log.Error("merge dispatcher failed, the dispatcherIDs are not consecutive", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Any("dispatcherIDs", dispatcherIDs), zap.Int64("mode", dispatcherItem.GetMode()), ) @@ -223,7 +231,8 @@ func registerMergeDispatcher[T dispatcher.Dispatcher](changefeedID common.Change func() { mergedDispatcher.SetComponentStatus(heartbeatpb.ComponentState_MergeReady) log.Info("merge dispatcher is ready", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Stringer("dispatcherID", mergedDispatcher.GetId()), zap.Int64("mode", mergedDispatcher.GetMode()), ) @@ -242,7 +251,8 @@ func removeDispatcher[T dispatcher.Dispatcher](e *DispatcherManager, if ok { if dispatcherItem.GetTryRemoving() { log.Info("dispatcher is already in removing state, skip repeated remove request", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Stringer("dispatcherID", id)) return } @@ -256,7 +266,8 @@ func removeDispatcher[T dispatcher.Dispatcher](e *DispatcherManager, err := appcontext.GetService[*HeartBeatCollector](appcontext.HeartbeatCollector).RemoveCheckpointTsMessage(changefeedID) if err != nil { log.Error("remove checkpointTs message failed", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Error(err), ) } @@ -267,7 +278,8 @@ func removeDispatcher[T dispatcher.Dispatcher](e *DispatcherManager, dispatcherItem.SetTryRemoving() log.Info("submitted async remove task", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Stringer("dispatcherID", id)) } else { statusesChan <- dispatcher.TableSpanStatusWithSeq{ @@ -307,7 +319,8 @@ func closeAllDispatchers[T dispatcher.Dispatcher](changefeedID common.ChangeFeed err := appcontext.GetService[*HeartBeatCollector](appcontext.HeartbeatCollector).RemoveCheckpointTsMessage(changefeedID) if err != nil { log.Error("remove checkpointTs message failed", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Error(err), ) } diff --git a/downstreamadapter/dispatchermanager/dispatcher_manager_merge.go b/downstreamadapter/dispatchermanager/dispatcher_manager_merge.go index b2921c1b1f..eb15c5b3c9 100644 --- a/downstreamadapter/dispatchermanager/dispatcher_manager_merge.go +++ b/downstreamadapter/dispatchermanager/dispatcher_manager_merge.go @@ -30,7 +30,8 @@ func (e *DispatcherManager) TrackMergeOperator(req *heartbeatpb.MergeDispatcherR mergedID := common.NewDispatcherIDFromPB(req.MergedDispatcherID) if mergedID.IsZero() { log.Warn("ignore merge operator with invalid merged dispatcher ID", - zap.Stringer("changefeedID", e.changefeedID), + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Int64("mode", req.Mode)) return } @@ -56,7 +57,8 @@ func (e *DispatcherManager) MaybeCleanupMergeOperator(req *heartbeatpb.MergeDisp return } log.Info("cleanup merge operator because merged dispatcher not found", - zap.Stringer("changefeedID", e.changefeedID), + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.String("dispatcherID", mergedID.String()), zap.Int64("mode", req.Mode)) e.RemoveMergeOperator(mergedID) @@ -73,7 +75,8 @@ func (e *DispatcherManager) cleanupFinishedMergeOperators() { } mergedID := common.NewDispatcherIDFromPB(req.MergedDispatcherID) log.Info("cleanup finished merge operator", - zap.Stringer("changefeedID", e.changefeedID), + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.String("dispatcherID", mergedID.String()), zap.Int64("mode", req.Mode)) e.RemoveMergeOperator(mergedID) diff --git a/downstreamadapter/dispatchermanager/dispatcher_manager_redo.go b/downstreamadapter/dispatchermanager/dispatcher_manager_redo.go index 938063112d..6914bf29d8 100644 --- a/downstreamadapter/dispatchermanager/dispatcher_manager_redo.go +++ b/downstreamadapter/dispatchermanager/dispatcher_manager_redo.go @@ -151,10 +151,13 @@ func (e *DispatcherManager) NewTableTriggerRedoDispatcher(id *heartbeatpb.Dispat err := e.collectRedoMeta(e.ctx) e.handleError(e.ctx, err) }() - log.Info("table trigger redo dispatcher created", - zap.Stringer("changefeedID", e.changefeedID), + log.Info("add dispatcher done", + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Stringer("dispatcherID", redoDispatcher.GetId()), zap.Uint64("startTs", redoDispatcher.GetStartTs()), + zap.String("kind", "tableTrigger"), + zap.Bool("redo", true), ) return nil } @@ -237,16 +240,20 @@ func (e *DispatcherManager) newRedoDispatchers(infos map[common.DispatcherID]dis e.metricRedoEventDispatcherCount.Inc() } - log.Info("new redo dispatcher created", - zap.Stringer("changefeedID", e.changefeedID), + log.Info("add dispatcher done", + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Stringer("dispatcherID", id), zap.Int64("startTs", startTsList[idx]), - zap.Bool("skipDMLAsStartTs", scheduleSkipDMLAsStartTsList[idx])) + zap.Bool("skipDMLAsStartTs", scheduleSkipDMLAsStartTsList[idx]), + zap.Bool("redo", true)) } e.metricRedoCreateDispatcherDuration.Observe(time.Since(start).Seconds() / float64(len(dispatcherIds))) - log.Info("batch create new redo dispatchers", - zap.Stringer("changefeedID", e.changefeedID), + log.Info("add dispatchers done", + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Int("count", len(dispatcherIds)), + zap.Bool("redo", true), zap.Duration("duration", time.Since(start)), ) return nil @@ -284,10 +291,12 @@ func (e *DispatcherManager) mergeRedoDispatcher(dispatcherIDs []common.Dispatche e.sharedInfo, ) - log.Info("new redo dispatcher created(merge dispatcher)", - zap.Stringer("changefeedID", e.changefeedID), + log.Info("add dispatcher done", + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Stringer("dispatcherID", mergedDispatcherID), - zap.Int64("tableID", mergedSpan.TableID)) + zap.String("kind", "merge"), + zap.Bool("redo", true)) e.writePathMu.Lock() if e.writePathClosed.Load() { @@ -311,9 +320,11 @@ func (e *DispatcherManager) cleanRedoDispatcher(id common.DispatcherID, schemaID } else { e.metricRedoEventDispatcherCount.Dec() } - log.Info("redo dispatcher completely stopped, and delete it from event dispatcher manager", - zap.Stringer("changefeedID", e.changefeedID), + log.Info("remove dispatcher done", + zap.String("keyspace", e.changefeedID.Keyspace()), + zap.String("changefeed", e.changefeedID.Name()), zap.Stringer("dispatcherID", id), + zap.Bool("redo", true), ) } diff --git a/downstreamadapter/dispatchermanager/helper.go b/downstreamadapter/dispatchermanager/helper.go index 0eb247e83b..68f43d8e29 100644 --- a/downstreamadapter/dispatchermanager/helper.go +++ b/downstreamadapter/dispatchermanager/helper.go @@ -400,7 +400,8 @@ func createDispatcherByInfo( if err != nil { if IsWritePathClosedError(err) { log.Info("dispatcher manager write path closed, keep add operators for redo dispatchers", - zap.String("changefeedID", dispatcherManager.changefeedID.String()), + zap.String("keyspace", dispatcherManager.changefeedID.Keyspace()), + zap.String("changefeed", dispatcherManager.changefeedID.Name()), zap.Int("count", len(redoInfos)), zap.Error(err), ) @@ -415,7 +416,8 @@ func createDispatcherByInfo( if err != nil { if IsWritePathClosedError(err) { log.Info("dispatcher manager write path closed, keep add operators", - zap.String("changefeedID", dispatcherManager.changefeedID.String()), + zap.String("keyspace", dispatcherManager.changefeedID.Keyspace()), + zap.String("changefeed", dispatcherManager.changefeedID.Name()), zap.Int("count", len(infos)), zap.Error(err), ) @@ -833,9 +835,10 @@ func logStaleMaintainerControlMessage( admission maintainerRequestAdmission, extraFields ...zap.Field, ) { - fields := make([]zap.Field, 0, 5+len(extraFields)) + fields := make([]zap.Field, 0, 6+len(extraFields)) fields = append(fields, - zap.String("changefeedID", changefeedID.String()), + zap.String("keyspace", changefeedID.GetKeyspace()), + zap.String("changefeed", changefeedID.GetName()), zap.String("from", from.String()), zap.Uint64(epochField, maintainerEpoch), zap.Uint64("currentMaintainerEpoch", admission.currentEpoch), diff --git a/downstreamadapter/dispatchermanager/task.go b/downstreamadapter/dispatchermanager/task.go index 32fa728f83..6f728f0746 100644 --- a/downstreamadapter/dispatchermanager/task.go +++ b/downstreamadapter/dispatchermanager/task.go @@ -184,7 +184,8 @@ func shouldAbortMerge[T dispatcher.Dispatcher](t *MergeCheckTask, dispatcherMap func abortMerge[T dispatcher.Dispatcher](t *MergeCheckTask, dispatcherMap *DispatcherMap[T], sinkType common.SinkType, reason string) { log.Info("abort merge", - zap.Stringer("changefeedID", t.manager.changefeedID), + zap.String("keyspace", t.manager.changefeedID.Keyspace()), + zap.String("changefeed", t.manager.changefeedID.Name()), zap.String("reason", reason), zap.Int64("mode", t.mergedDispatcher.GetMode()), zap.Any("dispatcherIDs", t.dispatcherIDs), @@ -224,7 +225,8 @@ func abortMerge[T dispatcher.Dispatcher](t *MergeCheckTask, dispatcherMap *Dispa func doMerge[T dispatcher.Dispatcher](t *MergeCheckTask, dispatcherMap *DispatcherMap[T]) { log.Info("do merge", - zap.Stringer("changefeedID", t.manager.changefeedID), + zap.String("keyspace", t.manager.changefeedID.Keyspace()), + zap.String("changefeed", t.manager.changefeedID.Name()), zap.Int64("mode", t.mergedDispatcher.GetMode()), zap.Any("dispatcherIDs", t.dispatcherIDs), zap.Any("dispatcherID", t.mergedDispatcher.GetId()), @@ -294,7 +296,8 @@ func doMerge[T dispatcher.Dispatcher](t *MergeCheckTask, dispatcherMap *Dispatch t.mergedDispatcher.SetComponentStatus(heartbeatpb.ComponentState_Initializing) appcontext.GetService[*eventcollector.EventCollector](appcontext.EventCollector).CommitAddDispatcher(t.mergedDispatcher, startTs) log.Info("merge dispatcher commit", - zap.Stringer("changefeedID", t.manager.changefeedID), + zap.String("keyspace", t.manager.changefeedID.Keyspace()), + zap.String("changefeed", t.manager.changefeedID.Name()), zap.Stringer("dispatcherID", t.mergedDispatcher.GetId()), zap.Int64("mode", t.mergedDispatcher.GetMode()), zap.Uint64("startTs", startTs), @@ -311,8 +314,9 @@ func doMerge[T dispatcher.Dispatcher](t *MergeCheckTask, dispatcherMap *Dispatch dispatcher, ok := dispatcherMap.Get(id) if !ok { log.Warn("dispatcher not found when do merge, skip remove", - zap.Stringer("dispatcherID", id), - zap.Stringer("changefeedID", t.manager.changefeedID)) + zap.String("keyspace", t.manager.changefeedID.Keyspace()), + zap.String("changefeed", t.manager.changefeedID.Name()), + zap.Stringer("dispatcherID", id)) continue } dispatcher.Remove() @@ -398,7 +402,8 @@ func mergeMergedStartTsCandidateWithMySQLRecovery(t *MergeCheckTask, candidate m if err != nil { log.Error("get table recovery info for merge dispatcher failed", zap.Stringer("dispatcherID", t.mergedDispatcher.GetId()), - zap.Stringer("changefeedID", t.manager.changefeedID), + zap.String("keyspace", t.manager.changefeedID.Keyspace()), + zap.String("changefeed", t.manager.changefeedID.Name()), zap.Error(err), ) t.mergedDispatcher.HandleError(err) @@ -418,7 +423,8 @@ func mergeMergedStartTsCandidateWithMySQLRecovery(t *MergeCheckTask, candidate m } log.Info("get table recovery info for merge dispatcher", - zap.Stringer("changefeedID", t.manager.changefeedID), + zap.String("keyspace", t.manager.changefeedID.Keyspace()), + zap.String("changefeed", t.manager.changefeedID.Name()), zap.Uint64("mergeStartTsCandidate", candidate.startTs), zap.Any("recoveryStartTs", newStartTsList), zap.Any("recoverySkipSyncpointAtStartTsList", skipSyncpointAtStartTsList), @@ -456,13 +462,15 @@ func resolveMergedDispatcherStartTs(t *MergeCheckTask, minCheckpointTs uint64, p if candidate.allSamePending { if !candidate.pendingIsSyncPoint && candidate.pendingCommitTs == 0 { log.Warn("pending ddl has zero commit ts, fallback to min checkpoint ts", - zap.Stringer("changefeedID", t.manager.changefeedID), + zap.String("keyspace", t.manager.changefeedID.Keyspace()), + zap.String("changefeed", t.manager.changefeedID.Name()), zap.Uint64("minCheckpointTs", minCheckpointTs), zap.Any("dispatcherID", t.mergedDispatcher.GetId())) } log.Info("merge dispatcher uses pending block event to calculate start ts", - zap.Stringer("changefeedID", t.manager.changefeedID), - zap.Any("dispatcherID", t.mergedDispatcher.GetId()), + zap.String("keyspace", t.manager.changefeedID.Keyspace()), + zap.String("changefeed", t.manager.changefeedID.Name()), + zap.Any("mergedDispatcher", t.mergedDispatcher.GetId()), zap.Uint64("pendingCommitTs", candidate.pendingCommitTs), zap.Bool("pendingIsSyncPoint", candidate.pendingIsSyncPoint), zap.Uint64("startTs", candidate.startTs), @@ -509,7 +517,9 @@ func (t *RemoveDispatcherTask) Execute() time.Time { if ok { // Successfully closed, execute Remove t.dispatcherItem.Remove() - log.Info("dispatcher removed successfully", + log.Info("remove dispatcher done", + zap.String("keyspace", t.manager.changefeedID.Keyspace()), + zap.String("changefeed", t.manager.changefeedID.Name()), zap.Stringer("dispatcherID", t.dispatcherItem.GetId()), zap.Int("retryCount", t.retryCount)) return time.Time{} // Task completed diff --git a/downstreamadapter/dispatcherorchestrator/dispatcher_orchestrator.go b/downstreamadapter/dispatcherorchestrator/dispatcher_orchestrator.go index 8bfa462bba..ace28b3b98 100644 --- a/downstreamadapter/dispatcherorchestrator/dispatcher_orchestrator.go +++ b/downstreamadapter/dispatcherorchestrator/dispatcher_orchestrator.go @@ -221,6 +221,7 @@ func (m *DispatcherOrchestrator) handleBootstrapRequest( if !exists { if closed && (maintainerEpoch == 0 || maintainerEpoch <= closedEpoch) { log.Warn("drop stale maintainer bootstrap request after close", + zap.String("keyspace", cfId.Keyspace()), zap.String("changefeed", cfId.Name()), zap.String("from", from.String()), zap.Uint64("requestMaintainerEpoch", maintainerEpoch), @@ -260,11 +261,17 @@ func (m *DispatcherOrchestrator) handleBootstrapRequest( if err != nil { if dispatchermanager.IsWritePathClosedError(err) || m.fenced.Load() || m.closed.Load() { log.Info("dispatcher manager write path closed while creating dispatcher manager", - zap.Stringer("changefeedID", cfId), zap.Duration("duration", time.Since(start)), zap.Error(err)) + zap.String("keyspace", cfId.Keyspace()), + zap.String("changefeed", cfId.Name()), + zap.Duration("duration", time.Since(start)), + zap.Error(err)) return nil } log.Error("failed to create new dispatcher manager", - zap.Any("changefeedID", cfId.Name()), zap.Duration("duration", time.Since(start)), zap.Error(err)) + zap.String("keyspace", cfId.Keyspace()), + zap.String("changefeed", cfId.Name()), + zap.Duration("duration", time.Since(start)), + zap.Error(err)) appcontext.GetService[*dispatchermanager.HeartBeatCollector](appcontext.HeartbeatCollector).RemoveDispatcherManager(cfId) @@ -274,7 +281,10 @@ func (m *DispatcherOrchestrator) handleBootstrapRequest( Err: newRunningError(from, err), } log.Error("create new dispatcher manager failed", - zap.Any("changefeedID", cfId.Name()), zap.Duration("duration", time.Since(start)), zap.Error(err)) + zap.String("keyspace", cfId.Keyspace()), + zap.String("changefeed", cfId.Name()), + zap.Duration("duration", time.Since(start)), + zap.Error(err)) return m.sendResponse(from, messaging.MaintainerManagerTopic, response) } @@ -293,6 +303,7 @@ func (m *DispatcherOrchestrator) handleBootstrapRequest( manager.MaintainerFenceMu.Lock() if !manager.CanUpdateMaintainer(from, maintainerEpoch) { log.Warn("drop stale maintainer bootstrap request", + zap.String("keyspace", cfId.Keyspace()), zap.String("changefeed", cfId.Name()), zap.String("from", from.String()), zap.Uint64("requestMaintainerEpoch", maintainerEpoch), @@ -316,6 +327,7 @@ func (m *DispatcherOrchestrator) handleBootstrapRequest( } if !manager.TryUpdateMaintainer(from, maintainerEpoch) { log.Warn("drop stale maintainer bootstrap request after trigger validation", + zap.String("keyspace", cfId.Keyspace()), zap.String("changefeed", cfId.Name()), zap.String("from", from.String()), zap.Uint64("requestMaintainerEpoch", maintainerEpoch), @@ -486,7 +498,8 @@ func ensureBootstrapTableTriggerDispatcher( if err := create(); err != nil { if !dispatchermanager.IsWritePathClosedError(err) { log.Error("failed to create table trigger dispatcher", - zap.Stringer("changefeedID", cfID), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.String("triggerName", triggerName), zap.Error(err)) } @@ -503,7 +516,8 @@ func validateBootstrapNoTableTriggerDispatcher( // A nil trigger ID is valid only after local trigger cleanup has removed the // previous owner; otherwise owner transfer would leave stale DDL ownership. log.Error("table trigger dispatcher present during nil trigger bootstrap", - zap.Stringer("changefeedID", cfID), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.String("triggerName", triggerName), zap.Stringer("dispatcherID", currentID)) return errors.ErrChangefeedInitTableTriggerDispatcherFailed. @@ -521,7 +535,8 @@ func validateBootstrapTableTriggerDispatcherID( return nil } log.Error("table trigger dispatcher id mismatch during bootstrap", - zap.Stringer("changefeedID", cfID), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.String("triggerName", triggerName), zap.Stringer("expectedDispatcherID", expectedID), zap.Stringer("dispatcherID", currentID)) @@ -539,14 +554,16 @@ func (m *DispatcherOrchestrator) handleBootstrapTriggerError( ) error { if dispatchermanager.IsWritePathClosedError(err) { log.Info("dispatcher manager write path closed while creating table trigger dispatcher", - zap.Stringer("changefeedID", cfID), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.String("triggerName", triggerName), zap.Error(err)) return nil } if m.fenced.Load() || m.closed.Load() { log.Info("dispatcher orchestrator closed while creating table trigger dispatcher", - zap.Stringer("changefeedID", cfID), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.String("triggerName", triggerName), zap.Error(err)) return nil @@ -573,12 +590,14 @@ func (m *DispatcherOrchestrator) handlePostBootstrapRequest( if !exists { log.Error("Receive post bootstrap request but there is no table trigger event dispatcher", - zap.Any("changefeedID", cfId.Name())) + zap.String("keyspace", cfId.Keyspace()), + zap.String("changefeed", cfId.Name())) return nil } manager.MaintainerFenceMu.Lock() if !manager.IsMaintainerRequestAllowed(from, req.MaintainerEpoch) { log.Warn("drop stale maintainer post bootstrap request", + zap.String("keyspace", cfId.Keyspace()), zap.String("changefeed", cfId.Name()), zap.String("from", from.String()), zap.Uint64("requestMaintainerEpoch", req.MaintainerEpoch), @@ -592,7 +611,9 @@ func (m *DispatcherOrchestrator) handlePostBootstrapRequest( err := errors.ErrChangefeedInitTableTriggerDispatcherFailed. GenWithStackByArgs("receive post bootstrap request but there is no table trigger event dispatcher") log.Error("receive post bootstrap request but there is no table trigger event dispatcher", - zap.Any("changefeedID", cfId.Name()), zap.Error(err)) + zap.String("keyspace", cfId.Keyspace()), + zap.String("changefeed", cfId.Name()), + zap.Error(err)) manager.MaintainerFenceMu.Unlock() return m.sendPostBootstrapErrorResponse(from, req, err) } @@ -600,7 +621,8 @@ func (m *DispatcherOrchestrator) handlePostBootstrapRequest( actualDispatcherID := common.NewDispatcherIDFromPB(req.TableTriggerEventDispatcherId) if expectedDispatcherID != actualDispatcherID { log.Error("Receive post bootstrap request but the table trigger event dispatcher id is not match", - zap.Any("changefeedID", cfId.Name()), + zap.String("keyspace", cfId.Keyspace()), + zap.String("changefeed", cfId.Name()), zap.String("expectedDispatcherID", expectedDispatcherID.String()), zap.String("dispatcherID", actualDispatcherID.String())) @@ -616,12 +638,16 @@ func (m *DispatcherOrchestrator) handlePostBootstrapRequest( if err != nil { if dispatchermanager.IsWritePathClosedError(err) { log.Info("dispatcher manager write path closed while initializing table trigger event dispatcher", - zap.Any("changefeedID", cfId.Name()), zap.Error(err)) + zap.String("keyspace", cfId.Keyspace()), + zap.String("changefeed", cfId.Name()), + zap.Error(err)) manager.MaintainerFenceMu.Unlock() return nil } log.Error("failed to initialize table trigger event dispatcher", - zap.Any("changefeedID", cfId.Name()), zap.Error(err)) + zap.String("keyspace", cfId.Keyspace()), + zap.String("changefeed", cfId.Name()), + zap.Error(err)) manager.MaintainerFenceMu.Unlock() return m.handleDispatcherError(from, req.ChangefeedID, req.MaintainerEpoch, err) } @@ -630,12 +656,16 @@ func (m *DispatcherOrchestrator) handlePostBootstrapRequest( if err != nil { if dispatchermanager.IsWritePathClosedError(err) { log.Info("dispatcher manager write path closed while initializing table trigger redo dispatcher", - zap.Any("changefeedID", cfId.Name()), zap.Error(err)) + zap.String("keyspace", cfId.Keyspace()), + zap.String("changefeed", cfId.Name()), + zap.Error(err)) manager.MaintainerFenceMu.Unlock() return nil } log.Error("failed to initialize table trigger redo dispatcher", - zap.Any("changefeedID", cfId.Name()), zap.Error(err)) + zap.String("keyspace", cfId.Keyspace()), + zap.String("changefeed", cfId.Name()), + zap.Error(err)) manager.MaintainerFenceMu.Unlock() return m.handleDispatcherError(from, req.ChangefeedID, req.MaintainerEpoch, err) } @@ -720,6 +750,7 @@ func (m *DispatcherOrchestrator) handleCloseRequest( // acknowledge the stale sender so removal-only maintainers can stop retrying. response.Success = true log.Warn("drop stale maintainer close request", + zap.String("keyspace", cfId.Keyspace()), zap.String("changefeed", cfId.Name()), zap.String("from", from.String()), zap.Uint64("requestMaintainerEpoch", req.MaintainerEpoch), @@ -733,7 +764,9 @@ func (m *DispatcherOrchestrator) handleCloseRequest( } log.Info("try close dispatcher manager", - zap.String("changefeed", cfId.String()), zap.Bool("success", response.Success)) + zap.String("keyspace", cfId.Keyspace()), + zap.String("changefeed", cfId.Name()), + zap.Bool("success", response.Success)) return m.sendResponse(from, messaging.MaintainerTopic, response) } @@ -979,7 +1012,8 @@ func retrieveOperatorsForBootstrapResponse( return true } log.Info("include stale remove operator in bootstrap response", - zap.String("changefeed", changefeedID.String()), + zap.String("keyspace", changefeedID.GetKeyspace()), + zap.String("changefeed", changefeedID.GetName()), zap.String("dispatcherID", req.Config.DispatcherID.String()), zap.String("from", req.From.String()), zap.Uint64("requestMaintainerEpoch", req.MaintainerEpoch), @@ -997,11 +1031,13 @@ func retrieveOperatorsForBootstrapResponse( if !dispatcherExists { if common.IsRedoMode(req.Config.Mode) { log.Error("Redo dispatcher not found, this should not happen", - zap.String("changefeed", changefeedID.String()), + zap.String("keyspace", changefeedID.GetKeyspace()), + zap.String("changefeed", changefeedID.GetName()), zap.String("dispatcherID", req.Config.DispatcherID.String())) } else { log.Error("Dispatcher not found, this should not happen", - zap.String("changefeed", changefeedID.String()), + zap.String("keyspace", changefeedID.GetKeyspace()), + zap.String("changefeed", changefeedID.GetName()), zap.String("dispatcherID", req.Config.DispatcherID.String())) } } diff --git a/downstreamadapter/eventcollector/dispatcher_session.go b/downstreamadapter/eventcollector/dispatcher_session.go index 9372679d3b..e5ab3074c1 100644 --- a/downstreamadapter/eventcollector/dispatcher_session.go +++ b/downstreamadapter/eventcollector/dispatcher_session.go @@ -379,7 +379,8 @@ func (s *dispatcherSession) retryCurrentRegistrationIfRemovedFrom(serverID node. return false } log.Info("dispatcher removed in current event service, retry registration", - zap.Stringer("changefeedID", s.target.GetChangefeedID()), + zap.String("keyspace", s.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", s.target.GetChangefeedID().Name()), zap.Stringer("dispatcherID", s.target.GetId()), zap.Stringer("eventServiceID", serverID)) if !s.beginRegister(serverID) { @@ -429,8 +430,9 @@ func (s *dispatcherSession) resetCurrentEventService() { serverID := s.connState.getCurrentEventServiceID() if serverID.IsEmpty() { log.Warn("skip reset because current event service is empty", - zap.Stringer("changefeedID", s.target.GetChangefeedID()), - zap.Stringer("dispatcherID", s.target.GetId())) + zap.String("keyspace", s.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", s.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", s.target.GetId())) return } s.doResetLocked(serverID, s.target.GetCheckpointTs()) @@ -457,8 +459,9 @@ func (s *dispatcherSession) doResetLocked(serverID node.ID, resetTs uint64) { msg := messaging.NewSingleTargetMessage(serverID, messaging.EventServiceTopic, resetRequest) s.sendMessage(msg) log.Info("send reset dispatcher request to event service", - zap.Stringer("changefeedID", s.target.GetChangefeedID()), - zap.Stringer("dispatcherID", s.target.GetId()), + zap.String("keyspace", s.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", s.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", s.target.GetId()), zap.Stringer("eventServiceID", serverID), zap.Uint64("epoch", epoch), zap.Uint64("resetTs", resetTs)) @@ -483,8 +486,9 @@ func (s *dispatcherSession) remove() { // cleanup of a stale registration on another event service. func (s *dispatcherSession) removeFromLocked(serverID node.ID) { log.Info("send remove dispatcher request to event service", - zap.Stringer("changefeedID", s.target.GetChangefeedID()), - zap.Stringer("dispatcherID", s.target.GetId()), + zap.String("keyspace", s.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", s.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", s.target.GetId()), zap.Stringer("eventServiceID", serverID)) msg := messaging.NewSingleTargetMessage( serverID, @@ -564,21 +568,24 @@ func (s *dispatcherSession) handleAcceptedLocalReadyLocked(resetTs uint64) { return } log.Info("received ready signal from local event service, prepare to reset the dispatcher", - zap.Stringer("changefeedID", s.target.GetChangefeedID()), - zap.Stringer("dispatcherID", s.target.GetId())) + zap.String("keyspace", s.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", s.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", s.target.GetId())) s.doResetLocked(s.localServerID, resetTs) } func (s *dispatcherSession) handleAcceptedRemoteReadyLocked(serverID node.ID) { if s.readyCallback != nil { log.Panic("ready callback should be nil when accepting remote ready", - zap.Stringer("changefeedID", s.target.GetChangefeedID()), - zap.Stringer("dispatcherID", s.target.GetId()), + zap.String("keyspace", s.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", s.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", s.target.GetId()), zap.Stringer("eventServiceID", serverID)) } log.Info("received ready signal from remote event service, prepare to reset the dispatcher", - zap.Stringer("changefeedID", s.target.GetChangefeedID()), - zap.Stringer("dispatcherID", s.target.GetId()), + zap.String("keyspace", s.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", s.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", s.target.GetId()), zap.Stringer("eventServiceID", serverID)) s.doResetLocked(serverID, s.target.GetCheckpointTs()) } @@ -672,7 +679,8 @@ func (s *dispatcherSession) startRemoteProbing(nodes []string) { return } log.Info("set remote candidates", - zap.Stringer("changefeedID", s.target.GetChangefeedID()), + zap.String("keyspace", s.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", s.target.GetChangefeedID().Name()), zap.Stringer("dispatcherID", s.target.GetId()), zap.Int64("tableID", s.target.GetTableSpan().TableID), zap.Strings("nodes", nodes)) diff --git a/downstreamadapter/eventcollector/dispatcher_stat.go b/downstreamadapter/eventcollector/dispatcher_stat.go index 3ab6e8cd61..68465d5789 100644 --- a/downstreamadapter/eventcollector/dispatcher_stat.go +++ b/downstreamadapter/eventcollector/dispatcher_stat.go @@ -118,8 +118,9 @@ func (d *dispatcherStat) loadCurrentEpochState() *dispatcherEpochState { state := d.currentEpoch.Load() if state == nil { log.Panic("dispatcher epoch state is not initialized", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID())) + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", d.getDispatcherID())) } return state } @@ -163,14 +164,10 @@ func (d *dispatcherStat) verifyEventSequence(event dispatcher.DispatcherEvent, s // check the invariant that handshake event is the first event of every epoch if event.GetType() != commonEvent.TypeHandshakeEvent && state.lastEventSeq.Load() == 0 { log.Warn("receive non-handshake event before handshake event, reset the dispatcher", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID()), - zap.Stringer("eventServiceID", event.From), - zap.Uint64("eventEpoch", event.GetEpoch()), - zap.Uint64("dispatcherEpoch", state.epoch), - zap.String("eventType", commonEvent.TypeToString(event.GetType())), - zap.Uint64("receivedSeq", event.GetSeq()), - zap.Uint64("commitTs", event.GetCommitTs())) + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", d.getDispatcherID()), + zap.Any("event", event.Event)) return false } @@ -193,17 +190,15 @@ func (d *dispatcherStat) verifyEventSequence(event dispatcher.DispatcherEvent, s if event.GetSeq() != expectedSeq { log.Warn("receive an out-of-order event, reset the dispatcher", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID()), - zap.Stringer("eventServiceID", event.From), - zap.Uint64("eventEpoch", event.GetEpoch()), - zap.Uint64("dispatcherEpoch", state.epoch), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), + zap.Uint64("commitTs", event.GetCommitTs()), + zap.Stringer("dispatcher", d.getDispatcherID()), zap.String("eventType", commonEvent.TypeToString(event.GetType())), zap.Uint64("lastEventSeq", lastEventSeq), zap.Uint64("lastEventCommitTs", d.lastEventCommitTs.Load()), zap.Uint64("receivedSeq", event.GetSeq()), - zap.Uint64("expectedSeq", expectedSeq), - zap.Uint64("commitTs", event.GetCommitTs())) + zap.Uint64("expectedSeq", expectedSeq)) return false } case commonEvent.TypeBatchDMLEvent: @@ -220,8 +215,7 @@ func (d *dispatcherStat) verifyEventSequence(event dispatcher.DispatcherEvent, s zap.Uint64("lastEventSeq", expectedSeq-1), zap.Uint64("lastEventCommitTs", d.lastEventCommitTs.Load()), zap.Uint64("receivedSeq", e.Seq), - zap.Uint64("expectedSeq", expectedSeq), - zap.Uint64("commitTs", e.CommitTs)) + zap.Uint64("expectedSeq", expectedSeq)) return false } } @@ -249,7 +243,8 @@ func (d *dispatcherStat) shouldForwardEventByCommitTs(event dispatcher.Dispatche } if shouldIgnore { log.Warn("receive a event older than sendCommitTs, ignore it", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), zap.Int64("tableID", d.target.GetTableSpan().TableID), zap.Stringer("dispatcherID", d.getDispatcherID()), zap.Uint64("eventCommitTs", event.GetCommitTs()), @@ -330,8 +325,9 @@ func (d *dispatcherStat) handleBatchDataEvents(events []dispatcher.DispatcherEve if !d.isFromCurrentEpoch(event, state) { if logger.IsDebugEnabled() { log.Debug("receive DML/Resolved event from a stale epoch, ignore it", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID()), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", d.getDispatcherID()), zap.String("eventType", commonEvent.TypeToString(event.GetType())), zap.Any("event", event.Event)) } @@ -353,8 +349,9 @@ func (d *dispatcherStat) handleBatchDataEvents(events []dispatcher.DispatcherEve tableInfo := d.tableInfo.Load().(*common.TableInfo) if tableInfo == nil { log.Panic("should not happen: table info should be set before batch DML event", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID())) + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", d.getDispatcherID())) } // The cloudstorage sink replicate different file according the table version. // If one table is just scheduled to a new processor, the tableInfoVersion should be @@ -373,7 +370,8 @@ func (d *dispatcherStat) handleBatchDataEvents(events []dispatcher.DispatcherEve } default: log.Panic("should not happen: unknown event type in batch data events", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), zap.Stringer("dispatcherID", d.getDispatcherID()), zap.String("eventType", commonEvent.TypeToString(event.GetType()))) } @@ -386,7 +384,8 @@ func (d *dispatcherStat) handleBatchDataEvents(events []dispatcher.DispatcherEve if hasDML { failpoint.Inject("InjectResetDispatcherAfterBatchDataEvents", func() { log.Info("inject dispatcher reset after batch data events", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), zap.Stringer("dispatcherID", d.getDispatcherID()), zap.Uint64("checkpointTs", d.target.GetCheckpointTs())) d.session.resetCurrentEventService() @@ -412,8 +411,9 @@ func (d *dispatcherStat) handleSingleDataEvents(events []dispatcher.DispatcherEv state := d.loadCurrentEpochState() if !d.isFromCurrentEpoch(events[0], state) { log.Info("receive DDL/SyncPoint/Handshake event from a stale epoch, ignore it", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID()), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", d.getDispatcherID()), zap.String("eventType", commonEvent.TypeToString(events[0].GetType())), zap.Uint64("eventEpoch", events[0].GetEpoch()), zap.Uint64("dispatcherEpoch", state.epoch), @@ -437,8 +437,9 @@ func (d *dispatcherStat) handleSingleDataEvents(events []dispatcher.DispatcherEv ddl, err := d.target.GetRouter().ApplyToDDLEvent(ddl) if err != nil { log.Error("failed to apply routing to DDL event", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID()), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", d.getDispatcherID()), zap.Error(err)) if target, ok := d.target.(dispatcher.Dispatcher); ok { target.HandleError(err) @@ -487,11 +488,12 @@ func (d *dispatcherStat) updateTableInfoByDDL(ddl *commonEvent.DDLEvent) { if change.PhysicalTableID != tableSpan.TableID { log.Error("table state change was delivered to the wrong dispatcher", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID()), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), + zap.Uint64("commitTs", ddl.FinishedTs), + zap.Stringer("dispatcher", d.getDispatcherID()), zap.Int64("expectedPhysicalTableID", tableSpan.TableID), - zap.Int64("actualPhysicalTableID", change.PhysicalTableID), - zap.Uint64("commitTs", ddl.FinishedTs)) + zap.Int64("actualPhysicalTableID", change.PhysicalTableID)) return } if change.Kind != commonEvent.TableStateUpdated { @@ -550,8 +552,9 @@ func (d *dispatcherStat) handleDropEvent(event dispatcher.DispatcherEvent) { dropEvent, ok := event.Event.(*commonEvent.DropEvent) if !ok { log.Panic("drop event is not a drop event", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID()), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", d.getDispatcherID()), zap.Any("event", event)) } @@ -559,17 +562,19 @@ func (d *dispatcherStat) handleDropEvent(event dispatcher.DispatcherEvent) { if !d.isFromCurrentEpoch(event, state) { if logger.IsDebugEnabled() { log.Debug("receive a drop event from a stale epoch, ignore it", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID()), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", d.getDispatcherID()), zap.Any("event", event.Event)) } return } log.Info("received a dropEvent, need to reset the dispatcher", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID()), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), zap.Uint64("commitTs", dropEvent.GetCommitTs()), + zap.Stringer("dispatcher", d.getDispatcherID()), zap.Uint64("sequence", dropEvent.GetSeq()), zap.Uint64("lastEventCommitTs", d.lastEventCommitTs.Load())) d.session.resetCurrentEventService() @@ -578,8 +583,9 @@ func (d *dispatcherStat) handleDropEvent(event dispatcher.DispatcherEvent) { func (d *dispatcherStat) handleHandshakeEvent(event dispatcher.DispatcherEvent) { log.Info("handle handshake event", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID()), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", d.getDispatcherID()), zap.Any("event", event)) handshakeEvent, ok := event.Event.(*commonEvent.HandshakeEvent) @@ -589,15 +595,17 @@ func (d *dispatcherStat) handleHandshakeEvent(event dispatcher.DispatcherEvent) state := d.loadCurrentEpochState() if !d.isFromCurrentEpoch(event, state) { log.Info("receive a handshake event from a stale epoch, ignore it", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID()), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", d.getDispatcherID()), zap.Any("event", event.Event)) return } if event.GetSeq() != 1 { log.Warn("should not happen: handshake event sequence number is not 1", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID()), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", d.getDispatcherID()), zap.Uint64("sequence", event.GetSeq())) return } @@ -606,8 +614,9 @@ func (d *dispatcherStat) handleHandshakeEvent(event dispatcher.DispatcherEvent) tableInfo, err := d.target.GetRouter().ApplyToTableInfo(tableInfo) if err != nil { log.Error("failed to apply routing to handshake table info", - zap.Stringer("changefeedID", d.target.GetChangefeedID()), - zap.Stringer("dispatcherID", d.getDispatcherID()), + zap.String("keyspace", d.target.GetChangefeedID().Keyspace()), + zap.String("changefeed", d.target.GetChangefeedID().Name()), + zap.Stringer("dispatcher", d.getDispatcherID()), zap.Error(err)) if target, ok := d.target.(dispatcher.Dispatcher); ok { target.HandleError(err) diff --git a/downstreamadapter/eventcollector/event_collector.go b/downstreamadapter/eventcollector/event_collector.go index 8bc17f39e8..6eb0c1b59a 100644 --- a/downstreamadapter/eventcollector/event_collector.go +++ b/downstreamadapter/eventcollector/event_collector.go @@ -256,13 +256,7 @@ func (c *EventCollector) PrepareAddDispatcher( readyCallback func(), ) { changefeedID := target.GetChangefeedID() - log.Info("add dispatcher", zap.Stringer("changefeedID", changefeedID), zap.Stringer("dispatcherID", target.GetId())) - defer func() { - log.Info("add dispatcher done", - zap.Stringer("changefeedID", changefeedID), - zap.Stringer("dispatcherID", target.GetId()), zap.Int64("tableID", target.GetTableSpan().GetTableID()), - zap.Uint64("startTs", target.GetStartTs()), zap.Int64("mode", target.GetMode())) - }() + start := time.Now() eventCollectorRegisteredDispatcherCount.Inc() stat := newDispatcherStat(target, c, readyCallback) @@ -283,21 +277,35 @@ func (c *EventCollector) PrepareAddDispatcher( ) err := ds.AddPath(target.GetId(), stat, areaSetting) if err != nil { - log.Warn("add dispatcher to dynamic stream failed", zap.Error(err)) + log.Warn("add dispatcher failed", + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), + zap.Stringer("dispatcherID", target.GetId()), + zap.Int64("tableID", target.GetTableSpan().GetTableID()), + zap.Error(err)) } stat.run() + log.Info("add dispatcher done", + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), + zap.Stringer("dispatcherID", target.GetId()), + zap.Int64("tableID", target.GetTableSpan().GetTableID()), + zap.Uint64("startTs", target.GetStartTs()), + zap.Int64("mode", target.GetMode()), + zap.Duration("duration", time.Since(start))) } // CommitAddDispatcher notify local event service that the dispatcher is ready to receive events. func (c *EventCollector) CommitAddDispatcher(target dispatcher.DispatcherService, startTs uint64) { changefeedID := target.GetChangefeedID() - log.Info("commit add dispatcher", zap.Stringer("changefeedID", changefeedID), zap.Stringer("dispatcherID", target.GetId()), - zap.Int64("tableID", target.GetTableSpan().GetTableID()), zap.Uint64("startTs", startTs)) value, ok := c.dispatcherMap.Load(target.GetId()) if !ok { - log.Warn("dispatcher not found when commit add dispatcher", - zap.Stringer("changefeedID", changefeedID), zap.Stringer("dispatcherID", target.GetId()), - zap.Int64("tableID", target.GetTableSpan().GetTableID()), zap.Uint64("startTs", startTs)) + log.Warn("add dispatcher failed since dispatcher not found", + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), + zap.Stringer("dispatcherID", target.GetId()), + zap.Int64("tableID", target.GetTableSpan().GetTableID()), + zap.Uint64("startTs", startTs)) return } stat := value.(*dispatcherStat) @@ -306,11 +314,22 @@ func (c *EventCollector) CommitAddDispatcher(target dispatcher.DispatcherService func (c *EventCollector) RemoveDispatcher(target dispatcher.DispatcherService) { changefeedID := target.GetChangefeedID() - log.Info("remove dispatcher", zap.Stringer("changefeedID", changefeedID), zap.Stringer("dispatcherID", target.GetId())) + start := time.Now() + var remaining *int32 defer func() { - log.Info("remove dispatcher done", - zap.Stringer("changefeedID", changefeedID), zap.Stringer("dispatcherID", target.GetId()), - zap.Int64("tableID", target.GetTableSpan().GetTableID())) + fields := []zap.Field{ + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), + zap.Stringer("dispatcherID", target.GetId()), + zap.Int64("tableID", target.GetTableSpan().GetTableID()), + zap.Uint64("startTs", target.GetStartTs()), + zap.Int64("mode", target.GetMode()), + zap.Duration("duration", time.Since(start)), + } + if remaining != nil { + fields = append(fields, zap.Int32("remaining", *remaining)) + } + log.Info("remove dispatcher done", fields...) }() value, ok := c.dispatcherMap.Load(target.GetId()) if !ok { @@ -322,25 +341,28 @@ func (c *EventCollector) RemoveDispatcher(target dispatcher.DispatcherService) { ds := c.getDynamicStream(target.GetMode()) err := ds.RemovePath(target.GetId()) if err != nil { - log.Error("remove dispatcher from dynamic stream failed", zap.Error(err)) + log.Error("remove dispatcher failed", + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), + zap.Stringer("dispatcherID", target.GetId()), + zap.Int64("tableID", target.GetTableSpan().GetTableID()), + zap.Error(err)) } c.dispatcherMap.Delete(target.GetId()) v, ok := c.changefeedMap.Load(changefeedID.ID()) if !ok { - log.Warn("changefeed stat not found when removing dispatcher", zap.Stringer("changefeedID", changefeedID)) + log.Warn("changefeed stat not found when removing dispatcher", + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name())) return } cfStat := v.(*changefeedStat) - remaining := cfStat.dispatcherCount.Add(-1) - log.Info("remove dispatcher from changefeed stat", - zap.Stringer("changefeedID", changefeedID), - zap.Int32("remaining", remaining)) - if remaining == 0 { + r := cfStat.dispatcherCount.Add(-1) + remaining = &r + if r == 0 { if _, ok := c.changefeedMap.LoadAndDelete(changefeedID.ID()); ok { - stat := v.(*changefeedStat) - stat.removeMetrics() - log.Info("last dispatcher removed, clean up changefeed stat", zap.Stringer("changefeedID", target.GetChangefeedID())) + cfStat.removeMetrics() } } } diff --git a/downstreamadapter/sink/cloudstorage/sink.go b/downstreamadapter/sink/cloudstorage/sink.go index 3d09d03cdc..7edccc7f28 100644 --- a/downstreamadapter/sink/cloudstorage/sink.go +++ b/downstreamadapter/sink/cloudstorage/sink.go @@ -210,7 +210,7 @@ func (s *sink) AddDMLEvent(event *commonEvent.DMLEvent) { log.Warn("ignore dml event because sink is not normal", zap.String("keyspace", s.changefeedID.Keyspace()), zap.String("changefeed", s.changefeedID.Name()), - zap.String("dispatcherID", event.GetDispatcherID().String())) + zap.String("dispatcher", event.GetDispatcherID().String())) return } s.dmlWriters.addDMLEvent(event) @@ -237,7 +237,7 @@ func (s *sink) WriteBlockEvent(event commonEvent.BlockEvent) error { err = s.writeDDLEvent(e) default: log.Error("cloudstorage sink doesn't support this type of block event", - zap.String("namespace", s.changefeedID.Keyspace()), + zap.String("keyspace", s.changefeedID.Keyspace()), zap.String("changefeed", s.changefeedID.Name()), zap.String("eventType", commonEvent.TypeToString(event.GetType()))) return errors.ErrInvalidEventType.GenWithStackByArgs(commonEvent.TypeToString(event.GetType())) diff --git a/downstreamadapter/sink/cloudstorage/writer.go b/downstreamadapter/sink/cloudstorage/writer.go index 71f98c7e0e..77adc6b74b 100644 --- a/downstreamadapter/sink/cloudstorage/writer.go +++ b/downstreamadapter/sink/cloudstorage/writer.go @@ -255,15 +255,19 @@ func (d *writer) writeFile(ctx context.Context, filePath string, data []byte) er if _, err = writer.Write(ctx, data); err != nil { if closeErr := writer.Close(ctx); closeErr != nil { log.Warn("failed to close writer after write failure", - zap.String("keyspace", keyspace), zap.String("changefeed", changefeed), - zap.String("path", filePath), zap.Error(closeErr)) + zap.String("keyspace", keyspace), + zap.String("changefeed", changefeed), + zap.String("path", filePath), + zap.Error(closeErr)) } return err } if err = writer.Close(ctx); err != nil { log.Error("failed to close concurrency writer", - zap.String("keyspace", keyspace), zap.String("changefeed", changefeed), - zap.String("path", filePath), zap.Error(err)) + zap.String("keyspace", keyspace), + zap.String("changefeed", changefeed), + zap.String("path", filePath), + zap.Error(err)) return err } return nil diff --git a/downstreamadapter/sink/kafka/sink.go b/downstreamadapter/sink/kafka/sink.go index 61eec8e928..8e194cf537 100644 --- a/downstreamadapter/sink/kafka/sink.go +++ b/downstreamadapter/sink/kafka/sink.go @@ -269,7 +269,7 @@ func (s *sink) WriteBlockEvent(event commonEvent.BlockEvent) error { err = s.sendDDLEvent(v) default: log.Error("unsupported kafka sink block event type", - zap.String("namespace", s.changefeedID.Keyspace()), + zap.String("keyspace", s.changefeedID.Keyspace()), zap.String("changefeed", s.changefeedID.Name()), zap.String("eventType", commonEvent.TypeToString(event.GetType()))) return errors.ErrInvalidEventType.GenWithStackByArgs(commonEvent.TypeToString(event.GetType())) @@ -470,9 +470,12 @@ func (s *sink) sendDDLEvent(event *commonEvent.DDLEvent) error { } if message == nil { log.Info("kafka ddl event skipped", - zap.String("keyspace", s.changefeedID.Keyspace()), zap.String("changefeed", s.changefeedID.Name()), - zap.Uint64("startTs", e.GetStartTs()), zap.Uint64("commitTs", e.GetCommitTs()), - zap.String("query", e.Query)) + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), + zap.Int64("tableID", e.GetTableID()), + zap.Uint64("startTs", e.GetStartTs()), + zap.Uint64("commitTs", e.GetCommitTs()), + zap.String("ddlQuery", util.RedactValue(e.Query))) continue } codecCommon.SetDDLMessageLogInfo(message, e) @@ -501,9 +504,11 @@ func (s *sink) sendDDLEvent(event *commonEvent.DDLEvent) error { return err } log.Info("kafka ddl event sent", - zap.String("keyspace", s.changefeedID.Keyspace()), zap.String("changefeed", s.changefeedID.Name()), - zap.Uint64("startTs", e.GetStartTs()), zap.Uint64("commitTs", e.GetCommitTs()), - zap.String("query", e.GetDDLQuery())) + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), + zap.Int64("tableID", e.GetTableID()), + zap.Uint64("startTs", e.GetStartTs()), + zap.Uint64("commitTs", e.GetCommitTs())) } return nil } diff --git a/downstreamadapter/sink/pulsar/dml_producer.go b/downstreamadapter/sink/pulsar/dml_producer.go index d030cdc2ae..7ede43eaf9 100644 --- a/downstreamadapter/sink/pulsar/dml_producer.go +++ b/downstreamadapter/sink/pulsar/dml_producer.go @@ -77,7 +77,7 @@ func newDMLProducers( ) (*dmlProducers, error) { log.Info("Creating pulsar DML producer ...", zap.String("keyspace", changefeedID.Keyspace()), - zap.String("changefeed", changefeedID.ID().String())) + zap.String("changefeed", changefeedID.Name())) start := time.Now() defaultTopicName := comp.config.GetDefaultTopicName() @@ -112,7 +112,9 @@ func newDMLProducers( failpointCh: failpointCh, errChan: make(chan error, 1), } - log.Info("Pulsar DML producer created", zap.Stringer("changefeed", p.changefeedID), + log.Info("Pulsar DML producer created", + zap.String("keyspace", p.changefeedID.Keyspace()), + zap.String("changefeed", p.changefeedID.Name()), zap.Duration("duration", time.Since(start))) return p, nil } @@ -146,8 +148,9 @@ func (p *dmlProducers) asyncSendMessage( failpoint.Inject("PulsarSinkAsyncSendError", func() { // simulate sending message to input channel successfully but flushing // message to Pulsar meets error - log.Info("PulsarSinkAsyncSendError error injected", zap.String("keyspace", p.changefeedID.Keyspace()), - zap.String("changefeed", p.changefeedID.ID().String())) + log.Info("PulsarSinkAsyncSendError error injected", + zap.String("keyspace", p.changefeedID.Keyspace()), + zap.String("changefeed", p.changefeedID.Name())) p.failpointCh <- errors.New("pulsar sink injected error") failpoint.Return(nil) }) @@ -172,7 +175,7 @@ func (p *dmlProducers) asyncSendMessage( e := errors.WrapError(errors.ErrPulsarAsyncSendMessage, err) log.Error("Pulsar DML producer async send error", zap.String("keyspace", p.changefeedID.Keyspace()), - zap.String("changefeed", p.changefeedID.ID().String()), + zap.String("changefeed", p.changefeedID.Name()), zap.Int("messageSize", len(m.Payload)), zap.String("topic", topic), zap.Error(err)) @@ -185,7 +188,9 @@ func (p *dmlProducers) asyncSendMessage( case p.errChan <- e: default: log.Warn("Error channel is full in pulsar DML producer", - zap.Stringer("changefeed", p.changefeedID), zap.Error(e)) + zap.String("keyspace", p.changefeedID.Keyspace()), + zap.String("changefeed", p.changefeedID.Name()), + zap.Error(e)) } return } @@ -212,7 +217,7 @@ func (p *dmlProducers) close() { // We have to hold the lock to synchronize clos // which could lead to panic. log.Warn("Pulsar DML producer already closed", zap.String("keyspace", p.changefeedID.Keyspace()), - zap.String("changefeed", p.changefeedID.ID().String())) + zap.String("changefeed", p.changefeedID.Name())) return } close(p.failpointCh) @@ -223,9 +228,10 @@ func (p *dmlProducers) close() { // We have to hold the lock to synchronize clos p.producers.Remove(topic) // callback func will be called topicName, _ := topic.(string) log.Info("Async client closed in pulsar DML producer", - zap.Duration("duration", time.Since(start)), zap.String("keyspace", p.changefeedID.Keyspace()), - zap.String("changefeed", p.changefeedID.ID().String()), zap.String("topic", topicName)) + zap.String("changefeed", p.changefeedID.Name()), + zap.Duration("duration", time.Since(start)), + zap.String("topic", topicName)) } } diff --git a/downstreamadapter/sink/pulsar/sink.go b/downstreamadapter/sink/pulsar/sink.go index c5ac0a10c0..572193d38d 100644 --- a/downstreamadapter/sink/pulsar/sink.go +++ b/downstreamadapter/sink/pulsar/sink.go @@ -27,6 +27,7 @@ import ( "github.com/pingcap/ticdc/pkg/config" "github.com/pingcap/ticdc/pkg/errors" "github.com/pingcap/ticdc/pkg/sink/codec/common" + "github.com/pingcap/ticdc/pkg/util" "github.com/pingcap/ticdc/pkg/writelease" "github.com/pingcap/ticdc/utils/chann" "github.com/prometheus/client_golang/prometheus" @@ -218,7 +219,7 @@ func (s *sink) WriteBlockEvent(event commonEvent.BlockEvent) error { err = s.sendDDLEvent(v) default: log.Error("pulsar sink doesn't support this type of block event", - zap.String("namespace", s.changefeedID.Keyspace()), + zap.String("keyspace", s.changefeedID.Keyspace()), zap.String("changefeed", s.changefeedID.Name()), zap.String("eventType", commonEvent.TypeToString(event.GetType()))) return errors.ErrInvalidEventType.GenWithStackByArgs(commonEvent.TypeToString(event.GetType())) @@ -239,10 +240,12 @@ func (s *sink) sendDDLEvent(event *commonEvent.DDLEvent) error { } if message == nil { log.Info("Skip ddl event", - zap.Uint64("startTs", event.GetStartTs()), + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), + zap.Int64("tableID", e.GetTableID()), + zap.Uint64("startTs", e.GetStartTs()), zap.Uint64("commitTs", e.GetCommitTs()), - zap.String("query", e.Query), - zap.Stringer("changefeed", s.changefeedID)) + zap.String("ddlQuery", util.RedactValue(e.Query))) continue } common.SetDDLMessageLogInfo(message, e) @@ -272,8 +275,11 @@ func (s *sink) sendDDLEvent(event *commonEvent.DDLEvent) error { } } log.Info("pulsar sink send DDL event", - zap.String("keyspace", s.changefeedID.Keyspace()), zap.String("changefeed", s.changefeedID.Name()), - zap.Any("startTs", event.GetStartTs()), zap.Any("commitTs", event.GetCommitTs()), zap.Any("event", event.GetDDLQuery())) + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), + zap.Int64("tableID", event.GetTableID()), + zap.Uint64("startTs", event.GetStartTs()), + zap.Uint64("commitTs", event.GetCommitTs())) return nil } diff --git a/downstreamadapter/sink/redo/meta.go b/downstreamadapter/sink/redo/meta.go index aa8b14ddef..99b762f7ed 100644 --- a/downstreamadapter/sink/redo/meta.go +++ b/downstreamadapter/sink/redo/meta.go @@ -173,17 +173,17 @@ func (m *RedoMeta) Run(ctx context.Context) error { func (m *RedoMeta) UpdateMeta(checkpointTs, resolvedTs common.Ts) { if ok := m.metaResolvedTs.checkAndSetUnflushed(resolvedTs); !ok { log.Warn("update redo meta with a regressed resolved ts, ignore", - zap.Uint64("currResolvedTs", m.metaResolvedTs.getFlushed()), - zap.Uint64("recvResolvedTs", resolvedTs), zap.String("keyspace", m.changeFeedID.Keyspace()), - zap.String("changefeed", m.changeFeedID.Name())) + zap.String("changefeed", m.changeFeedID.Name()), + zap.Uint64("currResolvedTs", m.metaResolvedTs.getFlushed()), + zap.Uint64("recvResolvedTs", resolvedTs)) } if ok := m.metaCheckpointTs.checkAndSetUnflushed(checkpointTs); !ok { log.Warn("update redo meta with a regressed checkpoint ts, ignore", - zap.Uint64("currCheckpointTs", m.metaCheckpointTs.getFlushed()), - zap.Uint64("recvCheckpointTs", checkpointTs), zap.String("keyspace", m.changeFeedID.Keyspace()), - zap.String("changefeed", m.changeFeedID.Name())) + zap.String("changefeed", m.changeFeedID.Name()), + zap.Uint64("currCheckpointTs", m.metaCheckpointTs.getFlushed()), + zap.Uint64("recvCheckpointTs", checkpointTs)) } } @@ -212,7 +212,8 @@ func (m *RedoMeta) initMeta(ctx context.Context) error { log.Info("redo: meta manager walk dir", zap.String("keyspace", m.changeFeedID.Keyspace()), zap.String("changefeed", m.changeFeedID.Name()), - zap.String("path", path), zap.Int64("size", size)) + zap.String("path", path), + zap.Int64("size", size)) // TODO: use prefix to accelerate traverse operation if !strings.HasSuffix(path, redo.MetaEXT) { return nil @@ -224,7 +225,8 @@ func (m *RedoMeta) initMeta(ctx context.Context) error { log.Warn("redo: read meta file failed", zap.String("keyspace", m.changeFeedID.Keyspace()), zap.String("changefeed", m.changeFeedID.Name()), - zap.String("path", path), zap.Error(err)) + zap.String("path", path), + zap.Error(err)) if !util.IsNotExistInExtStorage(err) { return err } @@ -236,7 +238,8 @@ func (m *RedoMeta) initMeta(ctx context.Context) error { log.Error("redo: unmarshal meta data failed", zap.String("keyspace", m.changeFeedID.Keyspace()), zap.String("changefeed", m.changeFeedID.Name()), - zap.Error(err), zap.ByteString("data", data)) + zap.Error(err), + zap.ByteString("data", data)) return err } metas = append(metas, &meta) @@ -327,14 +330,16 @@ func (m *RedoMeta) shouldRemoved(path string, checkPointTs uint64) bool { log.Error("parse file name failed", zap.String("keyspace", m.changeFeedID.Keyspace()), zap.String("changefeed", m.changeFeedID.Name()), - zap.String("path", path), zap.Error(err)) + zap.String("path", path), + zap.Error(err)) return false } if fileType != redo.RedoDDLLogFileType && fileType != redo.RedoRowLogFileType { log.Panic("unknown file type", zap.String("keyspace", m.changeFeedID.Keyspace()), zap.String("changefeed", m.changeFeedID.Name()), - zap.String("path", path), zap.Any("fileType", fileType)) + zap.String("path", path), + zap.Any("fileType", fileType)) } // if commitTs == checkPointTs, the DDL may be executed in the owner, @@ -543,7 +548,8 @@ func (m *RedoMeta) bgGC(egCtx context.Context) error { if err != nil { log.Warn("redo meta log GC fail", zap.String("keyspace", m.changeFeedID.Keyspace()), - zap.String("changefeed", m.changeFeedID.Name()), zap.Error(err)) + zap.String("changefeed", m.changeFeedID.Name()), + zap.Error(err)) return errors.Trace(err) } } diff --git a/downstreamadapter/sink/redo/sink.go b/downstreamadapter/sink/redo/sink.go index c7d11cdcee..9e2512b716 100644 --- a/downstreamadapter/sink/redo/sink.go +++ b/downstreamadapter/sink/redo/sink.go @@ -149,9 +149,14 @@ func (s *Sink) WriteBlockEvent(event commonEvent.BlockEvent) error { s.metricCollector.observeDDLWrite(time.Since(start)) } log.Info("redo sink send DDL event", - zap.String("keyspace", s.changefeedID.Keyspace()), zap.String("changefeed", s.changefeedID.Name()), - zap.String("query", e.GetDDLQuery()), zap.Uint64("startTs", event.GetStartTs()), zap.Uint64("commitTs", event.GetCommitTs()), - zap.String("schema", e.GetSchemaName()), zap.String("table", e.GetTableName()), zap.Int64("tableID", e.GetTableID())) + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), + zap.Int64("tableID", e.GetTableID()), + zap.Uint64("startTs", event.GetStartTs()), + zap.Uint64("commitTs", event.GetCommitTs()), + zap.String("query", e.GetDDLQuery()), + zap.String("schema", e.GetSchemaName()), + zap.String("table", e.GetTableName())) } return nil } diff --git a/downstreamadapter/sink/topicmanager/kafka_topic_manager.go b/downstreamadapter/sink/topicmanager/kafka_topic_manager.go index 29d3d0d42c..056d60a074 100644 --- a/downstreamadapter/sink/topicmanager/kafka_topic_manager.go +++ b/downstreamadapter/sink/topicmanager/kafka_topic_manager.go @@ -139,8 +139,7 @@ func (m *kafkaTopicManager) tryUpdatePartitionsAndLogging(topic string, partitio if ok { if oldPartitions.(int32) != partitions { m.topics.Store(topic, partitions) - log.Info( - "kafka topic partition count changed", + log.Info("kafka topic partition count changed", zap.String("keyspace", m.changefeedID.Keyspace()), zap.String("changefeed", m.changefeedID.Name()), zap.String("topic", topic), @@ -167,8 +166,7 @@ func (m *kafkaTopicManager) fetchAllTopicsPartitionsNum(ctx context.Context) (ma start := time.Now() numPartitions, err := m.admin.GetTopicsPartitionsNum(ctx, topics) if err != nil { - log.Warn( - "kafka topic metadata refresh failed", + log.Warn("kafka topic metadata refresh failed", zap.String("keyspace", m.changefeedID.Keyspace()), zap.String("changefeed", m.changefeedID.Name()), zap.Duration("duration", time.Since(start)), @@ -247,8 +245,7 @@ func (m *kafkaTopicManager) createTopic(ctx context.Context, topicName string) ( ReplicationFactor: m.cfg.ReplicationFactor, }) if err != nil { - log.Error( - "kafka topic creation failed", + log.Error("kafka topic creation failed", zap.String("keyspace", m.changefeedID.Keyspace()), zap.String("changefeed", m.changefeedID.Name()), zap.String("topic", topicName), @@ -296,8 +293,7 @@ func (m *kafkaTopicManager) CreateTopicAndWaitUntilVisible( } m.tryUpdatePartitionsAndLogging(topicName, partitionNum) - log.Info( - "kafka topic created", + log.Info("kafka topic created", zap.String("keyspace", m.changefeedID.Keyspace()), zap.String("changefeed", m.changefeedID.Name()), zap.String("topic", topicName), diff --git a/logservice/coordinator/coordinator.go b/logservice/coordinator/coordinator.go index 1bffc26142..3a5a480d4e 100644 --- a/logservice/coordinator/coordinator.go +++ b/logservice/coordinator/coordinator.go @@ -209,7 +209,8 @@ func (c *logCoordinator) sendResolvedTsToCoordinator(id node.ID, changefeedID co if err := c.messageCenter.SendEvent(msg); err != nil { log.Warn("failed to send resolved ts to coordinator", zap.Stringer("target", id), - zap.String("changefeed", changefeedID.DisplayName.String()), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Uint64("resolvedTs", resolvedTs), zap.Error(err)) } @@ -330,7 +331,8 @@ func (c *logCoordinator) updateChangefeedStates(from node.ID, states *logservice delete(state.nodeReportPhyTs, from) affectedGIDs[gid] = struct{}{} log.Info("changefeed removed from node", - zap.Stringer("changefeedID", state.cfID), + zap.String("keyspace", state.cfID.Keyspace()), + zap.String("changefeed", state.cfID.Name()), zap.String("nodeID", string(from)), zap.Uint64("changefeedGIDLow", gid.Low), zap.Uint64("changefeedGIDHigh", gid.High)) @@ -340,7 +342,8 @@ func (c *logCoordinator) updateChangefeedStates(from node.ID, states *logservice changefeedResolvedTsLagGauge.DeleteLabelValues(state.cfID.Keyspace(), state.cfID.Name()) delete(c.changefeedStates.m, gid) log.Info("changefeed state removed as it has no active nodes", - zap.Stringer("changefeedID", state.cfID), + zap.String("keyspace", state.cfID.Keyspace()), + zap.String("changefeed", state.cfID.Name()), zap.Uint64("changefeedGIDLow", gid.Low), zap.Uint64("changefeedGIDHigh", gid.High)) } @@ -354,7 +357,8 @@ func (c *logCoordinator) updateChangefeedStates(from node.ID, states *logservice gid := cfID.ID() if _, ok := c.changefeedStates.m[gid]; !ok { log.Info("new changefeed states added", - zap.Stringer("changefeedID", cfID), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.Uint64("changefeedGIDLow", gid.Low), zap.Uint64("changefeedGIDHigh", gid.High)) // Initialize metrics for the new changefeed. @@ -414,7 +418,8 @@ func (c *logCoordinator) updateChangefeedMetrics(state *changefeedState) { if minResolvedTs == math.MaxUint64 { log.Warn("minResolvedTs is MaxUint64, this should not happen", - zap.Stringer("changefeedID", state.cfID)) + zap.String("keyspace", state.cfID.Keyspace()), + zap.String("changefeed", state.cfID.Name())) return } @@ -503,8 +508,10 @@ func (c *logCoordinator) getCandidateNodes(req requestAndTarget) []string { sort.Slice(candidateSubs, func(i, j int) bool { return candidateSubs[i].resolvedTs > candidateSubs[j].resolvedTs }) - var subIDs []uint64 - var candidateNodes []string + var ( + subIDs []uint64 + candidateNodes []string + ) if len(candidateSubs) > 0 { c.nodes.Lock() for _, candidate := range candidateSubs { @@ -519,10 +526,9 @@ func (c *logCoordinator) getCandidateNodes(req requestAndTarget) []string { c.nodes.Unlock() } log.Info("log coordinator get candidate nodes", - zap.String("requestNodeID", requestNodeID.String()), - zap.Stringer("dispatcherID", common.NewDispatcherIDFromPB(req.req.GetID())), - zap.Int64("tableID", span.TableID), zap.Uint64("startTs", startTs), + zap.String("requestNodeID", requestNodeID.String()), + zap.String("span", common.FormatTableSpan(span)), zap.Strings("candidateNodes", candidateNodes), zap.Uint64s("subscriptionIDs", subIDs)) diff --git a/logservice/eventstore/event_store.go b/logservice/eventstore/event_store.go index 79cbb508da..8cfaf8288b 100644 --- a/logservice/eventstore/event_store.go +++ b/logservice/eventstore/event_store.go @@ -502,33 +502,46 @@ func (e *eventStore) RegisterDispatcher( lag := time.Since(oracle.GetTimeFromTS(startTs)) eventStoreRegisterDispatcherStartTsLagHist.Observe(lag.Seconds()) - if lag >= 10*time.Second { - log.Warn("register dispatcher with large startTs lag", - zap.Stringer("dispatcherID", dispatcherID), - zap.Uint64("startTs", startTs), - zap.Duration("lag", lag)) - } else { - log.Info("register dispatcher", - zap.Stringer("dispatcherID", dispatcherID), - zap.Uint64("startTs", startTs)) - } + + // The subscription the dispatcher ends up on, decided below. + var ( + subscriptionID uint64 + checkpointTs uint64 + resolvedTs uint64 + tableSpan *heartbeatpb.TableSpan + ) start := time.Now() defer func() { - if success { - log.Info("register dispatcher success", - zap.Stringer("dispatcherID", dispatcherID), - zap.Uint64("startTs", startTs), - zap.Bool("enableDataSharing", enableDataSharing), - zap.Bool("onlyReuse", onlyReuse), - zap.Duration("duration", time.Since(start))) + fields := []zap.Field{ + zap.Stringer("dispatcherID", dispatcherID), + zap.Int64("tableID", dispatcherSpan.GetTableID()), + zap.Uint64("startTs", startTs), + zap.Duration("lag", lag), + } + if subscriptionID != 0 { + fields = append(fields, + zap.Uint64("subscriptionID", subscriptionID), + zap.String("subscriptionTableSpan", common.FormatTableSpan(tableSpan)), + zap.Uint64("subscriptionCheckpointTs", checkpointTs), + zap.Uint64("subscriptionResolvedTs", resolvedTs)) + } + fields = append(fields, + zap.Bool("onlyReuse", onlyReuse), + zap.Bool("enableDataSharing", enableDataSharing), + zap.Duration("duration", time.Since(start))) + + msg := "add dispatcher done" + if subscriptionID != 0 { + msg = "add dispatcher done by reuse" + } + if !success { + msg = "add dispatcher failed" + } + if success && lag >= 10*time.Second { + log.Warn(msg, fields...) } else { - log.Info("register dispatcher failed", - zap.Stringer("dispatcherID", dispatcherID), - zap.Uint64("startTs", startTs), - zap.Bool("enableDataSharing", enableDataSharing), - zap.Bool("onlyReuse", onlyReuse), - zap.Duration("duration", time.Since(start))) + log.Info(msg, fields...) } }() @@ -578,11 +591,10 @@ func (e *eventStore) RegisterDispatcher( e.dispatcherMeta.dispatcherStats[dispatcherID] = stat e.addSubscriberToSubStat(subStat, dispatcherID, &Subscriber{notifyFunc: wrappedNotifier}) e.dispatcherMeta.Unlock() - log.Info("reuse existing subscription with exact span match", - zap.Stringer("dispatcherID", dispatcherID), - zap.Uint64("startTs", startTs), - zap.Uint64("subscriptionID", uint64(subStat.subID)), - zap.Uint64("checkpointTs", subStat.checkpointTs.Load())) + subscriptionID = uint64(subStat.subID) + tableSpan = subStat.tableSpan + checkpointTs = subStat.checkpointTs.Load() + resolvedTs = subStat.resolvedTs.Load() return true } @@ -602,13 +614,10 @@ func (e *eventStore) RegisterDispatcher( stat.subStat = bestMatch e.dispatcherMeta.dispatcherStats[dispatcherID] = stat e.addSubscriberToSubStat(bestMatch, dispatcherID, &Subscriber{notifyFunc: wrappedNotifier}) - log.Info("reuse existing subscription with smallest containing span", - zap.Stringer("dispatcherID", dispatcherID), - zap.Uint64("startTs", startTs), - zap.Uint64("subscriptionID", uint64(bestMatch.subID)), - zap.Uint64("resolvedTs", bestMatch.resolvedTs.Load()), - zap.Uint64("checkpointTs", bestMatch.checkpointTs.Load()), - zap.Bool("exactMatch", bestMatch.tableSpan.Equal(dispatcherSpan))) + subscriptionID = uint64(bestMatch.subID) + tableSpan = bestMatch.tableSpan + checkpointTs = bestMatch.checkpointTs.Load() + resolvedTs = bestMatch.resolvedTs.Load() } e.dispatcherMeta.Unlock() @@ -747,7 +756,9 @@ func (e *eventStore) UnregisterDispatcher(changefeedID common.ChangeFeedID, disp delete(e.dispatcherMeta.dispatcherStats, dispatcherID) } e.dispatcherMeta.Unlock() - log.Info("unregister dispatcher done", zap.Stringer("changefeedID", changefeedID), + log.Info("remove dispatcher done", + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Stringer("dispatcherID", dispatcherID)) } @@ -1186,8 +1197,8 @@ func (e *eventStore) cleanObsoleteSubscriptionsOnce(deltaMs int64) { for _, sub := range obsoleteSubs { log.Info("clean obsolete subscription", zap.Uint64("subscriptionID", uint64(sub.subID)), - zap.Int("dbIndex", sub.dbIndex), zap.Int64("tableID", sub.span.TableID), + zap.Int("dbIndex", sub.dbIndex), zap.Time("idleAt", sub.idleAt)) e.subClient.Unsubscribe(sub.subID) db := e.dbs[sub.dbIndex] @@ -1235,6 +1246,7 @@ func diskSpaceUsage(m *pebble.Metrics) uint64 { type slowSubscriptionLogEntry struct { SubID uint64 `json:"subID"` + TableID int64 `json:"tableID"` ResolvedLagSeconds float64 `json:"resolvedLagSeconds"` ResolvedTs uint64 `json:"resolvedTs"` CheckpointTs uint64 `json:"checkpointTs"` @@ -1260,7 +1272,8 @@ func (e *slowSubscriptionLogEntry) LessThan(other *slowSubscriptionLogEntry) boo } type uninitializedSubscriptionLogEntry struct { - SubID uint64 `json:"subID"` + SubID uint64 `json:"subID"` + TableID int64 `json:"tableID"` } func (e *eventStore) collectAndReportStoreMetrics() { @@ -1316,8 +1329,9 @@ func (e *eventStore) collectAndReportStoreMetrics() { lastLogTime := subStat.lastLogLagTime.Load() if time.Since(time.Unix(0, lastLogTime)) > logInterval { log.Warn("resolved ts lag is too large for initialized subscription", - zap.Uint64("subID", uint64(subStat.subID)), + zap.Uint64("subscriptionID", uint64(subStat.subID)), zap.Int64("tableID", subStat.tableSpan.TableID), + zap.Uint64("checkpointTs", subStat.checkpointTs.Load()), zap.Uint64("resolvedTs", subResolvedTs), zap.Float64("resolvedLag(s)", subResolvedTsLagInSec), zap.Stringer("lastAdvanceTime", lastAdvanceTime), @@ -1344,7 +1358,8 @@ func (e *eventStore) collectAndReportStoreMetrics() { uninitializedStatCount++ if len(uninitializedSamples) < logEntryLimit { uninitializedSamples = append(uninitializedSamples, uninitializedSubscriptionLogEntry{ - SubID: uint64(subStat.subID), + SubID: uint64(subStat.subID), + TableID: subStat.tableSpan.TableID, }) } } @@ -1404,9 +1419,11 @@ func (e *eventStore) writeEvents( insertCount := 0 updateCount := 0 deleteCount := 0 - var totalValueBytesBefore int64 - var totalValueBytesAfter int64 - var dstBuf []byte + var ( + totalValueBytesBefore int64 + totalValueBytesAfter int64 + dstBuf []byte + ) if compressionBuf != nil { dstBuf = *compressionBuf } @@ -1428,10 +1445,10 @@ func (e *eventStore) writeEvents( } if kv.CRTs <= event.currentResolvedTs { log.Warn("event store received kv with commitTs less than resolvedTs", - zap.Uint64("commitTs", kv.CRTs), - zap.Uint64("resolvedTs", event.currentResolvedTs), zap.Uint64("subscriptionID", uint64(event.subID)), - zap.Int64("tableID", event.tableID)) + zap.Int64("tableID", event.tableID), + zap.Uint64("commitTs", kv.CRTs), + zap.Uint64("resolvedTs", event.currentResolvedTs)) continue } @@ -1635,8 +1652,10 @@ func (iter *eventStoreIter) NextWithScanPosition() (*common.RawKVEntry, ScanPosi _, compressionType := DecodeKeyAttributes(key) var decodedValue []byte if compressionType == CompressionZSTD { - var err error - var dst []byte + var ( + err error + dst []byte + ) if iter.decodeBuf != nil { dst = iter.decodeBuf[:0] } @@ -1665,10 +1684,10 @@ func (iter *eventStoreIter) NextWithScanPosition() (*common.RawKVEntry, ScanPosi break } log.Debug("event store iter skip kv not in table span", - zap.Stringer("dispatcherID", iter.dispatcherID), - zap.String("key", util.RedactKey(rawKV.Key)), + zap.String("tableSpan", common.FormatTableSpan(iter.tableSpan)), zap.Uint64("startTs", rawKV.StartTs), zap.Uint64("commitTs", rawKV.CRTs), + zap.String("key", util.RedactKey(rawKV.Key)), zap.Bool("isInsert", rawKV.IsInsert()), zap.Bool("isDelete", rawKV.IsDelete()), zap.Bool("isUpdate", rawKV.IsUpdate())) diff --git a/logservice/logpuller/region_admission_controller.go b/logservice/logpuller/region_admission_controller.go index d820c6cbbb..45cf5379c3 100644 --- a/logservice/logpuller/region_admission_controller.go +++ b/logservice/logpuller/region_admission_controller.go @@ -56,8 +56,8 @@ func (r *regionReq) finish() bool { return true } log.Info("region request duration abnormal, skip metric", - zap.Float64("cost", cost), - zap.Uint64("regionID", r.regionInfo.verID.GetID())) + zap.Uint64("regionID", r.regionInfo.verID.GetID()), + zap.Float64("cost", cost)) return true } diff --git a/logservice/logpuller/region_event_handler.go b/logservice/logpuller/region_event_handler.go index 7a8b8826aa..d8da9e094f 100644 --- a/logservice/logpuller/region_event_handler.go +++ b/logservice/logpuller/region_event_handler.go @@ -121,8 +121,8 @@ func (h *regionEventHandler) Handle(span *subscribedSpan, events ...regionEvent) if len(span.kvEventsCache) != 0 { log.Panic("kvEventsCache is not empty", - zap.Int("kvEventsCacheLen", len(span.kvEventsCache)), - zap.Uint64("subscriptionID", uint64(span.subID))) + zap.Uint64("subscriptionID", uint64(span.subID)), + zap.Int("kvEventsCacheLen", len(span.kvEventsCache))) } newResolvedTs := uint64(0) @@ -243,8 +243,8 @@ func (h *regionEventHandler) OnDrop(event regionEvent) interface{} { // TODO: Distinguish between drop events caused by "path not found" errors and memory control. if len(event.states) == 0 || event.states[0] == nil { log.Error("drop invalid region event", - zap.Bool("hasEntries", event.entries != nil), zap.Uint64("resolvedTs", event.resolvedTs), + zap.Bool("hasEntries", event.entries != nil), zap.Int("states", len(event.states)), zap.Uint64("memoryBytes", event.memoryBytes)) return nil @@ -318,7 +318,9 @@ func handleEventEntries(span *subscribedSpan, state *regionFeedState, entries *c log.Debug("region is initialized", zap.Int64("tableID", span.span.TableID), zap.Uint64("regionID", regionID), - zap.Uint64("requestID", state.requestID)) + zap.Uint64("requestID", state.requestID), + zap.String("startKey", util.RedactKey(span.span.StartKey)), + zap.String("endKey", util.RedactKey(span.span.EndKey))) for _, cachedEvent := range state.matcher.matchCachedRow(true) { span.kvEventsCache = append(span.kvEventsCache, assembleRowEvent(regionID, cachedEvent)) } @@ -329,10 +331,10 @@ func handleEventEntries(span *subscribedSpan, state *regionFeedState, entries *c log.Panic("commit ts must be greater than resolved ts", zap.Int64("tableID", span.span.TableID), zap.Uint64("regionID", regionID), - zap.Uint64("requestID", state.requestID), - zap.String("eventType", "COMMITTED"), - zap.Uint64("commitTs", entry.CommitTs), zap.Uint64("resolvedTs", resolvedTs), + zap.Uint64("requestID", state.requestID), + zap.String("EventType", "COMMITTED"), + zap.Uint64("CommitTs", entry.CommitTs), zap.String("key", util.RedactKey(entry.GetKey()))) } span.kvEventsCache = append(span.kvEventsCache, assembleRowEvent(regionID, entry)) @@ -348,9 +350,9 @@ func handleEventEntries(span *subscribedSpan, state *regionFeedState, entries *c log.Fatal("prewrite not match", zap.Int64("tableID", span.span.TableID), zap.Uint64("regionID", state.getRegionID()), - zap.Uint64("requestID", state.requestID), zap.Uint64("startTs", entry.GetStartTs()), zap.Uint64("commitTs", entry.GetCommitTs()), + zap.Uint64("requestID", state.requestID), zap.String("key", util.RedactKey(entry.GetKey()))) } @@ -366,10 +368,10 @@ func handleEventEntries(span *subscribedSpan, state *regionFeedState, entries *c log.Panic("commit ts must be greater than resolved ts", zap.Int64("tableID", span.span.TableID), zap.Uint64("regionID", regionID), - zap.Uint64("requestID", state.requestID), - zap.String("eventType", "COMMIT"), - zap.Uint64("commitTs", entry.CommitTs), zap.Uint64("resolvedTs", resolvedTs), + zap.Uint64("requestID", state.requestID), + zap.String("EventType", "COMMIT"), + zap.Uint64("CommitTs", entry.CommitTs), zap.String("key", util.RedactKey(entry.GetKey()))) } span.kvEventsCache = append(span.kvEventsCache, assembleRowEvent(regionID, entry)) diff --git a/logservice/logpuller/region_request_scheduler.go b/logservice/logpuller/region_request_scheduler.go index 2ed223e824..d5df6917ca 100644 --- a/logservice/logpuller/region_request_scheduler.go +++ b/logservice/logpuller/region_request_scheduler.go @@ -85,8 +85,8 @@ func (s *regionRequestScheduler) Submit(region regionInfo) { log.Debug("cdc region scan task enqueued", zap.Uint64("subscriptionID", uint64(region.subscribedSpan.subID)), zap.Int64("tableID", region.subscribedSpan.span.TableID), - zap.Uint64("startTs", region.subscribedSpan.startTs), zap.Uint64("regionID", region.verID.GetID()), + zap.Uint64("startTs", region.subscribedSpan.startTs), zap.Uint64("regionEpochVersion", region.verID.GetVer()), zap.Uint64("regionEpochConfVer", region.verID.GetConfVer()), zap.String("priority", normalizeScanPriority(region.scanPriority).String()), diff --git a/logservice/logpuller/region_request_worker.go b/logservice/logpuller/region_request_worker.go index 54698f0e4d..052e2be4bd 100644 --- a/logservice/logpuller/region_request_worker.go +++ b/logservice/logpuller/region_request_worker.go @@ -323,9 +323,9 @@ func (s *regionRequestWorker) dispatchRegionChangeEvents(events []*cdcpb.Event) case *cdcpb.Event_Entries_: if eventData == nil { log.Warn("region request worker receives a region event with nil entries, ignore it", - zap.Uint64("workerID", s.workerID), zap.Uint64("subscriptionID", uint64(subscriptionID)), - zap.Uint64("regionID", regionID)) + zap.Uint64("regionID", regionID), + zap.Uint64("workerID", s.workerID)) continue } regionEvent.entries = eventData @@ -334,9 +334,9 @@ func (s *regionRequestWorker) dispatchRegionChangeEvents(events []*cdcpb.Event) continue case *cdcpb.Event_Error: log.Debug("region request worker receives a region error", - zap.Uint64("workerID", s.workerID), zap.Uint64("subscriptionID", uint64(subscriptionID)), zap.Uint64("regionID", event.RegionId), + zap.Uint64("workerID", s.workerID), zap.Any("error", eventData.Error)) state.markStopped(&eventError{err: eventData.Error}) case *cdcpb.Event_ResolvedTs: @@ -352,9 +352,9 @@ func (s *regionRequestWorker) dispatchRegionChangeEvents(events []*cdcpb.Event) case *cdcpb.Event_Error: // It is normal to receive a region error after deregistering a subscription. log.Debug("region request worker receives an error for a stale region, ignore it", - zap.Uint64("workerID", s.workerID), zap.Uint64("subscriptionID", uint64(subscriptionID)), - zap.Uint64("regionID", event.RegionId)) + zap.Uint64("regionID", event.RegionId), + zap.Uint64("workerID", s.workerID)) default: untrackedCount++ if len(sampleRegionIDs) < logRegionIDSampleSize { @@ -380,7 +380,6 @@ func (s *regionRequestWorker) dispatchResolvedTsEvent(resolvedTsEvent *cdcpb.Res // TODO: resolvedTsEvent.Ts be 0 is impossible, we need find the root cause. if resolvedTsEvent.Ts == 0 { log.Warn("region request worker receives a resolved ts event with zero value, ignore it", - zap.Uint64("workerID", s.workerID), zap.Uint64("subscriptionID", resolvedTsEvent.RequestId), zap.Int("regionCount", len(resolvedTsEvent.Regions)), zap.Uint64s("sampleRegionIDs", @@ -478,9 +477,9 @@ func (s *regionRequestWorker) sendRegionRequest(conn *ConnAndClient, req *region region := req.regionInfo subID := region.subscribedSpan.subID log.Debug("region request worker sends region request", - zap.Uint64("workerID", s.workerID), zap.Uint64("subscriptionID", uint64(subID)), zap.Uint64("regionID", region.verID.GetID()), + zap.Uint64("workerID", s.workerID), zap.String("addr", s.storeAddr), zap.Bool("bdrMode", region.filterLoop)) @@ -502,9 +501,9 @@ func (s *regionRequestWorker) sendRegionRequest(conn *ConnAndClient, req *region state.abortScanIfNeeded() state.matcher.clear() log.Warn("duplicate active region request ignored", - zap.Uint64("workerID", s.workerID), zap.Uint64("subscriptionID", uint64(subID)), - zap.Uint64("regionID", region.verID.GetID())) + zap.Uint64("regionID", region.verID.GetID()), + zap.Uint64("workerID", s.workerID)) return nil } if err := s.sendChangeDataRequest(conn, createRegionRequest(s.upstream.clusterID, region)); err != nil { diff --git a/logservice/logpuller/regionlock/region_range_lock.go b/logservice/logpuller/regionlock/region_range_lock.go index 045a57a2b0..bce8ed5411 100644 --- a/logservice/logpuller/regionlock/region_range_lock.go +++ b/logservice/logpuller/regionlock/region_range_lock.go @@ -104,7 +104,7 @@ func rangeLockEntryLess(a, b *rangeLockEntry) bool { } func (e *rangeLockEntry) String() string { - return fmt.Sprintf("region %v [%v, %v), version %v, %d waiters", + return fmt.Sprintf("region %v %s, version %v, %d waiters", e.regionID, util.RedactKey(e.startKey), util.RedactKey(e.endKey), @@ -194,16 +194,14 @@ func (l *RangeLock) UnlockRange( if !ok { log.Panic("unlocking a not locked range", zap.Uint64("regionID", regionID), - zap.String("startKey", util.RedactKey(startKey)), - zap.String("endKey", util.RedactKey(endKey)), + zap.String("range", util.FormatKeyRange(startKey, endKey)), zap.Uint64("version", version)) } if entry.regionID != regionID { log.Panic("unlocked a range but regionID mismatch", zap.Uint64("expectedRegionID", regionID), zap.Uint64("foundRegionID", entry.regionID), - zap.String("startKey", util.RedactKey(startKey)), - zap.String("endKey", util.RedactKey(endKey))) + zap.String("range", util.FormatKeyRange(startKey, endKey))) } if entry != l.regionIDToLockedRanges[regionID] { log.Panic("range lock and region id lock mismatch when trying to unlock", @@ -217,8 +215,7 @@ func (l *RangeLock) UnlockRange( if entry.regionVersion != version || !bytes.Equal(entry.endKey, endKey) { log.Panic("unlocking region doesn't match the locked region", zap.Uint64("regionID", regionID), - zap.String("startKey", util.RedactKey(startKey)), - zap.String("endKey", util.RedactKey(endKey)), + zap.String("range", util.FormatKeyRange(startKey, endKey)), zap.Uint64("version", version), zap.String("foundLockEntry", entry.String())) } @@ -245,10 +242,9 @@ func (l *RangeLock) UnlockRange( l.unlockedRanges.set(startKey, endKey, newResolvedTs) log.Debug("unlocked range", - zap.Uint64("lockID", l.id), zap.Uint64("regionID", entry.regionID), - zap.Uint64("resolvedTs", newResolvedTs), - zap.String("startKey", util.RedactKey(startKey)), - zap.String("endKey", util.RedactKey(endKey))) + zap.Uint64("regionID", entry.regionID), zap.Uint64("resolvedTs", newResolvedTs), + zap.Uint64("lockID", l.id), + zap.String("range", util.FormatKeyRange(startKey, endKey))) return } @@ -522,10 +518,10 @@ func (l *RangeLock) tryLockRange(startKey, endKey []byte, regionID, regionVersio currentRangeStartKey := startKey log.Info("try lock range staled", - zap.Uint64("lockID", l.id), zap.Uint64("regionID", regionID), - zap.String("startKey", util.RedactKey(startKey)), - zap.String("endKey", util.RedactKey(endKey)), - zap.Strings("allOverlapping", overlapStr)) + zap.Uint64("regionID", regionID), zap.Uint64("lockID", l.id), + zap.String("range", util.FormatKeyRange(startKey, endKey)), + zap.Int("overlappingCount", len(overlapStr)), + zap.Strings("allOverlapping", overlapStr)) // DEBUG for _, r := range overlappedRangeLocks { // Ignore the totally-disjointed range which may be added to the list because of @@ -560,10 +556,10 @@ func (l *RangeLock) tryLockRange(startKey, endKey []byte, regionID, regionVersio } log.Info("lock range blocked", - zap.Uint64("lockID", l.id), zap.Uint64("regionID", regionID), - zap.String("startKey", util.RedactKey(startKey)), - zap.String("endKey", util.RedactKey(endKey)), - zap.Strings("blockedBy", overlapStr)) + zap.Uint64("regionID", regionID), zap.Uint64("lockID", l.id), + zap.String("range", util.FormatKeyRange(startKey, endKey)), + zap.Int("blockedByCount", len(overlapStr)), + zap.Strings("blockedBy", overlapStr)) // DEBUG return LockRangeResult{ Status: LockRangeStatusWait, diff --git a/logservice/logpuller/subscription_client.go b/logservice/logpuller/subscription_client.go index 5f30da5bae..5294dfe2aa 100644 --- a/logservice/logpuller/subscription_client.go +++ b/logservice/logpuller/subscription_client.go @@ -266,7 +266,8 @@ func (s *subscriptionClient) Subscribe( priority: rt.baseScanPriority, }: log.Info("subscribes span done", zap.Uint64("subscriptionID", uint64(subID)), - zap.Int64("tableID", span.TableID), zap.Uint64("startTs", startTs)) + zap.Int64("tableID", span.TableID), zap.Uint64("startTs", startTs), + zap.String("startKey", util.RedactKey(span.StartKey)), zap.String("endKey", util.RedactKey(span.EndKey))) } } @@ -383,8 +384,7 @@ func (s *subscriptionClient) divideSpanAndScheduleRegionRequests( } log.Debug("subscription client is going to load regions", zap.Uint64("subscriptionID", uint64(subscribedSpan.subID)), - zap.String("startKey", util.RedactKey(nextSpan.StartKey)), - zap.String("endKey", util.RedactKey(nextSpan.EndKey))) + zap.String("tableSpan", common.FormatTableSpan(&nextSpan))) backoff := tikv.NewBackoffer(ctx, tikvRequestMaxBackoff) regions, err := s.upstream.regionCache.BatchLoadRegionsWithKeyRange( @@ -392,8 +392,7 @@ func (s *subscriptionClient) divideSpanAndScheduleRegionRequests( if err != nil { log.Warn("subscription client load regions failed", zap.Uint64("subscriptionID", uint64(subscribedSpan.subID)), - zap.String("startKey", util.RedactKey(nextSpan.StartKey)), - zap.String("endKey", util.RedactKey(nextSpan.EndKey)), + zap.String("tableSpan", common.FormatTableSpan(&nextSpan)), zap.Error(err)) backoffBeforeLoad = true continue @@ -408,8 +407,7 @@ func (s *subscriptionClient) divideSpanAndScheduleRegionRequests( if len(regionMetas) == 0 { log.Warn("subscription client load regions with holes", zap.Uint64("subscriptionID", uint64(subscribedSpan.subID)), - zap.String("startKey", util.RedactKey(nextSpan.StartKey)), - zap.String("endKey", util.RedactKey(nextSpan.EndKey))) + zap.String("tableSpan", common.FormatTableSpan(&nextSpan))) backoffBeforeLoad = true continue } diff --git a/logservice/logpuller/txn_matcher.go b/logservice/logpuller/txn_matcher.go index 70bb4d4f7c..b7aa3a04eb 100644 --- a/logservice/logpuller/txn_matcher.go +++ b/logservice/logpuller/txn_matcher.go @@ -127,8 +127,8 @@ func (m *matcher) matchCachedRow(initialized bool) []*cdcpb.Event_Row { // prewrite log before initialized, a committed log with // the same key and start-ts must have been received. log.Info("ignore commit event without prewrite", - zap.String("key", util.RedactKey(cacheEntry.GetKey())), - zap.Uint64("startTs", cacheEntry.GetStartTs())) + zap.Uint64("startTs", cacheEntry.GetStartTs()), + zap.String("key", util.RedactKey(cacheEntry.GetKey()))) continue } cachedCommit[top] = cacheEntry diff --git a/logservice/schemastore/disk_format.go b/logservice/schemastore/disk_format.go index f5e0d37517..c30e5fe1f2 100644 --- a/logservice/schemastore/disk_format.go +++ b/logservice/schemastore/disk_format.go @@ -31,6 +31,7 @@ import ( "github.com/pingcap/ticdc/pkg/errors" "github.com/pingcap/ticdc/pkg/filter" "github.com/pingcap/ticdc/pkg/ordering" + "github.com/pingcap/ticdc/pkg/util" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta/model" "go.uber.org/zap" @@ -463,7 +464,7 @@ func loadAndApplyDDLHistory( // 2. for other ddls to be ignored, they are already filtered before write to disk. handler, ok := allDDLHandlers[model.ActionType(ddlEvent.Type)] if !ok { - log.Panic("unknown ddl type", zap.Any("ddlType", ddlEvent.Type), zap.String("query", ddlEvent.Query)) + log.Panic("unknown ddl type", zap.Any("ddlType", ddlEvent.Type), zap.String("query", util.RedactValue(ddlEvent.Query))) } tableTriggerDDLHistory = handler.updateDDLHistoryFunc(updateDDLHistoryFuncArgs{ ddlEvent: &ddlEvent, @@ -1089,7 +1090,7 @@ func loadAllPhysicalTablesAtTs( ddlEvent := unmarshalPersistedDDLEvent(ddlValue) handler, ok := allDDLHandlers[model.ActionType(ddlEvent.Type)] if !ok { - log.Panic("unknown ddl type", zap.Any("ddlType", ddlEvent.Type), zap.String("query", ddlEvent.Query)) + log.Panic("unknown ddl type", zap.Any("ddlType", ddlEvent.Type), zap.String("query", util.RedactValue(ddlEvent.Query))) } tableTriggerDDLHistory = handler.updateDDLHistoryFunc(updateDDLHistoryFuncArgs{ ddlEvent: &ddlEvent, @@ -1114,8 +1115,8 @@ func loadAllPhysicalTablesAtTs( for tableID, tableInfo := range tableMap { if _, ok := databaseMap[tableInfo.SchemaID]; !ok { log.Panic("database not found", - zap.Int64("schemaID", tableInfo.SchemaID), zap.Int64("tableID", tableID), + zap.Int64("schemaID", tableInfo.SchemaID), zap.String("tableName", tableInfo.Name), zap.Any("databaseMapLen", len(databaseMap))) } diff --git a/logservice/schemastore/multi_version.go b/logservice/schemastore/multi_version.go index 2b65114f3e..77d8f3838d 100644 --- a/logservice/schemastore/multi_version.go +++ b/logservice/schemastore/multi_version.go @@ -21,6 +21,7 @@ import ( "github.com/pingcap/log" "github.com/pingcap/ticdc/pkg/common" + "github.com/pingcap/ticdc/pkg/util" "github.com/pingcap/tidb/pkg/meta/model" "go.uber.org/zap" ) @@ -79,7 +80,7 @@ func (v *versionedTableInfoStore) setTableInfoInitialized() { for _, job := range v.pendingDDLs { // log.Info("apply pending ddl", // zap.Int64("tableID", int64(v.tableID)), - // zap.String("query", job.Query), + // zap.String("query", util.RedactValue(job.Query)), // zap.Uint64("finishedTS", job.BinlogInfo.FinishedTS), // zap.Any("infosLen", len(v.infos))) v.doApplyDDL(&job) @@ -110,8 +111,8 @@ func (v *versionedTableInfoStore) getTableInfo(ts uint64) (*common.TableInfo, er if ts >= v.deleteVersion { log.Warn("table info deleted", - zap.Any("ts", ts), zap.Any("tableID", v.tableID), + zap.Any("ts", ts), zap.Any("deleteVersion", v.deleteVersion), zap.Any("infos", v.infos)) return nil, &TableDeletedError{} @@ -122,8 +123,8 @@ func (v *versionedTableInfoStore) getTableInfo(ts uint64) (*common.TableInfo, er }) if target == 0 { log.Error("no version found", - zap.Any("ts", ts), zap.Any("tableID", v.tableID), + zap.Any("ts", ts), zap.Any("deleteVersion", v.deleteVersion), zap.Any("infos", v.infos)) return nil, errors.New("no version found") @@ -194,7 +195,7 @@ func (v *versionedTableInfoStore) doApplyDDL(event *PersistedDDLEvent) { if len(v.infos) != 0 && event.FinishedTs <= v.infos[len(v.infos)-1].Version { log.Warn("already applied ddl, ignore it.", zap.Int64("tableID", v.tableID), - zap.String("query", event.Query), + zap.String("query", util.RedactValue(event.Query)), zap.Uint64("finishedTS", event.FinishedTs), zap.Int("infosLen", len(v.infos))) return @@ -202,7 +203,7 @@ func (v *versionedTableInfoStore) doApplyDDL(event *PersistedDDLEvent) { ddlType := model.ActionType(event.Type) handler, ok := allDDLHandlers[ddlType] if !ok { - log.Panic("unknown ddl type", zap.Any("ddlType", ddlType), zap.String("query", event.Query)) + log.Panic("unknown ddl type", zap.Any("ddlType", ddlType), zap.String("query", util.RedactValue(event.Query))) } tableInfo, deleted := handler.extractTableInfoFunc(event, v.tableID) if tableInfo != nil { diff --git a/logservice/schemastore/persist_storage.go b/logservice/schemastore/persist_storage.go index 62a37167ed..a8977c36a3 100644 --- a/logservice/schemastore/persist_storage.go +++ b/logservice/schemastore/persist_storage.go @@ -36,6 +36,7 @@ import ( "github.com/pingcap/ticdc/pkg/filter" "github.com/pingcap/ticdc/pkg/ordering" "github.com/pingcap/ticdc/pkg/txnutil/gc" + "github.com/pingcap/ticdc/pkg/util" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser" @@ -491,7 +492,7 @@ func (p *persistentStorage) fetchTableDDLEvents(dispatcherID common.DispatcherID zap.Int64("tableID", tableID), zap.Uint64("ts", ts), zap.String("type", model.ActionType(rawEvent.Type).String()), - zap.String("query", rawEvent.Query)) + zap.String("query", util.RedactValue(rawEvent.Query))) } } log.Debug("fetchTableDDLEvents", @@ -637,8 +638,8 @@ func (p *persistentStorage) doGc(ctx context.Context, gcTs uint64) { // It might happen when all changefeed is removed in the maintainer side, // the gc safe point thus advanced. log.Warn("gc safe point is larger than resolvedTs, ignore it", - zap.Uint64("gcTs", gcTs), - zap.Uint64("resolvedTs", p.upperBound.ResolvedTs)) + zap.Uint64("resolvedTs", p.upperBound.ResolvedTs), + zap.Uint64("gcTs", gcTs)) } if gcTs <= p.gcTs { p.mu.Unlock() @@ -801,7 +802,7 @@ func (p *persistentStorage) handleDDLJob(job *model.Job) error { handler, ok := allDDLHandlers[job.Type] if !ok { - log.Warn("unknown ddl type, ignore it", zap.Any("ddlType", job.Type), zap.String("query", job.Query)) + log.Warn("unknown ddl type, ignore it", zap.Any("ddlType", job.Type), zap.String("query", util.RedactValue(job.Query))) p.mu.Unlock() return nil } @@ -917,11 +918,11 @@ func shouldSkipDDL(job *model.Job, tableMap map[int64]*BasicTableInfo) bool { // Note: partition table's logical table id is also in tableMap if _, ok := tableMap[job.BinlogInfo.TableInfo.ID]; ok { log.Debug("table already exists. ignore DDL", + zap.Int64("tableID", job.TableID), zap.Int64("schemaID", job.SchemaID), zap.String("schemaName", job.SchemaName), - zap.Int64("tableID", job.TableID), zap.String("tableName", job.TableName), - zap.String("DDL", job.Query), + zap.String("DDL", util.RedactValue(job.Query)), zap.Int64("schemaVersion", job.BinlogInfo.SchemaVersion), zap.Uint64("finishedTs", job.BinlogInfo.FinishedTS)) return true @@ -930,11 +931,11 @@ func shouldSkipDDL(job *model.Job, tableMap map[int64]*BasicTableInfo) bool { // For duplicate create tables ddl job, the tables in the job should be same, check the first table is enough if _, ok := tableMap[job.BinlogInfo.MultipleTableInfos[0].ID]; ok { log.Debug("table already exists. ignore DDL", + zap.Int64("tableID", job.TableID), zap.Int64("schemaID", job.SchemaID), zap.String("schemaName", job.SchemaName), - zap.Int64("tableID", job.TableID), zap.String("tableName", job.TableName), - zap.String("DDL", job.Query), + zap.String("DDL", util.RedactValue(job.Query)), zap.Int64("schemaVersion", job.BinlogInfo.SchemaVersion), zap.Uint64("finishedTs", job.BinlogInfo.FinishedTS)) return true @@ -968,7 +969,7 @@ func shouldSkipDDL(job *model.Job, tableMap map[int64]*BasicTableInfo) bool { model.ActionAlterResourceGroup, model.ActionDropResourceGroup: log.Info("ignore ddl", - zap.String("DDL", job.Query), + zap.String("DDL", util.RedactValue(job.Query)), zap.Int64("jobID", job.ID), zap.Uint64("finishedTs", job.BinlogInfo.FinishedTS), zap.Any("type", job.Type)) @@ -980,7 +981,7 @@ func shouldSkipDDL(job *model.Job, tableMap map[int64]*BasicTableInfo) bool { func getDDLHandler(rawEvent *PersistedDDLEvent) *persistStorageDDLHandler { handler, ok := allDDLHandlers[model.ActionType(rawEvent.Type)] if !ok { - log.Panic("unknown ddl type", zap.Any("ddlType", rawEvent.Type), zap.String("query", rawEvent.Query)) + log.Panic("unknown ddl type", zap.Any("ddlType", rawEvent.Type), zap.String("query", util.RedactValue(rawEvent.Query))) } return handler } diff --git a/logservice/schemastore/persist_storage_ddl_handlers.go b/logservice/schemastore/persist_storage_ddl_handlers.go index b35f5df795..b4ffab918d 100644 --- a/logservice/schemastore/persist_storage_ddl_handlers.go +++ b/logservice/schemastore/persist_storage_ddl_handlers.go @@ -84,7 +84,7 @@ type iterateEventTablesFuncArgs struct { func (args *updateSchemaMetadataFuncArgs) addTableToDB(tableID int64, schemaID int64) { databaseInfo, ok := args.databaseMap[schemaID] if !ok { - log.Panic("database not found.", zap.Int64("schemaID", schemaID), zap.Int64("tableID", tableID)) + log.Panic("database not found.", zap.Int64("tableID", tableID), zap.Int64("schemaID", schemaID)) } databaseInfo.Tables[tableID] = true } @@ -92,7 +92,7 @@ func (args *updateSchemaMetadataFuncArgs) addTableToDB(tableID int64, schemaID i func (args *updateSchemaMetadataFuncArgs) removeTableFromDB(tableID int64, schemaID int64) { databaseInfo, ok := args.databaseMap[schemaID] if !ok { - log.Panic("database not found.", zap.Int64("schemaID", schemaID), zap.Int64("tableID", tableID)) + log.Panic("database not found.", zap.Int64("tableID", tableID), zap.Int64("schemaID", schemaID)) } delete(databaseInfo.Tables, tableID) } @@ -2071,9 +2071,9 @@ func extractTableInfoFuncForSingleTableDDL(event *PersistedDDLEvent, tableID int } } log.Panic("should not reach here", + zap.Int64("tableID", tableID), zap.Any("type", event.Type), - zap.String("query", event.Query), - zap.Int64("tableID", tableID)) + zap.String("query", event.Query)) return nil, false } @@ -2130,9 +2130,9 @@ func extractTableInfoFuncForDropTable(event *PersistedDDLEvent, tableID int64) ( } } log.Panic("should not reach here", + zap.Int64("tableID", tableID), zap.Bool("isPartitionTable", isPartitionTable(event.TableInfo)), - zap.Int64("eventTableID", event.TableID), - zap.Int64("tableID", tableID)) + zap.Int64("eventTableID", event.TableID)) return nil, false } @@ -2908,10 +2908,10 @@ func buildDDLEventForRenameTable(rawEvent *PersistedDDLEvent, tableFilter filter } else { // if the table is both filtered out before and after rename table, the ddl should not be fetched log.Panic("should not build a ignored rename table ddl", + zap.Int64("tableID", rawEvent.TableID), zap.String("DDL", rawEvent.Query), zap.Int64("jobID", rawEvent.ID), - zap.Int64("schemaID", rawEvent.SchemaID), - zap.Int64("tableID", rawEvent.TableID)) + zap.Int64("schemaID", rawEvent.SchemaID)) } } else { if !ignorePrevTable { @@ -2966,10 +2966,10 @@ func buildDDLEventForRenameTable(rawEvent *PersistedDDLEvent, tableFilter filter } else { // if the table is both filtered out before and after rename table, the ddl should not be fetched log.Panic("should not build a ignored rename table ddl", + zap.Int64("tableID", rawEvent.TableID), zap.String("DDL", rawEvent.Query), zap.Int64("jobID", rawEvent.ID), - zap.Int64("schemaID", rawEvent.SchemaID), - zap.Int64("tableID", rawEvent.TableID)) + zap.Int64("schemaID", rawEvent.SchemaID)) } } // For rename table, we only set NotSync to true when the previous table is filtered. diff --git a/logservice/schemastore/schema_store.go b/logservice/schemastore/schema_store.go index f4022d6de0..1cb3a3fffb 100644 --- a/logservice/schemastore/schema_store.go +++ b/logservice/schemastore/schema_store.go @@ -33,6 +33,7 @@ import ( "github.com/pingcap/ticdc/pkg/ordering" "github.com/pingcap/ticdc/pkg/pdutil" "github.com/pingcap/ticdc/pkg/txnutil/gc" + "github.com/pingcap/ticdc/pkg/util" "github.com/tikv/client-go/v2/oracle" pd "github.com/tikv/pd/client" "go.uber.org/zap" @@ -172,39 +173,23 @@ func (s *keyspaceSchemaStore) tryUpdateResolvedTs() { resolvedEvents := s.unsortedCache.fetchSortedDDLEventBeforeTS(pendingTs) for idx, event := range resolvedEvents { if event.Job.BinlogInfo.SchemaVersion == 0 /* means the ddl is ignored in upstream */ { - log.Info("skip ddl job with empty SchemaVersion", - zap.Any("type", event.Job.Type), - zap.String("job", event.Job.Query), - zap.Int64("jobSchemaVersion", event.Job.BinlogInfo.SchemaVersion), - zap.Uint64("jobFinishTs", event.Job.BinlogInfo.FinishedTS), - zap.Uint64("jobCommitTs", event.CommitTs), - zap.Any("storeSchemaVersion", s.schemaVersion), - zap.Uint64("storeFinishedDDLTS", s.finishedDDLTs)) + log.Info("ddl job ignored since schema version is empty", + zap.Int64("tableID", event.Job.TableID), + zap.Uint64("commitTs", event.CommitTs), + zap.String("ddlQuery", util.RedactValue(event.Job.Query))) continue } if event.Job.BinlogInfo.FinishedTS <= s.finishedDDLTs { - log.Info("skip already applied ddl job", - zap.Any("type", event.Job.Type), - zap.String("job", event.Job.Query), - zap.Int64("jobSchemaVersion", event.Job.BinlogInfo.SchemaVersion), - zap.Uint64("jobFinishTs", event.Job.BinlogInfo.FinishedTS), - zap.Uint64("jobCommitTs", event.CommitTs), - zap.Any("storeSchemaVersion", s.schemaVersion), - zap.Uint64("storeFinishedDDLTS", s.finishedDDLTs)) + log.Info("ddl job ignored since it is already applied", + zap.Int64("tableID", event.Job.TableID), + zap.Uint64("commitTs", event.CommitTs), + zap.Int64("schemaVersion", event.Job.BinlogInfo.SchemaVersion), + zap.Int64("storeSchemaVersion", s.schemaVersion), + zap.Uint64("storeFinishedDDLTS", s.finishedDDLTs), + zap.String("ddlQuery", util.RedactValue(event.Job.Query))) continue } - log.Info("handle a ddl job", - zap.Int64("schemaID", event.Job.SchemaID), - zap.String("schemaName", event.Job.SchemaName), - zap.Int64("tableID", event.Job.TableID), - zap.String("tableName", event.Job.TableName), - zap.Any("type", event.Job.Type), - zap.String("DDL", event.Job.Query), - zap.Int64("schemaVersion", event.Job.BinlogInfo.SchemaVersion), - zap.Uint64("jobFinishTs", event.Job.BinlogInfo.FinishedTS), - zap.Any("storeSchemaVersion", s.schemaVersion), - zap.Uint64("storeFinishedDDLTS", s.finishedDDLTs)) - + handleStart := time.Now() err := s.dataStorage.handleDDLJob(event.Job) if err != nil { // Keep failed and later events for retry. They are removed from cache when fetched. @@ -221,17 +206,14 @@ func (s *keyspaceSchemaStore) tryUpdateResolvedTs() { if lastHandledEventIdx >= 0 && resolvedEvents[lastHandledEventIdx].CommitTs > pendingTs { pendingTs = resolvedEvents[lastHandledEventIdx].CommitTs } - log.Error("handle ddl job failed, retry later", - zap.Int64("schemaID", event.Job.SchemaID), - zap.String("schemaName", event.Job.SchemaName), + log.Error("ddl job failed, retry later", zap.Int64("tableID", event.Job.TableID), - zap.String("tableName", event.Job.TableName), - zap.Any("type", event.Job.Type), - zap.String("DDL", event.Job.Query), - zap.Int64("jobSchemaVersion", event.Job.BinlogInfo.SchemaVersion), - zap.Uint64("jobFinishTs", event.Job.BinlogInfo.FinishedTS), - zap.Uint64("jobCommitTs", event.CommitTs), - zap.Any("storeSchemaVersion", s.schemaVersion), + zap.Uint64("startTs", event.Job.StartTS), + zap.Uint64("commitTs", event.CommitTs), + zap.Int64("schemaVersion", event.Job.BinlogInfo.SchemaVersion), + zap.String("ddlQuery", util.RedactValue(event.Job.Query)), + zap.Duration("duration", time.Since(handleStart)), + zap.Int64("storeSchemaVersion", s.schemaVersion), zap.Uint64("storeFinishedDDLTS", s.finishedDDLTs), zap.Error(err)) break @@ -240,6 +222,13 @@ func (s *keyspaceSchemaStore) tryUpdateResolvedTs() { // Update dedup watermark only after DDL is persisted successfully. s.schemaVersion = event.Job.BinlogInfo.SchemaVersion s.finishedDDLTs = event.Job.BinlogInfo.FinishedTS + log.Info("ddl job applied", + zap.Int64("tableID", event.Job.TableID), + zap.Uint64("startTs", event.Job.StartTS), + zap.Uint64("commitTs", event.CommitTs), + zap.Int64("schemaVersion", event.Job.BinlogInfo.SchemaVersion), + zap.String("ddlQuery", util.RedactValue(event.Job.Query)), + zap.Duration("duration", time.Since(handleStart))) } // When register a new table, it will load all ddl jobs from disk for the table, @@ -256,17 +245,17 @@ func (s *keyspaceSchemaStore) tryUpdateResolvedTs() { // TODO tenfyzhong 2025-09-13 13:40:26 use a chan to decoupling func (s *keyspaceSchemaStore) writeDDLEvent(ddlEvent DDLJobWithCommitTs) { log.Debug("write ddl event", - zap.Int64("schemaID", ddlEvent.Job.SchemaID), zap.Int64("tableID", ddlEvent.Job.TableID), + zap.Int64("schemaID", ddlEvent.Job.SchemaID), zap.Uint64("finishedTs", ddlEvent.Job.BinlogInfo.FinishedTS), - zap.String("query", ddlEvent.Job.Query)) + zap.String("ddlQuery", util.RedactValue(ddlEvent.Job.Query))) serverConfig := config.GetGlobalServerConfig() for _, ts := range serverConfig.Debug.SchemaStore.IgnoreDDLCommitTs { if ts == ddlEvent.CommitTs { - log.Info("ignore ddl job by commit ts", + log.Info("ddl job ignored by commit ts", zap.Uint64("commitTs", ts), - zap.String("query", ddlEvent.Job.Query)) + zap.String("ddlQuery", util.RedactValue(ddlEvent.Job.Query))) return } } diff --git a/logservice/schemastore/validator.go b/logservice/schemastore/validator.go index 4c46bb9646..7b79b82caa 100644 --- a/logservice/schemastore/validator.go +++ b/logservice/schemastore/validator.go @@ -226,6 +226,6 @@ dbLoop: if verifier.firstErr != nil { return nil, nil, nil, nil, verifier.firstErr } - log.Info("table replication eligibility verified", zap.Int("tableCount", len(verifier.tableInfos)), zap.Uint64("startTs", startTs)) + log.Info("table replication eligibility verified", zap.Uint64("startTs", startTs), zap.Int("tableCount", len(verifier.tableInfos))) return verifier.tableInfos, verifier.ineligibleTables, verifier.eligibleTables, verifier.allTables, nil } diff --git a/maintainer/barrier.go b/maintainer/barrier.go index ff2f211900..edb4987fdb 100644 --- a/maintainer/barrier.go +++ b/maintainer/barrier.go @@ -108,29 +108,32 @@ func (b *Barrier) HandleStatus(from node.ID, task := b.spanController.GetTaskByID(dispatcherID) if task == nil { log.Info("Get block status from unexisted dispatcher, ignore it", + zap.String("keyspace", request.ChangefeedID.GetKeyspace()), zap.String("changefeed", request.ChangefeedID.GetName()), - zap.String("dispatcherID", dispatcherID.String()), zap.Uint64("commitTs", status.State.BlockTs), + zap.String("dispatcher", dispatcherID.String()), zap.Int64("mode", b.mode)) continue } ownerNodeID := task.GetNodeID() if ownerNodeID != from { log.Warn("ignore block status from non-owner dispatcher", + zap.String("keyspace", request.ChangefeedID.GetKeyspace()), zap.String("changefeed", request.ChangefeedID.GetName()), zap.String("dispatcherID", dispatcherID.String()), + zap.Uint64("commitTs", status.State.BlockTs), zap.String("ownerNodeID", ownerNodeID.String()), zap.String("fromNodeID", from.String()), - zap.Uint64("commitTs", status.State.BlockTs), zap.Int64("mode", b.mode)) continue } if dispatcherID != b.spanController.GetDDLDispatcherID() { if !b.spanController.IsReplicating(task) { log.Info("Get block status from unreplicating dispatcher, ignore it", + zap.String("keyspace", request.ChangefeedID.GetKeyspace()), zap.String("changefeed", request.ChangefeedID.GetName()), - zap.String("dispatcherID", dispatcherID.String()), zap.Uint64("commitTs", status.State.BlockTs), + zap.String("dispatcher", dispatcherID.String()), zap.Int64("mode", b.mode)) // A newly added dispatcher may report its first WAITING barrier before the add // operator moves it from scheduling to replicating. We still cannot admit that @@ -164,10 +167,11 @@ func (b *Barrier) HandleStatus(from node.ID, if event == nil { // should not happen log.Error("handle block status failed, event is nil", - zap.String("from", from.String()), + zap.String("keyspace", request.ChangefeedID.GetKeyspace()), zap.String("changefeed", request.ChangefeedID.GetName()), - zap.String("detail", status.String()), zap.Uint64("commitTs", status.State.BlockTs), + zap.String("from", from.String()), + zap.String("detail", status.String()), zap.Int64("mode", b.mode)) continue } @@ -180,8 +184,9 @@ func (b *Barrier) HandleStatus(from node.ID, } if invalidStatusCount > 0 { log.Warn("ignore invalid block statuses", - zap.String("from", from.String()), + zap.String("keyspace", request.ChangefeedID.GetKeyspace()), zap.String("changefeed", request.ChangefeedID.GetName()), + zap.String("from", from.String()), zap.Int("invalidStatusCount", invalidStatusCount), zap.Int64("mode", b.mode)) } @@ -197,8 +202,9 @@ func (b *Barrier) HandleStatus(from node.ID, dispatcherStatus = append(dispatcherStatus, actions[from]...) if len(dispatcherStatus) <= 0 { log.Warn("no dispatcher status to send", + zap.String("keyspace", request.ChangefeedID.Keyspace), + zap.String("changefeed", request.ChangefeedID.Name), zap.String("from", from.String()), - zap.String("changefeed", request.ChangefeedID.String()), zap.Int64("mode", b.mode)) } @@ -408,8 +414,9 @@ func (b *Barrier) handleEventDone(changefeedID common.ChangeFeedID, dispatcherID event, ok := b.blockedEvents.Get(key) if !ok { log.Debug("No block event found, ignore the event done message", + zap.String("keyspace", changefeedID.Keyspace()), zap.String("changefeed", changefeedID.Name()), - zap.String("dispatcherID", dispatcherID.String()), + zap.String("dispatcher", dispatcherID.String()), zap.Uint64("commitTs", status.State.BlockTs), zap.Any("state", status.State), zap.Bool("isSyncPoint", status.State.IsSyncPoint), @@ -476,17 +483,19 @@ func (b *Barrier) handleBlockState(changefeedID common.ChangeFeedID, event.routeAdmissions = routeTableAdmissionsFromPB(blockState.RouteTableAdmissions) } log.Info("the block event is sent by ddl dispatcher", + zap.String("keyspace", changefeedID.Keyspace()), zap.String("changefeed", changefeedID.Name()), - zap.String("dispatcherID", dispatcherID.String()), zap.Uint64("commitTs", blockState.BlockTs), + zap.String("dispatcher", dispatcherID.String()), zap.Int64("mode", b.mode)) event.tableTriggerDispatcherRelated = true } if event.selected.Load() { // the event already in the selected state, ignore the block event just sent ack log.Debug("the block event already selected, ignore the block event", + zap.String("keyspace", changefeedID.Keyspace()), zap.String("changefeed", changefeedID.Name()), - zap.String("dispatcherID", dispatcherID.String()), + zap.String("dispatcher", dispatcherID.String()), zap.Uint64("commitTs", blockState.BlockTs), zap.Int64("mode", b.mode), ) @@ -511,9 +520,10 @@ func (b *Barrier) handleBlockState(changefeedID common.ChangeFeedID, (blockState.BlockTables.InfluenceType != heartbeatpb.InfluenceType_Normal) { if pending := b.pendingEvents.Len(); pending > 0 { log.Debug("discard db/all block event from ddl dispatcher due to pending schedule events, wait next resend", + zap.String("keyspace", changefeedID.Keyspace()), zap.String("changefeed", changefeedID.Name()), - zap.String("dispatcherID", dispatcherID.String()), zap.Uint64("commitTs", blockState.BlockTs), + zap.String("dispatcher", dispatcherID.String()), zap.Bool("isSyncPoint", blockState.IsSyncPoint), zap.Int("pendingScheduleEvents", pending), zap.Int64("mode", b.mode)) @@ -624,6 +634,7 @@ func (b *Barrier) checkEventFinish(be *BarrierEvent) { } if be.selected.Load() { log.Info("all dispatchers reported event done, remove event", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), zap.Uint64("commitTs", be.commitTs), zap.Int64("mode", b.mode)) @@ -637,8 +648,9 @@ func (b *Barrier) tryScheduleEvent(event *BarrierEvent) bool { return true } log.Info("event trySchedule", + zap.String("keyspace", event.cfID.Keyspace()), zap.String("changefeed", event.cfID.Name()), - zap.String("dispatcherID", event.writerDispatcher.String()), + zap.String("writerDispatcher", event.writerDispatcher.String()), zap.Uint64("EventCommitTs", event.commitTs), zap.Int64("mode", b.mode)) // pending queue ensures ddl with the same eventKey only schedules once and in order @@ -646,15 +658,17 @@ func (b *Barrier) tryScheduleEvent(event *BarrierEvent) bool { if !ready { if candidate == nil { log.Info("no candidate here, skip", + zap.String("keyspace", event.cfID.Keyspace()), zap.String("changefeed", event.cfID.Name()), - zap.String("dispatcherID", event.writerDispatcher.String()), + zap.String("writerDispatcher", event.writerDispatcher.String()), zap.Uint64("EventCommitTs", event.commitTs), zap.Bool("isSyncPoint", event.isSyncPoint), zap.Int64("mode", b.mode)) } else { log.Info("event waits for a smaller commitTs before scheduling", + zap.String("keyspace", event.cfID.Keyspace()), zap.String("changefeed", event.cfID.Name()), - zap.String("dispatcherID", event.writerDispatcher.String()), + zap.String("writerDispatcher", event.writerDispatcher.String()), zap.Uint64("EventCommitTs", event.commitTs), zap.Bool("isSyncPoint", event.isSyncPoint), zap.Uint64("blockingEventCommitTs", candidate.commitTs), diff --git a/maintainer/barrier_event.go b/maintainer/barrier_event.go index b11048b5b6..2fe2933b2c 100644 --- a/maintainer/barrier_event.go +++ b/maintainer/barrier_event.go @@ -128,6 +128,7 @@ func NewBlockEvent(cfID common.ChangeFeedID, } log.Info("new block event is created", + zap.String("keyspace", cfID.Keyspace()), zap.String("changefeedID", cfID.Name()), zap.String("dispatcherID", dispatcherID.String()), zap.Uint64("blockTs", event.commitTs), @@ -226,7 +227,7 @@ func (be *BarrierEvent) createRangeCheckerForTypeAll() { } else { be.rangeChecker = range_checker.NewTableCountChecker(tbls) } - log.Info("create range checker for block event", zap.Any("influcenceType", be.blockedDispatchers.InfluenceType), zap.Any("commitTs", be.commitTs), zap.Int64("mode", be.mode)) + log.Info("create range checker for block event", zap.Any("commitTs", be.commitTs), zap.Any("influcenceType", be.blockedDispatchers.InfluenceType), zap.Int64("mode", be.mode)) } func (be *BarrierEvent) createRangeCheckerForTypeDB() { @@ -242,7 +243,7 @@ func (be *BarrierEvent) createRangeCheckerForTypeDB() { } else { be.rangeChecker = range_checker.NewTableCountChecker(tbls) } - log.Info("create range checker for block event", zap.Any("influcenceType", be.blockedDispatchers.InfluenceType), zap.Any("commitTs", be.commitTs), zap.Int64("mode", be.mode)) + log.Info("create range checker for block event", zap.Any("commitTs", be.commitTs), zap.Any("influcenceType", be.blockedDispatchers.InfluenceType), zap.Int64("mode", be.mode)) } func (be *BarrierEvent) checkEventAction(dispatcherID common.DispatcherID) (*heartbeatpb.DispatcherStatus, node.ID) { @@ -261,9 +262,10 @@ func (be *BarrierEvent) onAllDispatcherReportedBlockEvent(dispatcherID common.Di case heartbeatpb.InfluenceType_DB, heartbeatpb.InfluenceType_All: // for all and db type, we always use the table trigger event dispatcher as the writer log.Info("use table trigger event as the writer dispatcher", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), - zap.String("dispatcherID", be.spanController.GetDDLDispatcherID().String()), zap.Uint64("commitTs", be.commitTs), + zap.String("dispatcher", be.spanController.GetDDLDispatcherID().String()), zap.Int64("mode", be.mode)) dispatcher = be.spanController.GetDDLDispatcherID() default: @@ -273,9 +275,10 @@ func (be *BarrierEvent) onAllDispatcherReportedBlockEvent(dispatcherID common.Di // or the table trigger event dispatcher if it's one of the blocked dispatcher selected = be.spanController.GetDDLDispatcherID().ToPB() log.Info("use table trigger event as the writer dispatcher", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), - zap.String("dispatcherID", selected.String()), zap.Uint64("commitTs", be.commitTs), + zap.String("dispatcher", selected.String()), zap.Int64("mode", be.mode)) } dispatcher = common.NewDispatcherIDFromPB(selected) @@ -292,9 +295,10 @@ func (be *BarrierEvent) onAllDispatcherReportedBlockEvent(dispatcherID common.Di be.lastResendTime = time.Now() be.passActionSent = false log.Info("all dispatcher reported heartbeat, schedule it, and select one to write", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), - zap.String("dispatcherID", be.writerDispatcher.String()), zap.Uint64("commitTs", be.commitTs), + zap.String("dispatcher", be.writerDispatcher.String()), zap.String("barrierType", be.blockedDispatchers.InfluenceType.String()), zap.Int64("mode", be.mode)) stm := be.spanController.GetTaskByID(be.writerDispatcher) @@ -315,6 +319,7 @@ func (be *BarrierEvent) scheduleBlockEvent() { case heartbeatpb.InfluenceType_DB: be.operatorController.RemoveTasksBySchemaID(be.dropDispatchers.SchemaID) log.Info("remove table", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), zap.Uint64("commitTs", be.commitTs), zap.Int64("schema", be.dropDispatchers.SchemaID), @@ -322,6 +327,7 @@ func (be *BarrierEvent) scheduleBlockEvent() { case heartbeatpb.InfluenceType_Normal: be.operatorController.RemoveTasksByTableIDs(be.dropDispatchers.TableIDs...) log.Info("remove table", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), zap.Uint64("commitTs", be.commitTs), zap.Int64s("table", be.dropDispatchers.TableIDs), @@ -329,7 +335,8 @@ func (be *BarrierEvent) scheduleBlockEvent() { case heartbeatpb.InfluenceType_All: log.Panic("invalid influence type meet drop dispatchers", zap.Any("blockedDispatchers", be.blockedDispatchers), - zap.Any("changefeed", be.cfID.Name()), + zap.String("keyspace", be.cfID.Keyspace()), + zap.String("changefeed", be.cfID.Name()), zap.Any("commitTs", be.commitTs), zap.Int64("mode", be.mode), ) @@ -337,8 +344,9 @@ func (be *BarrierEvent) scheduleBlockEvent() { } for _, add := range be.newTables { log.Info("add new table", - zap.Uint64("commitTs", be.commitTs), + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), + zap.Uint64("commitTs", be.commitTs), zap.Int64("schema", add.SchemaID), zap.Int64("table", add.TableID), zap.Int64("mode", be.mode)) @@ -351,6 +359,7 @@ func (be *BarrierEvent) scheduleBlockEvent() { for _, change := range be.schemaIDChange { log.Info("update schemaID for table", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), zap.Uint64("commitTs", be.commitTs), zap.Int64("newSchema", change.OldSchemaID), @@ -374,8 +383,9 @@ func (be *BarrierEvent) addDispatchersToRangeChecker() { replicaSpan := be.spanController.GetTaskByID(dispatcher) if replicaSpan == nil { log.Info("dispatcher not found, ignore", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), - zap.String("dispatcherID", dispatcher.String()), + zap.String("dispatcher", dispatcher.String()), zap.Int64("mode", be.mode)) continue } @@ -392,8 +402,9 @@ func (be *BarrierEvent) markDispatcherEventDone(dispatcherID common.DispatcherID replicaSpan := be.spanController.GetTaskByID(dispatcherID) if replicaSpan == nil { log.Warn("dispatcher not found, ignore", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), - zap.String("dispatcherID", dispatcherID.String()), + zap.String("dispatcher", dispatcherID.String()), zap.Int64("mode", be.mode)) return } @@ -449,8 +460,9 @@ func (be *BarrierEvent) allDispatcherReported() bool { task := be.spanController.GetTaskByID(dispatcherID) if task == nil { log.Info("unexisted dispatcher, remove it from barrier event", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), - zap.String("dispatcherID", dispatcherID.String()), + zap.String("dispatcher", dispatcherID.String()), zap.Uint64("commitTs", be.commitTs), zap.Int64("mode", be.mode), ) @@ -461,8 +473,9 @@ func (be *BarrierEvent) allDispatcherReported() bool { } } else if !be.spanController.IsDDLDispatcher(dispatcherID) && !be.spanController.IsReplicating(task) { // TODO:fix ddlReplicating status log.Info("unreplicating dispatcher, remove it from barrier event", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), - zap.String("dispatcherID", dispatcherID.String()), + zap.String("dispatcher", dispatcherID.String()), zap.Uint64("commitTs", be.commitTs), zap.Int64("mode", be.mode), ) @@ -587,6 +600,7 @@ func (be *BarrierEvent) checkBlockedDispatchers() { be.selected.Store(true) be.writerDispatcherAdvanced = true log.Info("one related dispatcher has forward checkpointTs, means the block event can be advanced", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), zap.Uint64("commitTs", be.commitTs), zap.Int64("tableId", tableId), @@ -607,6 +621,7 @@ func (be *BarrierEvent) checkBlockedDispatchers() { be.selected.Store(true) be.writerDispatcherAdvanced = true log.Info("one related dispatcher has forward checkpointTs, means the block event can be advanced", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), zap.Uint64("commitTs", be.commitTs), zap.Int64("schemaID", schemaID), @@ -625,6 +640,7 @@ func (be *BarrierEvent) checkBlockedDispatchers() { be.selected.Store(true) be.writerDispatcherAdvanced = true log.Info("one related dispatcher has forward checkpointTs, means the block event can be advanced", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), zap.Uint64("commitTs", be.commitTs), zap.Uint64("checkpointTs", replication.GetStatus().CheckpointTs), @@ -674,6 +690,7 @@ func (be *BarrierEvent) resend(mode int64) []*messaging.TargetMessage { if time.Since(be.lastWarningLogTime) > time.Second*10 { if be.rangeChecker != nil { log.Warn("barrier event is not resolved", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), zap.Uint64("commitTs", be.commitTs), zap.Bool("isSyncPoint", be.isSyncPoint), @@ -686,6 +703,7 @@ func (be *BarrierEvent) resend(mode int64) []*messaging.TargetMessage { ) } else { log.Warn("barrier event is not resolved", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), zap.Uint64("commitTs", be.commitTs), zap.Bool("isSyncPoint", be.isSyncPoint), @@ -704,6 +722,7 @@ func (be *BarrierEvent) resend(mode int64) []*messaging.TargetMessage { if !be.selected.Load() { if time.Since(be.lastWarningLogTime) > time.Second*10 { log.Info("barrier event is not being selected", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), zap.Uint64("commitTs", be.commitTs), zap.Bool("isSyncPoint", be.isSyncPoint), @@ -722,9 +741,10 @@ func (be *BarrierEvent) resend(mode int64) []*messaging.TargetMessage { stm := be.spanController.GetTaskByID(be.writerDispatcher) if stm == nil || stm.GetNodeID() == "" { log.Warn("writer dispatcher not found", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), - zap.String("dispatcherID", be.writerDispatcher.String()), zap.Uint64("commitTs", be.commitTs), + zap.String("dispatcher", be.writerDispatcher.String()), zap.Bool("isSyncPoint", be.isSyncPoint), zap.Int64("mode", be.mode)) @@ -733,10 +753,11 @@ func (be *BarrierEvent) resend(mode int64) []*messaging.TargetMessage { // So the block event influence type is must normal, we just need to select one dispatcher in the block dispatchers if be.blockedDispatchers.InfluenceType != heartbeatpb.InfluenceType_Normal || len(be.blockedDispatchers.TableIDs) == 0 { log.Panic("influence type should be normal when writer dispatcher not found", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), - zap.Any("event", be), - zap.String("dispatcherID", be.writerDispatcher.String()), zap.Uint64("commitTs", be.commitTs), + zap.Any("event", be), + zap.String("dispatcher", be.writerDispatcher.String()), zap.Bool("isSyncPoint", be.isSyncPoint), zap.Int64("mode", be.mode)) } @@ -746,11 +767,12 @@ func (be *BarrierEvent) resend(mode int64) []*messaging.TargetMessage { if len(replications) == 0 { log.Panic("replications for this block event should not be empty", + zap.String("keyspace", be.cfID.Keyspace()), zap.String("changefeed", be.cfID.Name()), zap.Int64("tableID", tableID), - zap.Any("event", be), - zap.String("dispatcherID", be.writerDispatcher.String()), zap.Uint64("commitTs", be.commitTs), + zap.Any("event", be), + zap.String("dispatcher", be.writerDispatcher.String()), zap.Bool("isSyncPoint", be.isSyncPoint), zap.Int64("mode", be.mode)) } diff --git a/maintainer/block_status_dedupe.go b/maintainer/block_status_dedupe.go index 205422f72e..41c8b60f26 100644 --- a/maintainer/block_status_dedupe.go +++ b/maintainer/block_status_dedupe.go @@ -152,7 +152,8 @@ func (m *Maintainer) filterBlockStatusEvent(event *Event) (*Event, bool) { if suppressedCount > 0 { log.Debug("suppress duplicate maintainer block statuses", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Stringer("from", event.message.From), zap.Int64("mode", req.Mode), zap.Int("kept", len(filteredStatuses)), diff --git a/maintainer/maintainer.go b/maintainer/maintainer.go index dc81b7873e..dcde633456 100644 --- a/maintainer/maintainer.go +++ b/maintainer/maintainer.go @@ -286,7 +286,8 @@ func NewMaintainer(cfID common.ChangeFeedID, } log.Info("changefeed maintainer started", - zap.Stringer("changefeedID", cfID), + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.String("state", string(info.State)), zap.Uint64("checkpointTs", checkpointTs), zap.String("dispatcherID", tableTriggerEventDispatcherID.String()), @@ -327,7 +328,8 @@ func (m *Maintainer) HandleEvent(event *Event) bool { // add a log for debug an occasional slow bootstrap problem if event.eventType == EventMessage { log.Info("maintainer is too slow", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Int("eventType", event.eventType), zap.Duration("duration", duration), zap.String("from", event.message.From.String()), @@ -337,7 +339,8 @@ func (m *Maintainer) HandleEvent(event *Event) bool { ) } else { log.Info("maintainer is too slow", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Int("eventType", event.eventType), zap.Duration("duration", duration)) } @@ -347,7 +350,8 @@ func (m *Maintainer) HandleEvent(event *Event) bool { if m.scheduleState.Load() == int32(heartbeatpb.ComponentState_Stopped) { log.Warn("maintainer is stopped, stop handling event", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Uint64("checkpointTs", m.getWatermark().CheckpointTs), zap.Uint64("resolvedTs", m.getWatermark().ResolvedTs), ) @@ -454,7 +458,8 @@ func (m *Maintainer) SetDispatcherDrainTarget(target node.ID, epoch uint64) { func (m *Maintainer) initialize() error { start := time.Now() log.Info("start to initialize changefeed maintainer", - zap.Stringer("changefeedID", m.changefeedID)) + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name())) failpoint.Inject("NewChangefeedRetryError", func() { failpoint.Return(errors.New("failpoint injected retriable error")) @@ -470,15 +475,17 @@ func (m *Maintainer) initialize() error { // register all nodes to bootstrapper nodes := m.nodeManager.GetAliveNodes() log.Info("changefeed bootstrap initial nodes", + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Stringer("selfNodeID", m.selfNode.ID), - zap.Stringer("changefeedID", m.changefeedID), zap.Int("nodeCount", len(nodes))) _, _, requests, _ := m.bootstrapper.HandleNodesChange(nodes) m.sendMessages(requests) log.Info("changefeed maintainer initialized", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.String("status", common.FormatMaintainerStatus(m.GetMaintainerStatus())), zap.String("info", m.info.String()), zap.Duration("duration", time.Since(start))) @@ -554,7 +561,8 @@ func (m *Maintainer) onMessage(msg *messaging.TargetMessage) { req := msg.Message[0].(*heartbeatpb.RemoveMaintainerRequest) if !m.isMaintainerEpochRequestAllowed(req.MaintainerEpoch) { log.Warn("drop stale remove maintainer request", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Stringer("from", msg.From), zap.Uint64("requestMaintainerEpoch", req.MaintainerEpoch), zap.Uint64("currentMaintainerEpoch", m.currentMaintainerEpoch())) @@ -595,7 +603,8 @@ func (m *Maintainer) onRemoveMaintainer(cascade, changefeedRemoved bool) { // If we mark the maintainer as removing here, later bootstrap responses may be dropped, // leaving the maintainer permanently not bootstrapped and the coordinator stuck retrying. log.Info("ignore non-cascade remove request before bootstrap", - zap.Stringer("changefeedID", m.changefeedID)) + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name())) return } m.removing.Store(true) @@ -612,8 +621,11 @@ func (m *Maintainer) onRemoveMaintainer(cascade, changefeedRemoved bool) { if closed { m.markRemoved() m.scheduleState.Store(int32(heartbeatpb.ComponentState_Stopped)) - log.Info("changefeed maintainer closed", zap.Stringer("changefeedID", m.changefeedID), - zap.Uint64("checkpointTs", m.getWatermark().CheckpointTs), zap.Bool("removed", m.removed.Load())) + log.Info("changefeed maintainer closed", + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), + zap.Uint64("checkpointTs", m.getWatermark().CheckpointTs), + zap.Bool("removed", m.removed.Load())) } } @@ -649,7 +661,9 @@ func (m *Maintainer) onRedoPersisted(req *heartbeatpb.RedoResolvedTsProgressMess func (m *Maintainer) onNodeChanged() { addedNodes, removedNodes, requests, responses := m.bootstrapper.HandleNodesChange(m.nodeManager.GetAliveNodes()) - log.Info("maintainer node changed", zap.Stringer("changefeedID", m.changefeedID), + log.Info("maintainer node changed", + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Int("addedCount", len(addedNodes)), zap.Int("removedCount", len(removedNodes)), zap.Any("addedNodes", addedNodes), @@ -678,7 +692,8 @@ func (m *Maintainer) handleRedoMetaTsMessage(ctx context.Context) { case <-ticker.C: if !m.initialized.Load() { log.Warn("can not advance redoTs since not bootstrapped", - zap.Stringer("changefeedID", m.changefeedID)) + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name())) break } needUpdate := false @@ -738,7 +753,8 @@ func (m *Maintainer) calCheckpointTs(ctx context.Context) { if !m.initialized.Load() { log.Warn("can not advance checkpointTs since not bootstrapped", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Uint64("checkpointTs", m.getWatermark().CheckpointTs), zap.Uint64("resolvedTs", m.getWatermark().ResolvedTs)) continue @@ -804,9 +820,11 @@ func (m *Maintainer) calculateNewCheckpointTs() (*heartbeatpb.Watermark, bool) { if !ok { updateCheckpointTs = false log.Warn("checkpointTs can not be advanced, since missing capture heartbeat", - zap.Stringer("changefeedID", m.changefeedID), zap.Any("node", id), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Uint64("checkpointTs", m.getWatermark().CheckpointTs), - zap.Uint64("resolvedTs", m.getWatermark().ResolvedTs)) + zap.Uint64("resolvedTs", m.getWatermark().ResolvedTs), + zap.Any("node", id)) continue } // Apply heartbeat constraint - can only make checkpointTs smaller (safer) @@ -825,7 +843,8 @@ func (m *Maintainer) calculateNewCheckpointTs() (*heartbeatpb.Watermark, bool) { // Only all the heartbeat from dispatcherManager contains no dispatcher span (eg. all dispatchers are in absent state), will cause MaxUint64. if newWatermark.CheckpointTs == math.MaxUint64 { log.Debug("checkpointTs can not be advanced, since global checkpoint is invalid", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Uint64("resolvedTs", newWatermark.ResolvedTs), zap.Uint64("minCheckpointTsForScheduler", minCheckpointTsForScheduler), zap.Uint64("minCheckpointTsForBarrier", minCheckpointTsForBarrier)) @@ -833,7 +852,8 @@ func (m *Maintainer) calculateNewCheckpointTs() (*heartbeatpb.Watermark, bool) { } log.Debug("can advance checkpointTs", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Uint64("newCheckpointTs", newWatermark.CheckpointTs), zap.Uint64("newResolvedTs", newWatermark.ResolvedTs), zap.Uint64("minCheckpointTsForScheduler", minCheckpointTsForScheduler), @@ -862,7 +882,8 @@ func (m *Maintainer) calculateNewRedoCheckpointTs() (*heartbeatpb.Watermark, boo if !ok { updateCheckpointTs = false log.Warn("redo checkpointTs can not be advanced, since missing capture heartbeat", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Any("node", id)) continue } @@ -878,7 +899,8 @@ func (m *Maintainer) calculateNewRedoCheckpointTs() (*heartbeatpb.Watermark, boo if newWatermark.CheckpointTs == math.MaxUint64 { log.Debug("redo checkpointTs can not be advanced, since redo global checkpoint is invalid", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Uint64("resolvedTs", newWatermark.ResolvedTs), zap.Uint64("minCheckpointTsForScheduler", minRedoCheckpointTsForScheduler), zap.Uint64("minCheckpointTsForBarrier", minRedoCheckpointTsForBarrier)) @@ -886,7 +908,8 @@ func (m *Maintainer) calculateNewRedoCheckpointTs() (*heartbeatpb.Watermark, boo } log.Debug("can advance redo checkpointTs", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Uint64("newCheckpointTs", newWatermark.CheckpointTs), zap.Uint64("newResolvedTs", newWatermark.ResolvedTs), zap.Uint64("minCheckpointTsForScheduler", minRedoCheckpointTsForScheduler), @@ -931,8 +954,10 @@ func (m *Maintainer) sendMessages(msgs []*messaging.TargetMessage) { err := m.mc.SendCommand(msg) if err != nil { log.Debug("failed to send maintainer request", - zap.Stringer("changefeedID", m.changefeedID), - zap.Any("msg", msg), zap.Error(err)) + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), + zap.Any("msg", msg), + zap.Error(err)) } } } @@ -985,7 +1010,8 @@ func (m *Maintainer) onHeartbeatRequest(msg *messaging.TargetMessage) { } if req.Err != nil { log.Error("dispatcher report an error", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Stringer("sourceNode", msg.From), zap.String("error", req.Err.Message)) m.onError(msg.From, req.Err) @@ -1087,7 +1113,8 @@ func (m *Maintainer) onBlockStateRequest(msg *messaging.TargetMessage) { // onMaintainerBootstrapResponse is called when a maintainer bootstrap response(send by dispatcher manager) is received. func (m *Maintainer) onMaintainerBootstrapResponse(msg *messaging.TargetMessage) { log.Info("maintainer received bootstrap response", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Stringer("sourceNodeID", msg.From)) resp := msg.Message[0].(*heartbeatpb.MaintainerBootstrapResponse) @@ -1097,7 +1124,8 @@ func (m *Maintainer) onMaintainerBootstrapResponse(msg *messaging.TargetMessage) } if resp.Err != nil { log.Warn("maintainer bootstrap failed", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.String("error", resp.Err.Message)) m.onError(msg.From, resp.Err) return @@ -1115,7 +1143,8 @@ func (m *Maintainer) onMaintainerBootstrapResponse(msg *messaging.TargetMessage) func (m *Maintainer) onMaintainerPostBootstrapResponse(msg *messaging.TargetMessage) { log.Info("received maintainer post bootstrap response", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Any("server", msg.From)) resp := msg.Message[0].(*heartbeatpb.MaintainerPostBootstrapResponse) if !m.isMaintainerEpochResponseAllowed(resp.MaintainerEpoch) { @@ -1124,7 +1153,8 @@ func (m *Maintainer) onMaintainerPostBootstrapResponse(msg *messaging.TargetMess } if resp.Err != nil { log.Warn("maintainer post bootstrap failed", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.String("error", resp.Err.Message)) m.onError(msg.From, resp.Err) return @@ -1156,7 +1186,8 @@ func (m *Maintainer) isMaintainerEpochRequestAllowed(requestEpoch uint64) bool { // logDroppedMaintainerResponse records responses rejected by maintainer epoch fencing. func (m *Maintainer) logDroppedMaintainerResponse(responseType string, from node.ID, responseEpoch uint64) { log.Warn("drop stale maintainer response", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.String("responseType", responseType), zap.Stringer("from", from), zap.Uint64("responseMaintainerEpoch", responseEpoch), @@ -1211,7 +1242,9 @@ func (m *Maintainer) onBootstrapResponses(responses map[node.ID]*heartbeatpb.Mai } m.initialized.Store(true) - log.Info("changefeed maintainer bootstrapped", zap.Stringer("changefeedID", m.changefeedID)) + log.Info("changefeed maintainer bootstrapped", + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name())) // Memory Consumption is 64(tableName/schemaName limit) * 4(utf8.UTFMax) * 2(tableName+schemaName) * tableNum // For an extreme case(100w tables, and 64 utf8 characters for each name), the memory consumption is about 488MB. // For a normal case(100w tables, and 16 ascii characters for each name), the memory consumption is about 30MB. @@ -1240,7 +1273,8 @@ func (m *Maintainer) onMaintainerCloseResponse(from node.ID, response *heartbeat // Close responses only complete an active remove flow. A delayed compat // response from a superseded maintainer can share this changefeed ID. log.Warn("drop unexpected maintainer close response", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Stringer("from", from), zap.Uint64("responseMaintainerEpoch", response.MaintainerEpoch), zap.Uint64("currentMaintainerEpoch", m.currentMaintainerEpoch())) @@ -1310,7 +1344,8 @@ func (m *Maintainer) trySendMaintainerCloseRequestToAllNode() bool { if len(msgs) > 0 { m.sendMessages(msgs) log.Info("send maintainer close request to all dispatcher managers", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Uint64("checkpointTs", m.getWatermark().CheckpointTs), zap.Int("nodeCount", len(msgs))) } @@ -1321,7 +1356,9 @@ func (m *Maintainer) trySendMaintainerCloseRequestToAllNode() bool { // and coordinator remove this maintainer func (m *Maintainer) handleError(err error) { log.Error("an error occurred in maintainer", - zap.Stringer("changefeedID", m.changefeedID), zap.Error(err)) + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), + zap.Error(err)) var code string if rfcCode, ok := errors.RFCCode(err); ok { code = string(rfcCode) @@ -1352,7 +1389,8 @@ func (m *Maintainer) createBootstrapMessageFactory() bootstrap.NewBootstrapReque cfgBytes, err := json.Marshal(m.info.ToChangefeedConfig()) if err != nil { log.Panic("marshal changefeed info failed", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.Error(err)) } return func(targetNodeID node.ID, targetAddr string) *messaging.TargetMessage { @@ -1370,7 +1408,8 @@ func (m *Maintainer) createBootstrapMessageFactory() bootstrap.NewBootstrapReque // only send dispatcher targetNodeID to dispatcher manager on the same node if targetNodeID == m.selfNode.ID { log.Info("create table event trigger dispatcher bootstrap message", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), zap.String("nodeAddr", targetAddr), zap.Any("nodeID", targetNodeID), zap.String("dispatcherID", m.ddlSpan.ID.String()), @@ -1384,10 +1423,11 @@ func (m *Maintainer) createBootstrapMessageFactory() bootstrap.NewBootstrapReque } log.Info("maintainer new bootstrap message to dispatcher orchestrator", - zap.Stringer("changefeedID", m.changefeedID), + zap.String("keyspace", m.changefeedID.Keyspace()), + zap.String("changefeed", m.changefeedID.Name()), + zap.Uint64("startTs", m.startCheckpointTs), zap.String("nodeAddr", targetAddr), - zap.Any("nodeID", targetNodeID), - zap.Uint64("startTs", m.startCheckpointTs)) + zap.Any("nodeID", targetNodeID)) return messaging.NewSingleTargetMessage(targetNodeID, messaging.DispatcherManagerManagerTopic, msg) } diff --git a/maintainer/maintainer_controller.go b/maintainer/maintainer_controller.go index ab07d8c5a6..edb5510d97 100644 --- a/maintainer/maintainer_controller.go +++ b/maintainer/maintainer_controller.go @@ -247,10 +247,11 @@ func (c *Controller) handleStatus(from node.ID, statusList []*heartbeatpb.TableS // No task + no operator => the dispatcher is orphaned (e.g. previous maintainer crashed after creating it, // or lost operator state during failover). Remove it to avoid leaks and duplicated outputs. log.Warn("no span found, remove it", + zap.String("keyspace", c.changefeedID.Keyspace()), zap.String("changefeed", c.changefeedID.Name()), + zap.String("dispatcherID", dispatcherID.String()), zap.String("from", from.String()), - zap.Any("status", status), - zap.String("dispatcherID", dispatcherID.String())) + zap.Any("status", status)) // If the span is not found but status is Working, we need to remove it from dispatcher. msg := replica.NewRemoveDispatcherMessage( from, @@ -269,6 +270,7 @@ func (c *Controller) handleStatus(from node.ID, statusList []*heartbeatpb.TableS if nodeID != from { // todo: handle the case that the nodeID is mismatch log.Warn("nodeID not match", + zap.String("keyspace", c.changefeedID.Keyspace()), zap.String("changefeed", c.changefeedID.Name()), zap.Any("from", from), zap.Stringer("node", nodeID)) @@ -308,9 +310,10 @@ func (c *Controller) handleStatus(from node.ID, statusList []*heartbeatpb.TableS } if spanController.MarkSpanAbsentIfCurrent(stm, from) { log.Warn("dispatcher becomes non-working without operator, mark span absent for rescheduling", + zap.String("keyspace", c.changefeedID.Keyspace()), zap.String("changefeed", c.changefeedID.Name()), - zap.String("from", from.String()), zap.String("dispatcherID", dispatcherID.String()), + zap.String("from", from.String()), zap.Any("status", status)) } } @@ -338,6 +341,7 @@ func (c *Controller) removeTerminalSpanCoveredByMergedSpan( // maintainer failover. When the merged span already covers the source range, the source // is obsolete desired state and must be removed instead of being marked absent. log.Info("remove terminal span covered by merged span", + zap.String("keyspace", c.changefeedID.Keyspace()), zap.String("changefeed", c.changefeedID.Name()), zap.String("dispatcherID", stm.ID.String()), zap.String("coveringDispatcherID", candidate.ID.String())) diff --git a/maintainer/maintainer_controller_bootstrap.go b/maintainer/maintainer_controller_bootstrap.go index d89b313e55..2a060e9b3a 100644 --- a/maintainer/maintainer_controller_bootstrap.go +++ b/maintainer/maintainer_controller_bootstrap.go @@ -83,20 +83,24 @@ func (c *Controller) FinishBootstrap( ) (*heartbeatpb.MaintainerPostBootstrapRequest, error) { if c.bootstrapped { log.Info("maintainer already bootstrapped, may a new node join the cluster", - zap.Stringer("changefeed", c.changefeedID), + zap.String("keyspace", c.changefeedID.Keyspace()), + zap.String("changefeed", c.changefeedID.Name()), zap.Any("allNodesResp", allNodesResp)) return nil, nil } log.Info("all nodes have sent bootstrap response, start to handle them", - zap.Stringer("changefeed", c.changefeedID), + zap.String("keyspace", c.changefeedID.Keyspace()), + zap.String("changefeed", c.changefeedID.Name()), zap.Int("nodeCount", len(allNodesResp))) // Step 1: Determine start timestamp and update DDL dispatcher startTs, redoStartTs, err := c.determineStartTs(allNodesResp) if err != nil { log.Error("can not determine the startTs from the bootstrap response", - zap.String("changefeed", c.changefeedID.Name()), zap.Error(err)) + zap.String("keyspace", c.changefeedID.Keyspace()), + zap.String("changefeed", c.changefeedID.Name()), + zap.Error(err)) return nil, errors.Trace(err) } @@ -114,6 +118,7 @@ func (c *Controller) FinishBootstrap( f, err := filter.NewFilter(c.replicaConfig.Filter, "", util.GetOrZero(c.replicaConfig.CaseSensitive), util.GetOrZero(c.replicaConfig.ForceReplicate)) if err != nil { log.Error("load table from scheme store failed", + zap.String("keyspace", c.changefeedID.Keyspace()), zap.String("changefeed", c.changefeedID.Name()), zap.Error(err)) return nil, err @@ -122,6 +127,7 @@ func (c *Controller) FinishBootstrap( tables, err := c.loadTables(ctx, startTs, schemaStore, f, txnOrderMatcher) if err != nil { log.Error("load table from scheme store failed", + zap.String("keyspace", c.changefeedID.Keyspace()), zap.String("changefeed", c.changefeedID.Name()), zap.Error(err)) return nil, errors.Trace(err) @@ -136,6 +142,7 @@ func (c *Controller) FinishBootstrap( redoTables, err = c.loadTables(ctx, redoStartTs, schemaStore, f, txnOrderMatcher) if err != nil { log.Error("load table from scheme store failed", + zap.String("keyspace", c.changefeedID.Keyspace()), zap.String("changefeed", c.changefeedID.Name()), zap.Error(err)) return nil, errors.Trace(err) @@ -224,9 +231,10 @@ func (c *Controller) determineStartTs(allNodesResp map[node.ID]*heartbeatpb.Main ) for node, resp := range allNodesResp { log.Info("handle bootstrap response", - zap.Stringer("changefeed", c.changefeedID), - zap.Stringer("nodeID", node), + zap.String("keyspace", c.changefeedID.Keyspace()), + zap.String("changefeed", c.changefeedID.Name()), zap.Uint64("checkpointTs", resp.CheckpointTs), + zap.Stringer("nodeID", node), zap.Int("spanCount", len(resp.Spans))) if resp.CheckpointTs > startTs { startTs = resp.CheckpointTs @@ -376,11 +384,13 @@ func (c *Controller) processTableSpans( } if isTableWorking { log.Info("table already reported by bootstrap snapshots", - zap.Stringer("changefeed", c.changefeedID), + zap.String("keyspace", c.changefeedID.Keyspace()), + zap.String("changefeed", c.changefeedID.Name()), zap.Int64("tableID", table.TableID)) } else { log.Info("table spans already exist in span controller during bootstrap", - zap.Stringer("changefeed", c.changefeedID), + zap.String("keyspace", c.changefeedID.Keyspace()), + zap.String("changefeed", c.changefeedID.Name()), zap.Int64("tableID", table.TableID)) } @@ -477,12 +487,14 @@ func (c *Controller) handleRemainingWorkingTasks( ) { for tableID := range redoWorkingTaskMap { log.Warn("found a redo working table that is not in initial table map, just ignore it", - zap.Stringer("changefeed", c.changefeedID), + zap.String("keyspace", c.changefeedID.Keyspace()), + zap.String("changefeed", c.changefeedID.Name()), zap.Int64("tableID", tableID)) } for tableID := range workingTaskMap { log.Warn("found a working table that is not in initial table map, just ignore it", - zap.Stringer("changefeed", c.changefeedID), + zap.String("keyspace", c.changefeedID.Keyspace()), + zap.String("changefeed", c.changefeedID.Name()), zap.Int64("tableID", tableID)) } } @@ -957,7 +969,8 @@ func (c *Controller) removeUnexpectedBootstrapOverlaps( } log.Warn("remove unexpected overlapping dispatcher reported during bootstrap", - zap.Stringer("changefeed", c.changefeedID), + zap.String("keyspace", c.changefeedID.Keyspace()), + zap.String("changefeed", c.changefeedID.Name()), zap.Int64("tableID", tableID), zap.String("keptDispatcherID", existing.ID.String()), zap.String("dispatcherID", candidate.ID.String()), @@ -1000,7 +1013,8 @@ func (c *Controller) addBootstrapCleanupOperator(replicaSet *replica.SpanReplica ) if !operatorController.AddOperator(op) { log.Warn("failed to add cleanup operator for unexpected bootstrap dispatcher", - zap.Stringer("changefeed", c.changefeedID), + zap.String("keyspace", c.changefeedID.Keyspace()), + zap.String("changefeed", c.changefeedID.Name()), zap.String("dispatcherID", replicaSet.ID.String()), zap.String("nodeID", replicaSet.GetNodeID().String()), zap.Int64("mode", replicaSet.GetMode())) @@ -1161,15 +1175,17 @@ func validateBootstrapOperatorRequest( ) (common.DispatcherID, bool) { if req == nil || req.Config == nil || req.Config.DispatcherID == nil { log.Warn("bootstrap operator config is nil, skip restoring it", - zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String())) + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), + zap.String("nodeID", nodeID.String())) return common.DispatcherID{}, false } dispatcherID := common.NewDispatcherIDFromPB(req.Config.DispatcherID) if dispatcherID.IsZero() { log.Warn("bootstrap operator has invalid dispatcher id, skip restoring it", - zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String())) + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), + zap.String("nodeID", nodeID.String())) return common.DispatcherID{}, false } if req.Config.Mode != mode { @@ -1205,9 +1221,10 @@ func normalizeBootstrapOperatorSpanAndSchemaID( } if span == nil { log.Warn("bootstrap operator missing span, skip restoring it", - zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("dispatcherID", dispatcherID.String()), + zap.String("nodeID", nodeID.String()), zap.String("operatorType", req.OperatorType.String()), zap.String("scheduleAction", req.ScheduleAction.String())) return nil, 0, false @@ -1312,11 +1329,12 @@ func (c *Controller) restoreCurrentWorkingCreateAction( // The table is absent from both the snapshot and confirmed post-snapshot // additions. Restoring this stale create would recreate a dropped table. log.Warn("bootstrap create operator references table missing from schema snapshot, skip restoring it", - zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("dispatcherID", dispatcherID.String()), - zap.String("operatorType", req.OperatorType.String()), - zap.Int64("tableID", span.TableID)) + zap.Int64("tableID", span.TableID), + zap.String("nodeID", nodeID.String()), + zap.String("operatorType", req.OperatorType.String())) return nil } @@ -1324,16 +1342,18 @@ func (c *Controller) restoreCurrentWorkingCreateAction( // the dispatcher (or maintainer already bound the span), treat it as done. if spanInfo != nil { log.Debug("dispatcher already exists, skip restoring add operator", - zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", dispatcherID.String())) + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), + zap.String("dispatcherID", dispatcherID.String()), + zap.String("nodeID", nodeID.String())) return nil } if replicaSet != nil && replicaSet.IsScheduled() { log.Debug("dispatcher already scheduled, skip restoring add operator", - zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", dispatcherID.String())) + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), + zap.String("dispatcherID", dispatcherID.String()), + zap.String("nodeID", nodeID.String())) return nil } if replicaSet == nil { @@ -1369,9 +1389,10 @@ func (c *Controller) restoreCurrentWorkingRemoveAction( if replicaSet == nil { if spanInfo == nil { log.Warn("bootstrap remove operator missing span info, skip restoring it", - zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("dispatcherID", dispatcherID.String()), + zap.String("nodeID", nodeID.String()), zap.String("operatorType", req.OperatorType.String())) return nil } @@ -1435,8 +1456,9 @@ func (c *Controller) handleCurrentWorkingAdd( if ok := operatorController.AddOperator(op); !ok { log.Error("add operator failed when dealing current working operators in bootstrap, should not happen", zap.String("nodeID", node.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", op.ID().String()), + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), + zap.String("dispatcher", op.ID().String()), zap.String("originOperatorType", req.OperatorType.String()), zap.Any("operator", op), ) @@ -1486,8 +1508,9 @@ func (c *Controller) handleCurrentWorkingRemove( if ok := operatorController.AddOperator(op); !ok { log.Error("add operator failed when dealing current working operators in bootstrap, should not happen", zap.String("nodeID", node.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", op.ID().String()), + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), + zap.String("dispatcher", op.ID().String()), zap.String("originOperatorType", req.OperatorType.String()), zap.Any("operator", op), ) @@ -1513,8 +1536,9 @@ func (c *Controller) handleCurrentWorkingRemove( if ok := operatorController.AddOperator(op); !ok { log.Error("add operator failed when dealing current working operators in bootstrap, should not happen", zap.String("nodeID", node.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", op.ID().String()), + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), + zap.String("dispatcher", op.ID().String()), zap.String("originOperatorType", req.OperatorType.String()), zap.Any("operator", op), ) @@ -1544,16 +1568,18 @@ func (c *Controller) restoreCurrentMergeOperators( } if len(mergeReq.DispatcherIDs) < 2 { log.Warn("merge operator has insufficient dispatcher IDs", - zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String())) + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), + zap.String("nodeID", nodeID.String())) continue } tableSplitMap, ok := tableSplitMapForMode(mergeReq.Mode, tableSplitMaps) if !ok { log.Warn("skip restoring merge operator due to unavailable mode", + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), zap.Int64("mode", mergeReq.Mode)) continue } @@ -1561,8 +1587,9 @@ func (c *Controller) restoreCurrentMergeOperators( operatorController := c.getOperatorController(mergeReq.Mode) if spanController == nil || operatorController == nil { log.Warn("skip restoring merge operator due to uninitialized controller", + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), zap.Int64("mode", mergeReq.Mode)) continue } @@ -1570,8 +1597,9 @@ func (c *Controller) restoreCurrentMergeOperators( mergedDispatcherID := common.NewDispatcherIDFromPB(mergeReq.MergedDispatcherID) if mergedDispatcherID.IsZero() { log.Warn("skip restoring merge operator due to invalid merged dispatcher ID", + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), zap.Int64("mode", mergeReq.Mode)) continue } @@ -1611,10 +1639,11 @@ func (c *Controller) restoreCurrentMergeOperators( splitable, tableExists := tableSplitMap[spanInfo.Span.TableID] if !tableExists { log.Warn("skip restoring merge operator because source table is missing from schema snapshot", - zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", dispatcherID.String()), + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.Int64("tableID", spanInfo.Span.TableID), + zap.String("nodeID", nodeID.String()), + zap.String("dispatcher", dispatcherID.String()), zap.Int64("mode", mergeReq.Mode)) skipMerge = true break @@ -1628,10 +1657,11 @@ func (c *Controller) restoreCurrentMergeOperators( break } else if _, tableExists := tableSplitMap[replicaSet.Span.TableID]; !tableExists { log.Warn("skip restoring merge operator because source table is missing from schema snapshot", - zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", dispatcherID.String()), + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.Int64("tableID", replicaSet.Span.TableID), + zap.String("nodeID", nodeID.String()), + zap.String("dispatcher", dispatcherID.String()), zap.Int64("mode", mergeReq.Mode)) skipMerge = true break @@ -1648,19 +1678,21 @@ func (c *Controller) restoreCurrentMergeOperators( if mergedSpanInfo != nil { if mergedSpanInfo.Span == nil { log.Warn("skip restoring merge operator because merged span is missing", + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", mergedDispatcherID.String()), + zap.String("dispatcher", mergedDispatcherID.String()), zap.Int64("mode", mergeReq.Mode)) cleanupCreatedSourceReplicaSets() continue } if _, tableExists := tableSplitMap[mergedSpanInfo.Span.TableID]; !tableExists { log.Warn("skip restoring merge operator because merged table is missing from schema snapshot", - zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", mergedDispatcherID.String()), + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.Int64("tableID", mergedSpanInfo.Span.TableID), + zap.String("nodeID", nodeID.String()), + zap.String("dispatcher", mergedDispatcherID.String()), zap.Int64("mode", mergeReq.Mode)) cleanupCreatedSourceReplicaSets() continue @@ -1669,10 +1701,11 @@ func (c *Controller) restoreCurrentMergeOperators( if mergedReplicaSet != nil && mergedReplicaSet.Span != nil { if _, tableExists := tableSplitMap[mergedReplicaSet.Span.TableID]; !tableExists { log.Warn("skip restoring merge operator because merged table is missing from schema snapshot", - zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", mergedDispatcherID.String()), + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.Int64("tableID", mergedReplicaSet.Span.TableID), + zap.String("nodeID", nodeID.String()), + zap.String("dispatcher", mergedDispatcherID.String()), zap.Int64("mode", mergeReq.Mode)) cleanupCreatedSourceReplicaSets() continue @@ -1685,9 +1718,10 @@ func (c *Controller) restoreCurrentMergeOperators( // represents a later concrete action for the same dispatcher. Treat the merge record // as stale instead of failing the entire bootstrap. log.Warn("skip restoring stale merge operator due to conflicting bootstrap operator", + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", conflictingDispatcherID.String()), + zap.String("dispatcher", conflictingDispatcherID.String()), zap.String("operatorType", conflictingOperatorType), zap.String("mergedDispatcherID", mergedDispatcherID.String()), zap.Int64("mode", mergeReq.Mode)) @@ -1715,17 +1749,19 @@ func (c *Controller) restoreCurrentMergeOperators( spanController.MarkSpanReplicating(mergedReplicaSet) } log.Info("merge already finished during bootstrap", + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", mergedDispatcherID.String())) + zap.String("dispatcher", mergedDispatcherID.String())) continue } if !sourceComplete || len(sourceReplicaSets) < 2 { log.Warn("skip restoring merge operator due to missing source dispatchers", + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", mergedDispatcherID.String())) + zap.String("dispatcher", mergedDispatcherID.String())) if mergedSpanInfo != nil && isCommittedMergeTargetState(mergedSpanInfo.ComponentStatus) { if mergedReplicaSet == nil { @@ -1744,9 +1780,10 @@ func (c *Controller) restoreCurrentMergeOperators( spanController.RemoveReplicatingSpan(replicaSet) } log.Info("continue merge from existing merged dispatcher after source loss", + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", mergedDispatcherID.String()), + zap.String("dispatcher", mergedDispatcherID.String()), zap.Any("status", mergedSpanInfo.ComponentStatus)) continue } @@ -1758,9 +1795,10 @@ func (c *Controller) restoreCurrentMergeOperators( c.addBootstrapCleanupOperator(mergedReplicaSet) targetStatus, _ := bootstrapMergeTargetStatus(mergedSpanInfo, mergedReplicaSet) log.Info("abort incomplete merge from uncommitted merged dispatcher", + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", mergedDispatcherID.String()), + zap.String("dispatcher", mergedDispatcherID.String()), zap.Any("status", targetStatus)) continue } @@ -1784,9 +1822,10 @@ func (c *Controller) restoreCurrentMergeOperators( mergedSpan, schemaID, checkpointTs, ok := buildMergedSpanFromReplicas(sourceReplicaSets) if !ok { log.Warn("skip restoring merge operator due to invalid merge spans", + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", mergedDispatcherID.String())) + zap.String("dispatcher", mergedDispatcherID.String())) cleanupCreatedSourceReplicaSets() continue } @@ -1812,18 +1851,21 @@ func (c *Controller) restoreCurrentMergeOperators( if mergedReplicaSet == nil { log.Warn("merge replica set not found when restoring merge", + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", mergedDispatcherID.String())) + zap.String("dispatcher", mergedDispatcherID.String())) continue } if operatorController.AddRestoredMergeOperator(sourceReplicaSets, mergedReplicaSet) == nil { log.Warn("skip stale merge operator that cannot be restored", + zap.String("keyspace", resp.ChangefeedID.Keyspace), + zap.String("changefeed", resp.ChangefeedID.Name), zap.String("nodeID", nodeID.String()), - zap.String("changefeed", resp.ChangefeedID.String()), - zap.String("dispatcherID", mergedDispatcherID.String()), - zap.Int("sourceReplicaSetCount", len(sourceReplicaSets))) + zap.String("dispatcher", mergedDispatcherID.String()), + zap.Any("mergedReplicaSet", mergedReplicaSet), + zap.Any("toMergedReplicaSets", sourceReplicaSets)) c.reconcileUnrestorableBootstrapMerge( mergedReplicaSet, mergedSpanInfo, diff --git a/maintainer/maintainer_manager_maintainers.go b/maintainer/maintainer_manager_maintainers.go index d706759d06..aa5238b801 100644 --- a/maintainer/maintainer_manager_maintainers.go +++ b/maintainer/maintainer_manager_maintainers.go @@ -94,8 +94,9 @@ func (m *Manager) onAddMaintainerRequest(req *heartbeatpb.AddMaintainerRequest) if currentLiveness == liveness.CaptureStopping { changefeedID := common.NewChangefeedIDFromPB(req.Id) log.Info("reject add maintainer request because node is stopping", - zap.Stringer("nodeID", m.nodeInfo.ID), - zap.Stringer("changefeedID", changefeedID)) + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), + zap.Stringer("nodeID", m.nodeInfo.ID)) return nil } @@ -121,10 +122,14 @@ func (m *Manager) onDispatchMaintainerRequest( switch msg.Type { case messaging.TypeAddMaintainerRequest: changefeedID := common.NewChangefeedIDFromPB(msg.Message[0].(*heartbeatpb.AddMaintainerRequest).Id) - fields = append(fields, zap.Stringer("changefeedID", changefeedID)) + fields = append(fields, + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name())) case messaging.TypeRemoveMaintainerRequest: changefeedID := common.NewChangefeedIDFromPB(msg.Message[0].(*heartbeatpb.RemoveMaintainerRequest).Id) - fields = append(fields, zap.Stringer("changefeedID", changefeedID)) + fields = append(fields, + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name())) } log.Warn("ignore invalid coordinator id", fields...) return nil @@ -202,7 +207,8 @@ func (p *managerMaintainerSet) handleAddMaintainer( changefeedID := common.NewChangefeedIDFromPB(req.Id) if req.CheckpointTs == 0 { log.Error("ignore add maintainer request with invalid checkpointTs", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Uint64("checkpointTs", req.CheckpointTs)) return nil } @@ -213,7 +219,8 @@ func (p *managerMaintainerSet) handleAddMaintainer( info := &config.ChangeFeedInfo{} if err := json.Unmarshal(req.Config, info); err != nil { log.Error("ignore add maintainer request with invalid config", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Int("configBytes", len(req.Config)), zap.Error(err)) return nil @@ -325,7 +332,8 @@ func logRejectedAddMaintainer(changefeedID common.ChangeFeedID, existing *Mainta return } log.Warn("reject add maintainer request because existing maintainer is still running", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Uint64("requestMaintainerEpoch", requestEpoch), zap.Uint64("existingMaintainerEpoch", existingEpoch), zap.Bool("existingRemoved", existing.removed.Load()), @@ -341,7 +349,8 @@ func (p *managerMaintainerSet) handleRemoveMaintainer(msg *messaging.TargetMessa if !req.Cascade { log.Warn("ignore remove maintainer request, "+ "since the maintainer not found", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Any("request", req)) return &heartbeatpb.MaintainerStatus{ ChangefeedID: req.GetId(), @@ -375,7 +384,8 @@ func (p *managerMaintainerSet) handleRemoveMaintainer(msg *messaging.TargetMessa message: msg, }) log.Info("received remove maintainer request", - zap.Stringer("changefeedID", changefeedID)) + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name())) return nil } @@ -423,7 +433,8 @@ func (p *managerMaintainerSet) cleanupRemovedMaintainer(key, value interface{}) } cf.Close() log.Info("maintainer removed, remove it from dynamic stream", - zap.Stringer("changefeedID", cf.changefeedID), + zap.String("keyspace", cf.changefeedID.Keyspace()), + zap.String("changefeed", cf.changefeedID.Name()), zap.Uint64("checkpointTs", cf.getWatermark().CheckpointTs), ) } @@ -445,7 +456,8 @@ func (p *managerMaintainerSet) dispatchMaintainerMessage( c, ok := p.registry.Load(changefeed) if !ok { log.Warn("maintainer is not found", - zap.Stringer("changefeedID", changefeed), + zap.String("keyspace", changefeed.Keyspace()), + zap.String("changefeed", changefeed.Name()), zap.String("message", msg.String())) return nil } diff --git a/maintainer/operator/operator_add.go b/maintainer/operator/operator_add.go index 1ef8ed98ef..0f30141ddc 100644 --- a/maintainer/operator/operator_add.go +++ b/maintainer/operator/operator_add.go @@ -86,19 +86,22 @@ func (m *AddDispatcherOperator) Check(from node.ID, status *heartbeatpb.TableSpa switch status.ComponentStatus { case heartbeatpb.ComponentState_Working: log.Info("dispatcher report working status", - zap.String("changefeed", m.replicaSet.ChangefeedID.String()), - zap.String("dispatcherID", m.replicaSet.ID.String())) + zap.String("keyspace", m.replicaSet.ChangefeedID.Keyspace()), + zap.String("changefeed", m.replicaSet.ChangefeedID.Name()), + zap.String("replicaSet", m.replicaSet.ID.String())) m.finished.Store(true) case heartbeatpb.ComponentState_Removed: log.Info("dispatcher report removed status", - zap.String("changefeed", m.replicaSet.ChangefeedID.String()), - zap.String("dispatcherID", m.replicaSet.ID.String())) + zap.String("keyspace", m.replicaSet.ChangefeedID.Keyspace()), + zap.String("changefeed", m.replicaSet.ChangefeedID.Name()), + zap.String("replicaSet", m.replicaSet.ID.String())) m.finished.Store(true) m.removed.Store(true) case heartbeatpb.ComponentState_Stopped: log.Warn("dispatcher report unexpected stopped status, ignore", - zap.String("changefeed", m.replicaSet.ChangefeedID.String()), - zap.String("dispatcherID", m.replicaSet.ID.String())) + zap.String("keyspace", m.replicaSet.ChangefeedID.Keyspace()), + zap.String("changefeed", m.replicaSet.ChangefeedID.Name()), + zap.String("replicaSet", m.replicaSet.ID.String())) } } diff --git a/maintainer/operator/operator_controller.go b/maintainer/operator/operator_controller.go index 55514ab7a7..b9a9a9a286 100644 --- a/maintainer/operator/operator_controller.go +++ b/maintainer/operator/operator_controller.go @@ -243,17 +243,19 @@ func (oc *Controller) AddOperator(op operator.Operator[common.DispatcherID, *hea if !oc.isOperatorAllowedLocked(op.ID()) { oc.mu.RUnlock() log.Info("add operator failed, controller is quiescing", - zap.String("role", oc.role), - zap.Stringer("changefeedID", oc.changefeedID), + zap.String("keyspace", oc.changefeedID.Keyspace()), + zap.String("changefeed", oc.changefeedID.Name()), zap.String("dispatcherID", op.ID().String()), + zap.String("role", oc.role), zap.String("operator", op.String())) return false } if old, ok := oc.operators[op.ID()]; ok { oc.mu.RUnlock() log.Info("add operator failed, operator already exists", + zap.String("keyspace", oc.changefeedID.Keyspace()), + zap.String("changefeed", oc.changefeedID.Name()), zap.String("role", oc.role), - zap.Stringer("changefeedID", oc.changefeedID), zap.String("operator", op.String()), zap.String("oldOperator", old.OP.String())) return false @@ -262,8 +264,9 @@ func (oc *Controller) AddOperator(op operator.Operator[common.DispatcherID, *hea span := oc.spanController.GetTaskByID(op.ID()) if span == nil { log.Warn("add operator failed, span not found", + zap.String("keyspace", oc.changefeedID.Keyspace()), + zap.String("changefeed", oc.changefeedID.Name()), zap.String("role", oc.role), - zap.Stringer("changefeedID", oc.changefeedID), zap.String("operator", op.String())) return false } @@ -412,8 +415,9 @@ func (oc *Controller) pollQueueingOperator() ( if shouldWarn { log.Warn("operator is still in running queue", - zap.Stringer("changefeedID", oc.changefeedID), - zap.String("dispatcherID", opID.String()), + zap.String("keyspace", oc.changefeedID.Keyspace()), + zap.String("changefeed", oc.changefeedID.Name()), + zap.String("operator", opID.String()), zap.String("operator", op.String()), zap.Any("timeSinceCreated", time.Since(item.CreatedAt))) } @@ -455,9 +459,10 @@ func (oc *Controller) finalizeOperator( operatorCount.WithLabelValues(common.DefaultKeyspaceName, oc.changefeedID.Name(), op.Type(), common.StringMode(oc.mode)).Dec() operatorDuration.WithLabelValues(common.DefaultKeyspaceName, oc.changefeedID.Name(), op.Type(), common.StringMode(oc.mode)).Observe(time.Since(item.CreatedAt).Seconds()) log.Info("operator finished", + zap.String("keyspace", oc.changefeedID.Keyspace()), + zap.String("changefeed", oc.changefeedID.Name()), zap.String("role", oc.role), - zap.Stringer("changefeedID", oc.changefeedID), - zap.String("dispatcherID", opID.String()), + zap.String("operatorID", opID.String()), zap.String("operator", op.String())) } @@ -486,9 +491,10 @@ func (oc *Controller) removeReplicaSet(op *removeDispatcherOperator) { if !oc.isOperatorAllowed(op.ID()) { log.Info("skip remove operator while controller is quiescing", - zap.String("role", oc.role), - zap.Stringer("changefeedID", oc.changefeedID), + zap.String("keyspace", oc.changefeedID.Keyspace()), + zap.String("changefeed", oc.changefeedID.Name()), zap.String("dispatcherID", op.ID().String()), + zap.String("role", oc.role), zap.String("operator", op.String())) return } @@ -497,9 +503,10 @@ func (oc *Controller) removeReplicaSet(op *removeDispatcherOperator) { oc.mu.RUnlock() if ok { log.Info("replica set is removed, replace the old one", + zap.String("keyspace", oc.changefeedID.Keyspace()), + zap.String("changefeed", oc.changefeedID.Name()), zap.String("role", oc.role), - zap.Stringer("changefeedID", oc.changefeedID), - zap.String("dispatcherID", old.OP.ID().String()), + zap.String("replicaSet", old.OP.ID().String()), zap.String("operator", old.OP.String())) old.OP.OnTaskRemoved() oc.finalizeOperator(old, op.ID()) @@ -518,8 +525,9 @@ func (oc *Controller) pushOperatorWithAdmission( if old, ok := oc.operators[opID]; ok && !replaceExisting { oc.mu.Unlock() log.Info("add operator failed, operator already exists", + zap.String("keyspace", oc.changefeedID.Keyspace()), + zap.String("changefeed", oc.changefeedID.Name()), zap.String("role", oc.role), - zap.Stringer("changefeedID", oc.changefeedID), zap.String("operator", op.String()), zap.String("oldOperator", old.OP.String())) return false @@ -527,8 +535,9 @@ func (oc *Controller) pushOperatorWithAdmission( oc.operators[opID] = withTime oc.mu.Unlock() log.Info("add operator to running queue", + zap.String("keyspace", oc.changefeedID.Keyspace()), + zap.String("changefeed", oc.changefeedID.Name()), zap.String("role", oc.role), - zap.Stringer("changefeedID", oc.changefeedID), zap.String("operator", op.String())) op.Start() @@ -605,7 +614,9 @@ func (oc *Controller) addMergeOccupyOperators( continue } log.Error("failed to add occupy dispatcher operator", - zap.Stringer("changefeedID", oc.changefeedID), + zap.String("keyspace", oc.changefeedID.Keyspace()), + zap.String("changefeed", oc.changefeedID.Name()), + zap.String("tableSpan", common.FormatTableSpan(replicaSet.Span)), zap.Int64("group", replicaSet.GetGroupID()), zap.Stringer("dispatcherID", replicaSet.ID), zap.String("operator", occupyOperator.String())) @@ -642,8 +653,9 @@ func (oc *Controller) AddMergeOperator( ret := oc.AddOperator(mergeOperator) if !ret { log.Error("failed to add merge dispatcher operator", - zap.Stringer("changefeedID", oc.changefeedID), - zap.Int("mergeSpanCount", len(affectedReplicaSets)), + zap.String("keyspace", oc.changefeedID.Keyspace()), + zap.String("changefeed", oc.changefeedID.Name()), + zap.Any("mergeSpans", affectedReplicaSets), zap.String("operator", mergeOperator.String())) oc.cancelMergeOccupyOperators(operators) oc.spanController.RemoveReplicatingSpan(mergeOperator.newReplicaSet) @@ -651,7 +663,8 @@ func (oc *Controller) AddMergeOperator( } log.Info("add merge operator", zap.String("role", oc.role), - zap.Stringer("changefeedID", oc.changefeedID), + zap.String("keyspace", oc.changefeedID.Keyspace()), + zap.String("changefeed", oc.changefeedID.Name()), zap.Int("affectedReplicaSets", len(affectedReplicaSets)), ) return mergeOperator @@ -684,15 +697,17 @@ func (oc *Controller) AddRestoredMergeOperator( ret := oc.AddOperator(mergeOperator) if !ret { log.Error("failed to add merge dispatcher operator when restoring merge", - zap.Stringer("changefeedID", oc.changefeedID), - zap.Int("mergeSpanCount", len(affectedReplicaSets)), + zap.String("keyspace", oc.changefeedID.Keyspace()), + zap.String("changefeed", oc.changefeedID.Name()), + zap.Any("mergeSpans", affectedReplicaSets), zap.String("operator", mergeOperator.String())) oc.cancelMergeOccupyOperators(operators) return nil } log.Info("restore merge operator", zap.String("role", oc.role), - zap.Stringer("changefeedID", oc.changefeedID), + zap.String("keyspace", oc.changefeedID.Keyspace()), + zap.String("changefeed", oc.changefeedID.Name()), zap.Int("affectedReplicaSets", len(affectedReplicaSets)), ) return mergeOperator diff --git a/maintainer/operator/operator_merge.go b/maintainer/operator/operator_merge.go index 7a56f09946..890e009206 100644 --- a/maintainer/operator/operator_merge.go +++ b/maintainer/operator/operator_merge.go @@ -199,8 +199,8 @@ func (m *MergeDispatcherOperator) Check(from node.ID, status *heartbeatpb.TableS if from == m.originNode && status.ComponentStatus == heartbeatpb.ComponentState_Working { m.checkpointTs = status.CheckpointTs log.Info("new merged replica set created", - zap.Uint64("checkpointTs", m.checkpointTs), - zap.String("dispatcherID", m.id.String())) + zap.String("dispatcherID", m.id.String()), + zap.Uint64("checkpointTs", m.checkpointTs)) m.finished.Store(true) } } diff --git a/maintainer/operator/operator_move.go b/maintainer/operator/operator_move.go index 63daeb95fe..2b5526a4e8 100644 --- a/maintainer/operator/operator_move.go +++ b/maintainer/operator/operator_move.go @@ -90,7 +90,8 @@ func (m *MoveDispatcherOperator) enterAddDest() { // Caller must hold m.lck. func (m *MoveDispatcherOperator) finishAsAbsent() { log.Info("move dispatcher operator aborted, mark span absent for rescheduling", - zap.Stringer("changefeedID", m.replicaSet.ChangefeedID), + zap.String("keyspace", m.replicaSet.ChangefeedID.Keyspace()), + zap.String("changefeed", m.replicaSet.ChangefeedID.Name()), zap.String("dispatcherID", m.replicaSet.ID.String()), zap.String("origin", m.origin.String()), zap.String("dest", m.dest.String())) @@ -252,8 +253,9 @@ func (m *MoveDispatcherOperator) OnTaskRemoved() { defer m.lck.Unlock() log.Info("replicaset is removed, mark move dispatcher operator finished", - zap.String("dispatcherID", m.replicaSet.ID.String()), - zap.String("changefeed", m.replicaSet.ChangefeedID.String())) + zap.String("keyspace", m.replicaSet.ChangefeedID.Keyspace()), + zap.String("changefeed", m.replicaSet.ChangefeedID.Name()), + zap.String("replicaSet", m.replicaSet.ID.String())) m.spanController.MarkSpanReplicating(m.replicaSet) m.state = moveStateDoneNoPostFinish } @@ -284,7 +286,8 @@ func (m *MoveDispatcherOperator) PostFinish() { } log.Info("move dispatcher operator finished", - zap.Stringer("changefeedID", m.replicaSet.ChangefeedID), + zap.String("keyspace", m.replicaSet.ChangefeedID.Keyspace()), + zap.String("changefeed", m.replicaSet.ChangefeedID.Name()), zap.String("dispatcherID", m.replicaSet.ID.String())) m.spanController.MarkSpanReplicating(m.replicaSet) } diff --git a/maintainer/operator/operator_occupy.go b/maintainer/operator/operator_occupy.go index 1a71ed8c68..d921fd6940 100644 --- a/maintainer/operator/operator_occupy.go +++ b/maintainer/operator/operator_occupy.go @@ -96,10 +96,11 @@ func (m *OccupyDispatcherOperator) Start() { func (m *OccupyDispatcherOperator) PostFinish() { log.Info("occupy dispatcher operator finished", + zap.String("keyspace", m.replicaSet.ChangefeedID.Keyspace()), + zap.String("changefeed", m.replicaSet.ChangefeedID.Name()), zap.Any("removed", m.removed.Load()), zap.Any("finished", m.finished.Load()), - zap.String("changefeed", m.replicaSet.ChangefeedID.String()), - zap.String("dispatcherID", m.replicaSet.ID.String())) + zap.String("replicaSet", m.replicaSet.ID.String())) } func (m *OccupyDispatcherOperator) String() string { diff --git a/maintainer/operator/operator_remove.go b/maintainer/operator/operator_remove.go index ae3ad0239b..2dbbb8c1dc 100644 --- a/maintainer/operator/operator_remove.go +++ b/maintainer/operator/operator_remove.go @@ -150,8 +150,9 @@ func (m *removeDispatcherOperator) Start() { func (m *removeDispatcherOperator) PostFinish() { log.Info("remove dispatcher operator finished", - zap.String("dispatcherID", m.replicaSet.ID.String()), - zap.String("changefeed", m.replicaSet.ChangefeedID.String()), + zap.String("keyspace", m.replicaSet.ChangefeedID.Keyspace()), + zap.String("changefeed", m.replicaSet.ChangefeedID.Name()), + zap.String("replicaSet", m.replicaSet.ID.String()), zap.Bool("taskRemoved", m.removed.Load())) // If the task is removed, the span will be cleaned up by spanController, and we must not run diff --git a/maintainer/operator/operator_split.go b/maintainer/operator/operator_split.go index aae053e101..d980d45252 100644 --- a/maintainer/operator/operator_split.go +++ b/maintainer/operator/operator_split.go @@ -15,6 +15,7 @@ package operator import ( "fmt" + "strings" "sync" "sync/atomic" @@ -66,6 +67,16 @@ type SplitDispatcherOperator struct { sendThrottler sendThrottler } +// formatTableSpans formats the given spans for logging. Formatting happens at +// output time so that the current redaction mode always applies. +func formatTableSpans(spans []*heartbeatpb.TableSpan) string { + var sb strings.Builder + for _, span := range spans { + fmt.Fprintf(&sb, "[%s]", common.FormatTableSpan(span)) + } + return sb.String() +} + // NewSplitDispatcherOperator creates a new SplitDispatcherOperator func NewSplitDispatcherOperator( spanController *span.Controller, @@ -180,7 +191,7 @@ func (m *SplitDispatcherOperator) PostFinish() { ret := m.postFinish(span, m.splitTargetNodes[idx]) if !ret { log.Error("post finish in split dispatcher operator failed, set the span absent", - zap.String("sourceDispatcherID", m.replicaSet.ID.String()), + zap.String("id", m.replicaSet.ID.String()), zap.String("dispatcherID", span.ID.String()), zap.String("targetNode", m.splitTargetNodes[idx].String())) m.spanController.MarkSpanAbsent(span) @@ -191,7 +202,7 @@ func (m *SplitDispatcherOperator) PostFinish() { zap.String("dispatcherID", m.replicaSet.ID.String()), zap.Int("targetNodeCount", len(m.splitTargetNodes)), zap.Int("newReplicaCount", len(newReplicaSets)), - zap.Int("splitSpanCount", len(m.splitSpans))) + zap.String("splitSpans", formatTableSpans(m.splitSpans))) } log.Info("split dispatcher operator post finish finished", zap.String("dispatcherID", m.replicaSet.ID.String())) diff --git a/maintainer/replica/checker.go b/maintainer/replica/checker.go index 692e186d8b..46902e261a 100644 --- a/maintainer/replica/checker.go +++ b/maintainer/replica/checker.go @@ -46,7 +46,10 @@ func GetNewGroupChecker( case replica.GroupTable: return NewSplitSpanChecker(cfID, groupID, schedulerCfg, refresher) } - log.Panic("unknown group type", zap.String("changefeed", cfID.Name()), zap.Int8("groupType", int8(groupType))) + log.Panic("unknown group type", + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), + zap.Int8("groupType", int8(groupType))) return nil } } diff --git a/maintainer/replica/default_span_split_checker.go b/maintainer/replica/default_span_split_checker.go index e71ed41529..4529453518 100644 --- a/maintainer/replica/default_span_split_checker.go +++ b/maintainer/replica/default_span_split_checker.go @@ -68,7 +68,9 @@ func NewDefaultSpanSplitChecker( refresher *RegionCountRefresher, ) *defaultSpanSplitChecker { if schedulerCfg == nil { - log.Panic("scheduler config is nil, please check the config", zap.String("changefeed", changefeedID.Name())) + log.Panic("scheduler config is nil, please check the config", + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name())) } return &defaultSpanSplitChecker{ @@ -99,7 +101,10 @@ func (s *defaultSpanSplitChecker) AddReplica(replica *SpanReplication) { return } if !replica.enabledSplit { - log.Debug("default span split checker: replica not enabled to split, skip add", zap.Stringer("changefeed", s.changefeedID), zap.String("dispatcherID", replica.ID.String())) + log.Debug("default span split checker: replica not enabled to split, skip add", + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), + zap.String("replica", replica.ID.String())) return } s.allTasks[replica.ID] = &spanSplitStatus{ @@ -125,7 +130,10 @@ func (s *defaultSpanSplitChecker) RemoveReplica(replica *SpanReplication) { func (s *defaultSpanSplitChecker) UpdateStatus(replica *SpanReplication) { status, ok := s.allTasks[replica.ID] if !ok { - log.Warn("default span split checker: replica not found", zap.String("changefeed", s.changefeedID.Name()), zap.String("dispatcherID", replica.ID.String())) + log.Warn("default span split checker: replica not found", + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), + zap.String("replica", replica.ID.String())) return } if status.GetStatus().ComponentStatus != heartbeatpb.ComponentState_Working { diff --git a/maintainer/replica/region_count_refresher.go b/maintainer/replica/region_count_refresher.go index 8466ccafd2..e52a4e3467 100644 --- a/maintainer/replica/region_count_refresher.go +++ b/maintainer/replica/region_count_refresher.go @@ -57,7 +57,8 @@ func (r *RegionCountRefresher) addDispatcher(ctx context.Context, id common.Disp regions, err := r.regionCache.LoadRegionsInKeyRange(backoff, span.StartKey, span.EndKey) if err != nil { log.Warn("load regions failed, just continue", - zap.Stringer("changefeedID", r.changefeedID), + zap.String("keyspace", r.changefeedID.Keyspace()), + zap.String("changefeed", r.changefeedID.Name()), zap.Stringer("dispatcherID", id), zap.Error(err)) } @@ -83,7 +84,9 @@ func (r *RegionCountRefresher) Run(ctx context.Context) { for { select { case <-ctx.Done(): - log.Info("region count refresher exited", zap.Stringer("changefeedID", r.changefeedID)) + log.Info("region count refresher exited", + zap.String("keyspace", r.changefeedID.Keyspace()), + zap.String("changefeed", r.changefeedID.Name())) return case <-ticker.C: r.queryRegionCount(ctx) @@ -107,7 +110,8 @@ func (r *RegionCountRefresher) queryRegionCount(ctx context.Context) { ) if err != nil { log.Warn("load regions failed, just continue", - zap.Stringer("changefeedID", r.changefeedID), + zap.String("keyspace", r.changefeedID.Keyspace()), + zap.String("changefeed", r.changefeedID.Name()), zap.Stringer("dispatcherID", dispatcherID), zap.Error(err)) return true @@ -118,7 +122,9 @@ func (r *RegionCountRefresher) queryRegionCount(ctx context.Context) { if tableCount > 0 { log.Info("refresh region count for all tables", - zap.Stringer("changefeedID", r.changefeedID), - zap.Int("tableCount", tableCount), zap.Duration("duration", time.Since(start))) + zap.String("keyspace", r.changefeedID.Keyspace()), + zap.String("changefeed", r.changefeedID.Name()), + zap.Int("tableCount", tableCount), + zap.Duration("duration", time.Since(start))) } } diff --git a/maintainer/replica/replication_span.go b/maintainer/replica/replication_span.go index 465afa20c1..518635990e 100644 --- a/maintainer/replica/replication_span.go +++ b/maintainer/replica/replication_span.go @@ -23,6 +23,7 @@ import ( "github.com/pingcap/ticdc/pkg/messaging" "github.com/pingcap/ticdc/pkg/node" "github.com/pingcap/ticdc/pkg/scheduler/replica" + "github.com/pingcap/ticdc/pkg/util" "go.uber.org/atomic" "go.uber.org/zap" ) @@ -65,14 +66,15 @@ func NewSpanReplication(cfID common.ChangeFeedID, CheckpointTs: checkpointTs, Mode: mode, }) - log.Info("new span replication created", - zap.Stringer("changefeedID", cfID), - zap.Stringer("dispatcherID", id), - zap.Int64("schemaID", SchemaID), + log.Info("span replication created", + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), + zap.String("dispatcherID", id.String()), zap.Int64("tableID", span.TableID), - zap.String("groupID", replica.GetGroupName(r.groupID)), + zap.String("tableSpan", common.FormatTableSpan(span)), zap.Uint64("checkpointTs", checkpointTs), - zap.String("span", common.FormatTableSpan(span))) + zap.Int64("schemaID", SchemaID), + zap.Int64("groupID", r.groupID)) return r } @@ -89,16 +91,17 @@ func NewWorkingSpanReplication( // Must set Node ID when creating a working span replication r.SetNodeID(nodeID) r.initStatus(status) - log.Info("new working span replication created", - zap.Stringer("changefeedID", cfID), + log.Info("span replication created", + zap.String("keyspace", cfID.Keyspace()), + zap.String("changefeed", cfID.Name()), zap.String("dispatcherID", id.String()), - zap.String("nodeID", nodeID.String()), + zap.Int64("tableID", span.TableID), + zap.String("tableSpan", common.FormatTableSpan(span)), zap.Uint64("checkpointTs", status.CheckpointTs), - zap.String("componentStatus", status.ComponentStatus.String()), zap.Int64("schemaID", SchemaID), - zap.Int64("tableID", span.TableID), zap.Int64("groupID", r.groupID), - zap.String("span", common.FormatTableSpan(span))) + zap.String("nodeID", nodeID.String()), + zap.String("componentStatus", status.ComponentStatus.String())) return r } @@ -124,7 +127,8 @@ func (r *SpanReplication) IsSplitEnabled() bool { func (r *SpanReplication) initStatus(status *heartbeatpb.TableSpanStatus) { if status == nil || status.CheckpointTs == 0 { log.Panic("add replica with invalid checkpoint ts", - zap.Stringer("changefeedID", r.ChangefeedID), + zap.String("keyspace", r.ChangefeedID.Keyspace()), + zap.String("changefeed", r.ChangefeedID.Name()), zap.String("dispatcherID", r.ID.String()), zap.Uint64("checkpointTs", status.CheckpointTs), ) @@ -144,10 +148,13 @@ func (r *SpanReplication) initGroupID() { totalSpan := common.TableIDToComparableSpan(span.KeyspaceID, span.TableID) if !common.IsSubSpan(span, totalSpan) { log.Warn("invalid span range", - zap.Stringer("changefeedID", r.ChangefeedID), - zap.String("dispatcherID", r.ID.String()), zap.Int64("tableID", span.TableID), + zap.String("keyspace", r.ChangefeedID.Keyspace()), + zap.String("changefeed", r.ChangefeedID.Name()), + zap.String("dispatcherID", r.ID.String()), + zap.Int64("tableID", span.TableID), zap.String("totalSpan", common.FormatTableSpan(&totalSpan)), - zap.String("span", common.FormatTableSpan(&span))) + zap.String("start", util.RedactKey(span.StartKey)), + zap.String("end", util.RedactKey(span.EndKey))) } if !bytes.Equal(span.StartKey, totalSpan.StartKey) || !bytes.Equal(span.EndKey, totalSpan.EndKey) { r.groupID = replica.GenGroupID(replica.GroupTable, span.TableID) diff --git a/maintainer/replica/split_span_checker.go b/maintainer/replica/split_span_checker.go index bb20f8a4ce..8bfb37c55a 100644 --- a/maintainer/replica/split_span_checker.go +++ b/maintainer/replica/split_span_checker.go @@ -182,7 +182,9 @@ func NewSplitSpanChecker( refresher *RegionCountRefresher, ) *SplitSpanChecker { if schedulerCfg == nil { - log.Panic("scheduler config is nil, please check the config", zap.String("changefeed", changefeedID.Name())) + log.Panic("scheduler config is nil, please check the config", + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name())) } return &SplitSpanChecker{ changefeedID: changefeedID, @@ -227,7 +229,10 @@ func (s *SplitSpanChecker) RemoveReplica(replica *SpanReplication) { func (s *SplitSpanChecker) UpdateStatus(replica *SpanReplication) { status, ok := s.allTasks[replica.ID] if !ok { - log.Warn("split span checker: replica not found", zap.String("changefeed", s.changefeedID.Name()), zap.String("dispatcherID", replica.ID.String())) + log.Warn("split span checker: replica not found", + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), + zap.String("replica", replica.ID.String())) return } if status.GetStatus().ComponentStatus != heartbeatpb.ComponentState_Working { @@ -296,7 +301,8 @@ func (s *SplitSpanChecker) Check(batch int) replica.GroupCheckResult { if !s.checkAllTaskAvailableLocked() { log.Debug("some task is not available, skip check", - zap.String("changefeed", s.changefeedID.String()), + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), zap.Int64("group", s.groupID), ) return results @@ -353,6 +359,7 @@ func (s *SplitSpanChecker) Check(batch int) replica.GroupCheckResult { // only when the lag is less than 30s, we can consider to merge spans. if lag > maxLagThreshold { log.Debug("the lag for the group is too large, skip merge", + zap.String("keyspace", s.changefeedID.Keyspace()), zap.String("changefeed", s.changefeedID.Name()), zap.Int64("groupID", s.groupID), zap.Float64("lag", lag), @@ -424,7 +431,8 @@ func (s *SplitSpanChecker) chooseMoveSpans(minTrafficNodeID node.ID, maxTrafficN if result := s.findOptimalSpanMoves(minTrafficNodeID, maxTrafficNodeID, sortedSpanByStartKey, adjacencyMap, lastThreeTrafficPerNode); len(result) > 0 { results = append(results, result...) log.Info("chooseMoveSpans found multiple move plans", - zap.Any("changefeedID", s.changefeedID), + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), zap.Any("groupID", s.groupID), zap.Int("moveCount", len(result)), zap.Stringer("minTrafficNodeID", minTrafficNodeID), @@ -756,7 +764,8 @@ func (s *SplitSpanChecker) chooseMergedSpans(batchSize int) ([]SplitSpanCheckRes return true } log.Info("chooseMergedSpans merge spans", - zap.String("changefeed", s.changefeedID.String()), + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), zap.Int64("group", s.groupID), zap.Int("mergeSpanCount", len(mergeSpans)), zap.Any("node", mergeSpans[0].GetNodeID()), @@ -783,9 +792,12 @@ func (s *SplitSpanChecker) chooseMergedSpans(batchSize int) ([]SplitSpanCheckRes if !bytes.Equal(prev.Span.EndKey, cur.Span.StartKey) { // just panic for debug log.Panic("unexpected error: span is not continuous", + zap.String("keyspace", s.changefeedID.Keyspace()), zap.String("changefeed", s.changefeedID.Name()), - zap.Any("previousDispatcherID", prev.ID), - zap.Any("dispatcherID", cur.ID), + zap.Any("prev.Span", common.FormatTableSpan(prev.Span)), + zap.Any("prev.dispatcherID", prev.ID), + zap.Any("cur.Span", common.FormatTableSpan(cur.Span)), + zap.Any("cur.dispatcherID", cur.ID), ) } // not in the same node, can't merge @@ -906,8 +918,9 @@ func (s *SplitSpanChecker) chooseSplitSpans( nodeID := status.GetNodeID() if nodeID == "" { log.Info("split span checker: node id is empty, please check the node id", + zap.String("keyspace", s.changefeedID.Keyspace()), zap.String("changefeed", s.changefeedID.Name()), - zap.Stringer("dispatcherID", status.ID)) + zap.String("dispatcherID", status.ID.String())) continue } @@ -930,7 +943,8 @@ func (s *SplitSpanChecker) chooseSplitSpans( if s.writeThreshold > 0 { if status.trafficScore > trafficScoreThreshold { log.Info("chooseSplitSpans split span by traffic", - zap.String("changefeed", s.changefeedID.String()), + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), zap.Int64("group", s.groupID), zap.String("dispatcherID", status.ID.String()), zap.Any("splitTargetNodes", status.GetNodeID()), @@ -955,8 +969,9 @@ func (s *SplitSpanChecker) chooseSplitSpans( if s.regionThreshold > 0 { if status.regionCount > s.regionThreshold { log.Info("chooseSplitSpans split span by region", - zap.String("changefeed", s.changefeedID.String()), - zap.String("dispatcherID", status.ID.String()), + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), + zap.String("splitSpan", status.ID.String()), zap.Int64("group", s.groupID), zap.Any("splitTargetNodes", status.GetNodeID()), ) @@ -1107,9 +1122,10 @@ func (s *SplitSpanChecker) checkBalanceTraffic( if diffTraffic < 0 { log.Panic("unexpected error: diffTraffic is less than 0", zap.Float64("diffTraffic", diffTraffic), + zap.String("keyspace", s.changefeedID.Keyspace()), zap.String("changefeed", s.changefeedID.Name()), - zap.Int("moveSpanCount", len(moveSpans)), - zap.Int("nodeCount", len(taskMap)), + zap.Any("moveSpans", moveSpans), + zap.Any("taskMap", taskMap), ) } // we can only find next possible in sortedSpans[:idx] @@ -1123,7 +1139,8 @@ func (s *SplitSpanChecker) checkBalanceTraffic( if len(moveSpans) > 0 { log.Info("checkBalanceTraffic move spans", - zap.String("changefeed", s.changefeedID.String()), + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), zap.Int64("group", s.groupID), zap.Int("moveSpanCount", len(moveSpans)), zap.Any("minTrafficNodeID", minTrafficNodeID), @@ -1146,8 +1163,9 @@ func (s *SplitSpanChecker) checkBalanceTraffic( } log.Info("checkBalanceTraffic split span", - zap.Stringer("changefeed", s.changefeedID), - zap.String("dispatcherID", span.ID.String()), + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), + zap.String("splitSpan", span.ID.String()), zap.Int64("group", s.groupID), zap.Any("splitTargetNodes", []node.ID{minTrafficNodeID, maxTrafficNodeID}), ) diff --git a/maintainer/scheduler/balance_splits.go b/maintainer/scheduler/balance_splits.go index 7898fdf5de..597bba7f42 100644 --- a/maintainer/scheduler/balance_splits.go +++ b/maintainer/scheduler/balance_splits.go @@ -119,7 +119,8 @@ func (s *balanceSplitsScheduler) Execute() time.Time { replications := s.spanController.GetReplicatingByGroup(group) if len(replications) != s.spanController.GetTaskSizeByGroup(group) { log.Info("here is some spans in the group is not in the replicating state; skip this balance check", - zap.String("changefeed", s.changefeedID.String()), + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), zap.Int64("group", int64(group)), zap.Int("replicatingSize", len(replications)), zap.Int("taskSize", s.spanController.GetTaskSizeByGroup(group))) diff --git a/maintainer/scheduler/drain.go b/maintainer/scheduler/drain.go index bfe07daa8d..a940fb7222 100644 --- a/maintainer/scheduler/drain.go +++ b/maintainer/scheduler/drain.go @@ -162,7 +162,8 @@ func (s *drainScheduler) Execute() time.Time { if scheduled > 0 { log.Info("drain scheduler created move operators", - zap.Stringer("changefeedID", s.changefeedID), + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), zap.Int("scheduledCount", scheduled), zap.String("targetNodeID", target.String()), zap.Uint64("targetEpoch", targetEpoch), @@ -192,7 +193,8 @@ func (s *drainScheduler) ensureDrainSessionLimit(target node.ID, epoch uint64) { s.fixedDrainMoveLimit = calculateDrainMoveLimit(initialTargetDispatcherCount) log.Info("drain scheduler initialized fixed move limit", - zap.Stringer("changefeedID", s.changefeedID), + zap.String("keyspace", s.changefeedID.Keyspace()), + zap.String("changefeed", s.changefeedID.Name()), zap.String("targetNodeID", target.String()), zap.Uint64("targetEpoch", epoch), zap.Int("initialTargetDispatcherCount", initialTargetDispatcherCount), diff --git a/maintainer/span/span_controller.go b/maintainer/span/span_controller.go index 83868cbc5b..1c6139d47a 100644 --- a/maintainer/span/span_controller.go +++ b/maintainer/span/span_controller.go @@ -183,6 +183,7 @@ func (c *Controller) AdvanceMaintainerCommittedCheckpointTs(ts uint64) { func (c *Controller) AddNewTable(table commonEvent.Table, startTs uint64) { if c.IsTableExists(table.TableID) { log.Warn("table already add, ignore", + zap.String("keyspace", c.changefeedID.Keyspace()), zap.String("changefeed", c.changefeedID.Name()), zap.Int64("schema", table.SchemaID), zap.Int64("table", table.TableID)) @@ -492,8 +493,9 @@ func (c *Controller) ReplaceReplicaSet( for _, old := range oldReplications { if _, ok := c.allTasks[old.ID]; !ok { log.Panic("old replica set not found", + zap.String("keyspace", c.changefeedID.Keyspace()), zap.String("changefeed", c.changefeedID.Name()), - zap.String("dispatcherID", old.ID.String())) + zap.String("span", old.ID.String())) } oldCheckpointTs := old.GetStatus().GetCheckpointTs() if checkpointTs > oldCheckpointTs { diff --git a/maintainer/split/region_count_splitter.go b/maintainer/split/region_count_splitter.go index 95652835e0..3eaae3a795 100644 --- a/maintainer/split/region_count_splitter.go +++ b/maintainer/split/region_count_splitter.go @@ -22,6 +22,7 @@ import ( "github.com/pingcap/ticdc/heartbeatpb" "github.com/pingcap/ticdc/pkg/common" appcontext "github.com/pingcap/ticdc/pkg/common/context" + "github.com/pingcap/ticdc/pkg/util" "github.com/tikv/client-go/v2/tikv" "go.uber.org/zap" ) @@ -75,7 +76,7 @@ func (m *regionCountSplitter) split( log.Warn("load regions failed, skip split span", zap.String("keyspace", m.changefeedID.Keyspace()), zap.String("changefeed", m.changefeedID.Name()), - zap.Int64("tableID", span.TableID), + zap.String("tableSpan", common.FormatTableSpan(span)), zap.Error(err)) return []*heartbeatpb.TableSpan{span} } @@ -84,7 +85,7 @@ func (m *regionCountSplitter) split( log.Info("skip split span because region count is less than region threshold or region threshold is 0", zap.String("keyspace", m.changefeedID.Keyspace()), zap.String("changefeed", m.changefeedID.Name()), - zap.Int64("tableID", span.TableID), + zap.String("tableSpan", common.FormatTableSpan(span)), zap.Int("regionCount", len(regions)), zap.Int("regionThreshold", m.regionThreshold)) return []*heartbeatpb.TableSpan{span} @@ -93,7 +94,7 @@ func (m *regionCountSplitter) split( log.Info("skip split span because region count is less than target spans num", zap.String("keyspace", m.changefeedID.Keyspace()), zap.String("changefeed", m.changefeedID.Name()), - zap.Int64("tableID", span.TableID), + zap.String("tableSpan", common.FormatTableSpan(span)), zap.Int("regionCount", len(regions)), zap.Int("targetSpansNum", spansNum)) return []*heartbeatpb.TableSpan{span} @@ -117,7 +118,10 @@ func (m *regionCountSplitter) split( log.Warn("schedulerv3: list region out of order detected", zap.String("keyspace", m.changefeedID.Keyspace()), zap.String("changefeed", m.changefeedID.Name()), - zap.Int64("tableID", span.TableID)) + zap.String("tableSpan", common.FormatTableSpan(span)), + zap.String("lastSpan", common.FormatTableSpan(spans[len(spans)-1])), + zap.String("startKey", util.RedactKey(startKey)), + zap.String("endKey", util.RedactKey(endKey))) return []*heartbeatpb.TableSpan{span} } spans = append(spans, newSpan) @@ -140,7 +144,8 @@ func (m *regionCountSplitter) split( log.Info("split span by region count", zap.String("keyspace", m.changefeedID.Keyspace()), zap.String("changefeed", m.changefeedID.Name()), - zap.Int64("tableID", span.TableID), + zap.String("tableSpan", common.FormatTableSpan(span)), + zap.Uint32("keyspaceID", span.KeyspaceID), zap.Int("spans", len(spans)), zap.Int("regionCount", len(regions)), zap.Int("regionCountPerSpan", m.regionCountPerSpan), diff --git a/maintainer/split/write_bytes_splitter.go b/maintainer/split/write_bytes_splitter.go index 337d27c7d5..d22e5d3a4b 100644 --- a/maintainer/split/write_bytes_splitter.go +++ b/maintainer/split/write_bytes_splitter.go @@ -67,7 +67,7 @@ func (m *writeBytesSplitter) split( log.Warn("scan regions failed, skip split span", zap.String("keyspace", m.changefeedID.Keyspace()), zap.String("changefeed", m.changefeedID.Name()), - zap.Int64("tableID", span.TableID), + zap.String("span", common.FormatTableSpan(span)), zap.Error(err)) return []*heartbeatpb.TableSpan{span} } @@ -76,7 +76,7 @@ func (m *writeBytesSplitter) split( log.Info("split span by written keys", zap.String("keyspace", m.changefeedID.Keyspace()), zap.String("changefeed", m.changefeedID.Name()), - zap.Int64("tableID", span.TableID), + zap.String("span", common.FormatTableSpan(span)), zap.Ints("perSpanRegionCounts", splitInfo.RegionCounts), zap.Uint64s("weights", splitInfo.Weights), zap.Int("spans", len(splitInfo.Spans)), diff --git a/pkg/applier/message/event_group.go b/pkg/applier/message/event_group.go index b1d81ad068..fdffef3b52 100644 --- a/pkg/applier/message/event_group.go +++ b/pkg/applier/message/event_group.go @@ -865,8 +865,10 @@ func (g *EventsGroup) PrepareResolve( // batch lazily so polling those groups does not create a full-sized slice. var entries []spilledMessage seenPayloads := make(map[payloadCacheKey]struct{}) - var plannedBytes int64 - var lastCommitTs uint64 + var ( + plannedBytes int64 + lastCommitTs uint64 + ) valid := iterator.First() for valid { commitTs, err := decodeEventIndexCommitTs(iterator.Key()) @@ -920,8 +922,8 @@ func (g *EventsGroup) PrepareResolve( } if g.outOfOrder { log.Warn("DML events were appended out of order; restore from ordered spill index", - zap.Int32("partition", g.Partition), zap.Int64("tableID", g.tableID), + zap.Int32("partition", g.Partition), zap.Uint64("resolveTs", g.resolvedTs), zap.Int("resolved", len(entries))) g.outOfOrder = false diff --git a/pkg/applier/redo.go b/pkg/applier/redo.go index 0e9a081153..eb440a1c92 100644 --- a/pkg/applier/redo.go +++ b/pkg/applier/redo.go @@ -161,7 +161,8 @@ func (ra *RedoApplier) getTableDDLTs(tableIDs ...int64) ddlTs { skipDML: skipDMLAsStartTsList[0], } log.Info("calculate real startTs for redo apply", - zap.Stringer("changefeedID", ra.rd.GetChangefeedID()), + zap.String("keyspace", ra.rd.GetChangefeedID().Keyspace()), + zap.String("changefeed", ra.rd.GetChangefeedID().Name()), zap.Int64("tableID", tableID), zap.Any("realStartTs", newStartTsList[0]), zap.Any("skipDML", skipDMLAsStartTsList[0]), @@ -312,7 +313,7 @@ func (ra *RedoApplier) applyDDL( } if tableDDLTs.ts >= int64(ddl.DDL.CommitTs) { log.Warn("ignore DDL which commit ts is less than current ts", - zap.Uint64("commitTs", ddl.DDL.CommitTs), zap.Int64("startTs", tableDDLTs.ts), + zap.Int64("startTs", tableDDLTs.ts), zap.Uint64("commitTs", ddl.DDL.CommitTs), zap.String("ddl", ddl.DDL.Query)) // Ignore the previous dml events, because the drop ddl has replicated the downstream // DML + Drop Table: If the drop table ddl is ignored and the previous dmls should be replicated the downstream in the past. diff --git a/pkg/check/cluster.go b/pkg/check/cluster.go index f8f0c05963..d3213e1329 100644 --- a/pkg/check/cluster.go +++ b/pkg/check/cluster.go @@ -62,6 +62,7 @@ func IsSameUpstreamDownstream( return false, err } log.Warn("skip the upstream/downstream cluster verification because allow-same-cluster is enabled", + zap.String("keyspace", changefeedCfg.ChangefeedID.Keyspace()), zap.String("changefeedID", changefeedCfg.ChangefeedID.Name()), zap.String("sinkURI", util.MaskSensitiveDataInURI(changefeedCfg.SinkURI))) return false, nil diff --git a/pkg/common/event/ddl_event.go b/pkg/common/event/ddl_event.go index d6982202e8..d7043c71e7 100644 --- a/pkg/common/event/ddl_event.go +++ b/pkg/common/event/ddl_event.go @@ -21,6 +21,7 @@ import ( "github.com/pingcap/log" "github.com/pingcap/ticdc/pkg/common" + "github.com/pingcap/ticdc/pkg/util" "github.com/pingcap/tidb/pkg/meta/model" "github.com/pingcap/tidb/pkg/parser" "github.com/pingcap/tidb/pkg/parser/ast" @@ -295,7 +296,7 @@ func (d *DDLEvent) GetEvents() []*DDLEvent { log.Panic("split queries failed", zap.Error(err)) } if len(queries) != len(d.MultipleTableInfos) { - log.Panic("queries length should be equal to multipleTableInfos length", zap.String("query", d.Query), zap.Any("multipleTableInfos", d.MultipleTableInfos)) + log.Panic("queries length should be equal to multipleTableInfos length", zap.String("ddlQuery", util.RedactValue(d.Query)), zap.Any("multipleTableInfos", d.MultipleTableInfos)) } t := model.ActionCreateTable @@ -333,11 +334,11 @@ func (d *DDLEvent) GetEvents() []*DDLEvent { func extractRenameTargetExtraFromQuery(query string) (string, string) { stmt, err := parser.New().ParseOneStmt(query, "", "") if err != nil { - log.Panic("parse split rename query failed", zap.String("query", query), zap.Error(err)) + log.Panic("parse split rename query failed", zap.String("ddlQuery", util.RedactValue(query)), zap.Error(err)) } renameStmt, ok := stmt.(*ast.RenameTableStmt) if !ok || len(renameStmt.TableToTables) == 0 { - log.Panic("unexpected split rename query", zap.String("query", query), zap.Any("stmt", stmt)) + log.Panic("unexpected split rename query", zap.String("ddlQuery", util.RedactValue(query)), zap.Any("stmt", stmt)) } oldTable := renameStmt.TableToTables[0].OldTable return oldTable.Schema.O, oldTable.Name.O diff --git a/pkg/common/kv_entry.go b/pkg/common/kv_entry.go index 98c215e605..0752e497c1 100644 --- a/pkg/common/kv_entry.go +++ b/pkg/common/kv_entry.go @@ -52,6 +52,11 @@ const ( // RawKVEntry represents a kv change or a resolved ts event // TODO: use a different struct +var ( + _ fmt.Stringer = RawKVEntry{} + _ fmt.Stringer = (*RawKVEntry)(nil) +) + type RawKVEntry struct { OpType OpType `msg:"op_type"` // offset 0 bytes CRTs uint64 `msg:"crts"` // offset 4 bytes @@ -132,7 +137,7 @@ func (v *RawKVEntry) SplitUpdate() (deleteRow, insertRow *RawKVEntry, err error) return deleteRow, insertRow, nil } -func (v *RawKVEntry) String() string { +func (v RawKVEntry) String() string { return fmt.Sprintf( "OpType: %v, Key: %s, Value: %s, OldValue: %s, StartTs: %d, CRTs: %d, RegionID: %d", v.OpType, util.RedactValue(string(v.Key)), util.RedactValue(string(v.Value)), diff --git a/pkg/config/changefeed.go b/pkg/config/changefeed.go index 41906240dd..910e3f576b 100644 --- a/pkg/config/changefeed.go +++ b/pkg/config/changefeed.go @@ -602,39 +602,39 @@ func (info *ChangeFeedInfo) rmDBOnlyFields() { func (info *ChangeFeedInfo) FixIncompatible() { creatorVersionGate := version.NewCreatorVersionGate(info.CreatorVersion) if creatorVersionGate.ChangefeedStateFromAdminJob() { - log.Info("Start fixing incompatible changefeed state", zap.String("changefeed", info.String())) + log.Info("Start fixing incompatible changefeed state", zap.String("changefeedInfo", info.String())) info.fixState() - log.Info("Fix incompatibility changefeed state completed", zap.String("changefeed", info.String())) + log.Info("Fix incompatibility changefeed state completed", zap.String("changefeedInfo", info.String())) } if creatorVersionGate.ChangefeedAcceptUnknownProtocols() { - log.Info("Start fixing incompatible changefeed MQ sink protocol", zap.String("changefeed", info.String())) + log.Info("Start fixing incompatible changefeed MQ sink protocol", zap.String("changefeedInfo", info.String())) info.fixMQSinkProtocol() - log.Info("Fix incompatibility changefeed MQ sink protocol completed", zap.String("changefeed", info.String())) + log.Info("Fix incompatibility changefeed MQ sink protocol completed", zap.String("changefeedInfo", info.String())) } if creatorVersionGate.ChangefeedAcceptProtocolInMysqlSinURI() { - log.Info("Start fixing incompatible changefeed sink uri", zap.String("changefeed", info.String())) + log.Info("Start fixing incompatible changefeed sink uri", zap.String("changefeedInfo", info.String())) info.fixMySQLSinkProtocol() - log.Info("Fix incompatibility changefeed sink uri completed", zap.String("changefeed", info.String())) + log.Info("Fix incompatibility changefeed sink uri completed", zap.String("changefeedInfo", info.String())) } if util.GetOrZero(info.Config.MemoryQuota) == uint64(0) { - log.Info("Start fixing incompatible memory quota", zap.String("changefeed", info.String())) + log.Info("Start fixing incompatible memory quota", zap.String("changefeedInfo", info.String())) info.fixMemoryQuota() - log.Info("Fix incompatible memory quota completed", zap.String("changefeed", info.String())) + log.Info("Fix incompatible memory quota completed", zap.String("changefeedInfo", info.String())) } if info.Config.ChangefeedErrorStuckDuration == nil { - log.Info("Start fixing incompatible error stuck duration", zap.String("changefeed", info.String())) + log.Info("Start fixing incompatible error stuck duration", zap.String("changefeedInfo", info.String())) info.Config.ChangefeedErrorStuckDuration = GetDefaultReplicaConfig().ChangefeedErrorStuckDuration - log.Info("Fix incompatible error stuck duration completed", zap.String("changefeed", info.String())) + log.Info("Fix incompatible error stuck duration completed", zap.String("changefeedInfo", info.String())) } - log.Info("Start fixing incompatible scheduler", zap.String("changefeed", info.String())) + log.Info("Start fixing incompatible scheduler", zap.String("changefeedInfo", info.String())) inheritV66 := creatorVersionGate.ChangefeedInheritSchedulerConfigFromV66() info.fixScheduler(inheritV66) - log.Info("Fix incompatible scheduler completed", zap.String("changefeed", info.String())) + log.Info("Fix incompatible scheduler completed", zap.String("changefeedInfo", info.String())) } // fixState attempts to fix state loss from upgrading the old owner to the new owner. diff --git a/pkg/config/changefeed_log_test.go b/pkg/config/changefeed_log_test.go index 170d3c8f95..30145c92be 100644 --- a/pkg/config/changefeed_log_test.go +++ b/pkg/config/changefeed_log_test.go @@ -32,12 +32,7 @@ func TestRmUnusedFieldsMasksUnparsableSinkURIInLog(t *testing.T) { info := &ChangeFeedInfo{SinkURI: "mysql://root:verysecure@127.0.0.1:port/", Config: GetDefaultReplicaConfig()} info.RmUnusedFields() - entries := logs.FilterMessage("failed to parse the sink uri").All() + entries := logs.All() require.Len(t, entries, 1) - for _, field := range entries[0].Context { - require.NotContains(t, field.String, "verysecure") - if err, ok := field.Interface.(error); ok { - require.NotContains(t, err.Error(), "verysecure") - } - } + require.Equal(t, "", entries[0].ContextMap()["sinkURI"]) } diff --git a/pkg/encryption/kms/client_test.go b/pkg/encryption/kms/client_test.go index 25a8ff1825..0b5cf5b6cb 100644 --- a/pkg/encryption/kms/client_test.go +++ b/pkg/encryption/kms/client_test.go @@ -51,12 +51,13 @@ func TestKMSClientFactoryErrorPreservesCauseAndMasksEndpoint(t *testing.T) { require.Contains(t, err.Error(), "region=west") require.NotContains(t, err.Error(), "secret-in-query") require.NotContains(t, err.Error(), "password") + var endpoint string for _, entry := range observedLogs.All() { - context := fmt.Sprint(entry.ContextMap(), entry.Message) - require.Contains(t, context, "factory connection failed") - require.NotContains(t, context, "secret-in-query") - require.NotContains(t, context, "password") + if v, ok := entry.ContextMap()["endpoint"].(string); ok { + endpoint = v + } } + require.Equal(t, "https://user:xxxxx@kms.example.com/kms?token=xxxxx", endpoint) } type fakeDecryptor struct { diff --git a/pkg/encryption/tikv_http_client_test.go b/pkg/encryption/tikv_http_client_test.go index 80933087d9..852e861e45 100644 --- a/pkg/encryption/tikv_http_client_test.go +++ b/pkg/encryption/tikv_http_client_test.go @@ -15,7 +15,6 @@ package encryption import ( "context" - "fmt" "net/http" "net/http/httptest" "net/url" @@ -43,47 +42,28 @@ func (m *mockTiKVMetaPDClient) GetAllStores(ctx context.Context, opts ...pdopt.G } func TestTiKVEncryptionHTTPClientResponseBodyLogging(t *testing.T) { - for _, tc := range []struct { - name string - statusCode int - body string - wantLogged bool - }{ - {name: "HTTP error keeps diagnostics", statusCode: http.StatusInternalServerError, body: "diagnostic response", wantLogged: true}, - {name: "decode error hides encryption payload", statusCode: http.StatusOK, body: "encrypted-key-material", wantLogged: false}, - } { - t.Run(tc.name, func(t *testing.T) { - core, observedLogs := observer.New(zapcore.DebugLevel) - restore := plog.ReplaceGlobals(zap.New(core), nil) - defer restore() - - srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { - w.WriteHeader(tc.statusCode) - _, _ = w.Write([]byte(tc.body)) - })) - defer srv.Close() - - srvURL, err := url.Parse(srv.URL) - require.NoError(t, err) - client, err := NewTiKVEncryptionHTTPClient(&mockTiKVMetaPDClient{stores: []*metapb.Store{ - {Id: 1, StatusAddress: srvURL.Host}, - }}, nil) - require.NoError(t, err) - - _, err = client.GetKeyspaceEncryptionMeta(context.Background(), 1) - require.Error(t, err) - logged := "" - for _, entry := range observedLogs.All() { - logged += fmt.Sprint(entry.ContextMap(), entry.Message) - } - if tc.wantLogged { - require.Contains(t, logged, tc.body) - } else { - require.NotContains(t, logged, tc.body) - require.Contains(t, logged, "bodySize") - } - }) - } + core, observedLogs := observer.New(zapcore.DebugLevel) + restore := plog.ReplaceGlobals(zap.New(core), nil) + defer restore() + + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte("encrypted-key-material")) + })) + defer srv.Close() + + srvURL, err := url.Parse(srv.URL) + require.NoError(t, err) + client, err := NewTiKVEncryptionHTTPClient(&mockTiKVMetaPDClient{stores: []*metapb.Store{ + {Id: 1, StatusAddress: srvURL.Host}, + }}, nil) + require.NoError(t, err) + + _, err = client.GetKeyspaceEncryptionMeta(context.Background(), 1) + require.Error(t, err) + entries := observedLogs.All() + require.Len(t, entries, 1) + require.Equal(t, int64(len("encrypted-key-material")), entries[0].ContextMap()["bodySize"]) } func TestTiKVEncryptionHTTPClientGetKeyspaceEncryptionMeta(t *testing.T) { diff --git a/pkg/etcd/etcd.go b/pkg/etcd/etcd.go index 7a28de31e8..675501fa67 100644 --- a/pkg/etcd/etcd.go +++ b/pkg/etcd/etcd.go @@ -492,7 +492,9 @@ func (c *CDCEtcdClientImpl) saveChangefeedAndUpstreamInfo( } if len(jobResp.Kvs) == 0 { // Note that status may not exist, so we don't check it here. - log.Debug("job status not exists", zap.Stringer("changefeed", changeFeedID)) + log.Debug("job status not exists", + zap.String("keyspace", changeFeedID.Keyspace), + zap.String("changefeed", changeFeedID.Name)) } else { jobModRevision = jobResp.Kvs[0].ModRevision } diff --git a/pkg/eventservice/dispatcher_stat.go b/pkg/eventservice/dispatcher_stat.go index 50b55090d8..56e359fa7c 100644 --- a/pkg/eventservice/dispatcher_stat.go +++ b/pkg/eventservice/dispatcher_stat.go @@ -344,7 +344,8 @@ func (a *dispatcherStat) onResolvedTs(resolvedTs uint64) bool { } if !a.hasReceivedFirstResolvedTs.Load() { log.Info("received first resolved ts from event store", - zap.Stringer("changefeedID", a.changefeedStat.changefeedID), + zap.String("keyspace", a.changefeedStat.changefeedID.Keyspace()), + zap.String("changefeed", a.changefeedStat.changefeedID.Name()), zap.Stringer("dispatcherID", a.id), zap.Uint64("resolvedTs", resolvedTs)) a.lastUpdateScanLimitTime.Store(time.Now()) diff --git a/pkg/eventservice/event_broker.go b/pkg/eventservice/event_broker.go index bfe0260c11..3b97859b68 100644 --- a/pkg/eventservice/event_broker.go +++ b/pkg/eventservice/event_broker.go @@ -33,7 +33,6 @@ import ( "github.com/pingcap/ticdc/pkg/node" "github.com/pingcap/ticdc/pkg/ordering" "github.com/pingcap/ticdc/pkg/pdutil" - "github.com/pingcap/ticdc/pkg/util" "github.com/pingcap/ticdc/utils/notifyqueue" "github.com/tikv/client-go/v2/oracle" "go.uber.org/atomic" @@ -313,12 +312,15 @@ func (c *eventBroker) sendDDL(ctx context.Context, remoteID node.ID, e *event.DD } log.Info("send ddl event to dispatcher", - zap.Stringer("changefeedID", d.changefeedStat.changefeedID), + zap.String("keyspace", d.changefeedStat.changefeedID.Keyspace()), + zap.String("changefeed", d.changefeedStat.changefeedID.Name()), zap.Stringer("dispatcherID", d.id), + zap.Uint64("commitTs", e.FinishedTs), zap.Int64("DDLSpanTableID", d.info.GetTableSpan().TableID), zap.Int64("EventTableID", e.GetTableID()), - zap.String("query", e.Query), zap.Uint64("commitTs", e.FinishedTs), - zap.Uint64("seq", e.Seq), zap.Int64("mode", d.info.GetMode())) + zap.String("ddlQuery", e.Query), + zap.Uint64("seq", e.Seq), + zap.Int64("mode", d.info.GetMode())) } func (c *eventBroker) refreshMinSentResolvedTs(ctx context.Context) error { @@ -456,7 +458,8 @@ func (c *eventBroker) logUninitializedDispatchers(ctx context.Context) error { dispatcher := value.(*atomic.Pointer[dispatcherStat]).Load() if isUninitialized(dispatcher) { log.Info("dispatcher not reset", - zap.Stringer("changefeedID", dispatcher.changefeedStat.changefeedID), + zap.String("keyspace", dispatcher.changefeedStat.changefeedID.Keyspace()), + zap.String("changefeed", dispatcher.changefeedStat.changefeedID.Name()), zap.Any("dispatcherID", dispatcher.id)) } return true @@ -465,7 +468,8 @@ func (c *eventBroker) logUninitializedDispatchers(ctx context.Context) error { dispatcher := value.(*atomic.Pointer[dispatcherStat]).Load() if isUninitialized(dispatcher) { log.Info("table trigger dispatcher not reset", - zap.Stringer("changefeedID", dispatcher.changefeedStat.changefeedID), + zap.String("keyspace", dispatcher.changefeedStat.changefeedID.Keyspace()), + zap.String("changefeed", dispatcher.changefeedStat.changefeedID.Name()), zap.Any("dispatcherID", dispatcher.id)) } return true @@ -536,7 +540,8 @@ func (c *eventBroker) getScanTaskRequestResult(task scanTask) scanTaskRequestRes dataRange.CommitTsEnd = min(dataRange.CommitTsEnd, scanMaxTs) if dataRange.CommitTsEnd < commitTsEndBeforeWindow { log.Debug("scan window capped", - zap.Stringer("changefeedID", task.changefeedStat.changefeedID), + zap.String("keyspace", task.changefeedStat.changefeedID.Keyspace()), + zap.String("changefeed", task.changefeedStat.changefeedID.Name()), zap.Stringer("dispatcherID", task.id), zap.Uint64("baseTs", task.changefeedStat.minSentTs.Load()), zap.Uint64("scanMaxTs", scanMaxTs), @@ -564,7 +569,8 @@ func (c *eventBroker) getScanTaskRequestResult(task scanTask) scanTaskRequestRes dataRange.CommitTsEnd = min(commitTsEndBeforeWindow, localScanMaxTs) if dataRange.CommitTsEnd > dataRange.CommitTsStart { log.Info("scan window local advance due to pending barrier event", - zap.Stringer("changefeedID", task.changefeedStat.changefeedID), + zap.String("keyspace", task.changefeedStat.changefeedID.Keyspace()), + zap.String("changefeed", task.changefeedStat.changefeedID.Name()), zap.Stringer("dispatcherID", task.id), zap.Uint64("startTs", dataRange.CommitTsStart), zap.Uint64("globalScanMaxTs", scanMaxTs), @@ -682,7 +688,8 @@ func (c *eventBroker) sendHandshakeIfNeed(task scanTask) { remoteID := node.ID(task.info.GetServerID()) event := event.NewHandshakeEvent(task.id, task.startTs, task.epoch, task.startTableInfo) log.Info("send handshake event to dispatcher", - zap.Stringer("changefeedID", task.changefeedStat.changefeedID), + zap.String("keyspace", task.changefeedStat.changefeedID.Keyspace()), + zap.String("changefeed", task.changefeedStat.changefeedID.Name()), zap.Stringer("dispatcherID", task.id), zap.Int64("tableID", task.info.GetTableSpan().GetTableID()), zap.Uint64("commitTs", event.GetCommitTs()), @@ -734,9 +741,11 @@ func (c *eventBroker) doScan(ctx context.Context, task scanTask) { return } - var interrupted bool - var schemaBlocked bool - var schemaBlockedUntilTs uint64 + var ( + interrupted bool + schemaBlocked bool + schemaBlockedUntilTs uint64 + ) defer func() { c.finishScan(task, interrupted, schemaBlocked, schemaBlockedUntilTs) }() @@ -757,7 +766,8 @@ func (c *eventBroker) doScan(ctx context.Context, task scanTask) { // To avoid the useless scan task. if !c.msgSender.IsReadyToSend(remoteID) { log.Info("The remote target is not ready, skip scan", - zap.Stringer("changefeed", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Stringer("dispatcherID", task.id), zap.Int64("tableID", task.info.GetTableSpan().GetTableID()), zap.String("remote", remoteID.String())) @@ -804,7 +814,8 @@ func (c *eventBroker) doScan(ctx context.Context, task scanTask) { item, ok := c.changefeedMap.Load(changefeedID) if !ok { log.Info("changefeed status is not found, skip scan", - zap.Stringer("changefeed", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Stringer("dispatcherID", task.id), zap.Int64("tableID", task.info.GetTableSpan().GetTableID())) return @@ -814,7 +825,9 @@ func (c *eventBroker) doScan(ctx context.Context, task scanTask) { item, ok = status.availableMemoryQuota.Load(remoteID) if !ok { log.Info("available memory quota is not set, skip scan", - zap.String("changefeed", changefeedID.String()), zap.String("remote", remoteID.String())) + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), + zap.String("remote", remoteID.String())) return } @@ -827,7 +840,8 @@ func (c *eventBroker) doScan(ctx context.Context, task scanTask) { ok = allocQuota(available, uint64(sl.maxDMLBytes)) if !ok { log.Debug("changefeed available memory quota is not enough, skip scan", - zap.String("changefeed", changefeedID.String()), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.String("remote", remoteID.String()), zap.Uint64("available", available.Load()), zap.Uint64("required", uint64(sl.maxDMLBytes))) @@ -838,7 +852,7 @@ func (c *eventBroker) doScan(ctx context.Context, task scanTask) { if uint64(sl.maxDMLBytes) > task.availableMemoryQuota.Load() { releaseQuota(available, uint64(sl.maxDMLBytes)) - log.Debug("dispatcher available memory quota is not enough, skip scan", zap.Stringer("dispatcherID", task.id), zap.Uint64("available", task.availableMemoryQuota.Load()), zap.Int64("required", sl.maxDMLBytes)) + log.Debug("dispatcher available memory quota is not enough, skip scan", zap.Stringer("dispatcherID", task.id), zap.Uint64("available", task.availableMemoryQuota.Load()), zap.Int64("required", int64(sl.maxDMLBytes))) c.sendSignalResolvedTs(task) eventServiceSkipScanCount.WithLabelValues("dispatcher_quota").Inc() return @@ -868,14 +882,14 @@ func (c *eventBroker) doScan(ctx context.Context, task scanTask) { return } log.Error("scan events failed", - zap.Stringer("changefeedID", task.changefeedStat.changefeedID), - zap.Stringer("dispatcherID", task.id), zap.Int64("tableID", task.info.GetTableSpan().GetTableID()), - zap.Uint64("commitTsStart", request.Range.CommitTsStart), - zap.Uint64("commitTsEnd", request.Range.CommitTsEnd), - zap.Uint64("cursorTxnStartTs", request.Cursor.TxnStartTs), - zap.String("cursorPosition", util.RedactKey(request.Cursor.Position)), + zap.String("keyspace", task.changefeedStat.changefeedID.Keyspace()), + zap.String("changefeed", task.changefeedStat.changefeedID.Name()), + zap.Stringer("dispatcherID", task.id), + zap.Int64("tableID", task.info.GetTableSpan().GetTableID()), + zap.Any("scanRequest", request), zap.Uint64("receivedResolvedTs", task.receivedResolvedTs.Load()), - zap.Uint64("sentResolvedTs", task.sentResolvedTs.Load()), zap.Error(err)) + zap.Uint64("sentResolvedTs", task.sentResolvedTs.Load()), + zap.Error(err)) return } if scannedBytes < 0 { @@ -1107,9 +1121,11 @@ func (c *eventBroker) removeInactiveDispatchers() { removeInactive := func(_, value any) bool { d := value.(*atomic.Pointer[dispatcherStat]).Load() if c.isInactiveDispatcher(d) { - log.Warn("remove in-active dispatcher", - zap.Stringer("changefeedID", d.changefeedStat.changefeedID), - zap.Stringer("dispatcherID", d.id), zap.Time("lastReceivedHeartbeatTime", time.Unix(d.lastReceivedHeartbeatTime.Load(), 0))) + log.Warn("remove dispatcher since it's inactive", + zap.String("keyspace", d.changefeedStat.changefeedID.Keyspace()), + zap.String("changefeed", d.changefeedStat.changefeedID.Name()), + zap.Stringer("dispatcherID", d.id), + zap.Time("lastReceivedHeartbeatTime", time.Unix(d.lastReceivedHeartbeatTime.Load(), 0))) c.removeDispatcher(d.info) } return true @@ -1404,11 +1420,14 @@ func (c *eventBroker) addDispatcher(info DispatcherInfo) error { c.dispatcherCount.Inc() c.metricsCollector.metricDispatcherCount.Inc() } - log.Info("table trigger dispatcher register dispatcher", - zap.Uint64("clusterID", c.tidbClusterID), - zap.Stringer("changefeedID", changefeedID), + log.Info("add dispatcher done", + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Stringer("dispatcherID", id), - zap.Uint64("startTs", info.GetStartTs())) + zap.String("tableSpan", common.FormatTableSpan(span)), + zap.Uint64("startTs", info.GetStartTs()), + zap.String("kind", "tableTrigger"), + zap.Uint64("clusterID", c.tidbClusterID)) return nil } @@ -1435,9 +1454,12 @@ func (c *eventBroker) addDispatcher(info DispatcherInfo) error { if !success { if !info.IsOnlyReuse() { - log.Error("register dispatcher to eventStore failed", - zap.Stringer("changefeedID", changefeedID), - zap.Stringer("dispatcherID", id), zap.Int64("tableID", span.GetTableID()), + log.Error("add dispatcher failed", + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), + zap.Stringer("dispatcherID", id), + zap.Int64("tableID", span.GetTableID()), + zap.String("tableSpan", common.FormatTableSpan(span)), zap.Uint64("startTs", info.GetStartTs())) } status.removeDispatcher(id) @@ -1457,7 +1479,7 @@ func (c *eventBroker) addDispatcher(info DispatcherInfo) error { log.Error("register table to schemaStore failed", zap.Uint32("keyspaceID", span.KeyspaceID), zap.Stringer("dispatcherID", id), zap.Int64("tableID", span.GetTableID()), - zap.Uint64("startTs", info.GetStartTs()), + zap.Uint64("startTs", info.GetStartTs()), zap.String("tableSpan", common.FormatTableSpan(span)), zap.Error(err), ) // Mark removed to avoid processing notifications before unregister completes. @@ -1473,13 +1495,14 @@ func (c *eventBroker) addDispatcher(info DispatcherInfo) error { c.dispatcherCount.Inc() c.metricsCollector.metricDispatcherCount.Inc() } - log.Info("register dispatcher", - zap.Uint64("clusterID", c.tidbClusterID), - zap.Stringer("changefeedID", changefeedID), + log.Info("add dispatcher done", + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Stringer("dispatcherID", id), - zap.Int64("mode", info.GetMode()), zap.Int64("tableID", span.GetTableID()), zap.Uint64("startTs", info.GetStartTs()), + zap.Uint64("clusterID", c.tidbClusterID), + zap.Int64("mode", info.GetMode()), zap.String("txnAtomocity", string(info.GetTxnAtomicity())), zap.Duration("duration", time.Since(start))) return nil @@ -1503,7 +1526,8 @@ func (c *eventBroker) removeDispatcher(dispatcherInfo DispatcherInfo) { c.removeSchemaBlockedDispatcher(stat) if err := c.cleanupLargeTxnState(stat); err != nil { log.Warn("cleanup large txn state failed when removing dispatcher, scheduled retry", - zap.Stringer("changefeedID", dispatcherInfo.GetChangefeedID()), + zap.String("keyspace", dispatcherInfo.GetChangefeedID().Keyspace()), + zap.String("changefeed", dispatcherInfo.GetChangefeedID().Name()), zap.Stringer("dispatcherID", id), zap.Error(err)) } @@ -1525,7 +1549,8 @@ func (c *eventBroker) removeDispatcher(dispatcherInfo DispatcherInfo) { if stat.changefeedStat.isEmpty() { log.Info("All dispatchers for the changefeed are removed, remove the changefeed status", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), ) c.removeChangefeedStatus(stat.changefeedStat) } @@ -1542,9 +1567,13 @@ func (c *eventBroker) removeDispatcher(dispatcherInfo DispatcherInfo) { _ = c.schemaStore.UnregisterTable(keyspaceMeta, span.TableID) } - log.Info("remove dispatcher", - zap.Uint64("clusterID", c.tidbClusterID), zap.Stringer("changefeedID", changefeedID), - zap.Stringer("dispatcherID", id), zap.Int64("tableID", dispatcherInfo.GetTableSpan().GetTableID()), + log.Info("remove dispatcher done", + zap.Uint64("clusterID", c.tidbClusterID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), + zap.Stringer("dispatcherID", id), + zap.Int64("tableID", dispatcherInfo.GetTableSpan().GetTableID()), + zap.String("tableSpan", common.FormatTableSpan(dispatcherInfo.GetTableSpan())), ) } @@ -1568,7 +1597,8 @@ func (c *eventBroker) resetDispatcher(dispatcherInfo DispatcherInfo) error { if statPtr == nil { // The dispatcher is not registered, ignore it. log.Warn("reset a non-exist dispatcher, ignore it", - zap.Stringer("changefeedID", dispatcherInfo.GetChangefeedID()), + zap.String("keyspace", dispatcherInfo.GetChangefeedID().Keyspace()), + zap.String("changefeed", dispatcherInfo.GetChangefeedID().Name()), zap.Stringer("dispatcherID", dispatcherID), zap.Int64("tableID", dispatcherInfo.GetTableSpan().GetTableID()), zap.Uint64("startTs", dispatcherInfo.GetStartTs())) @@ -1592,7 +1622,8 @@ func (c *eventBroker) resetDispatcher(dispatcherInfo DispatcherInfo) error { c.removeSchemaBlockedDispatcher(oldStat) if err := c.cleanupLargeTxnState(oldStat); err != nil { log.Warn("cleanup large txn state failed when resetting dispatcher, scheduled retry", - zap.Stringer("changefeedID", dispatcherInfo.GetChangefeedID()), + zap.String("keyspace", dispatcherInfo.GetChangefeedID().Keyspace()), + zap.String("changefeed", dispatcherInfo.GetChangefeedID().Name()), zap.Stringer("dispatcherID", dispatcherID), zap.Error(err)) } @@ -1611,7 +1642,8 @@ func (c *eventBroker) resetDispatcher(dispatcherInfo DispatcherInfo) error { tableInfo, err = c.schemaStore.GetTableInfo(c.ctx, keyspaceMeta, span.GetTableID(), dispatcherInfo.GetStartTs()) if err != nil { log.Error("get table info from schemaStore failed", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Stringer("dispatcherID", dispatcherID), zap.Int64("tableID", span.GetTableID()), zap.Uint64("startTs", dispatcherInfo.GetStartTs()), @@ -1628,7 +1660,8 @@ func (c *eventBroker) resetDispatcher(dispatcherInfo DispatcherInfo) error { break } log.Warn("reset dispatcher failed since the dispatcher is changed concurrently", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Stringer("dispatcherID", dispatcherID), zap.Int64("tableID", span.GetTableID()), zap.Uint64("oldStartTs", oldStat.info.GetStartTs()), @@ -1645,15 +1678,19 @@ func (c *eventBroker) resetDispatcher(dispatcherInfo DispatcherInfo) error { c.removeSchemaBlockedDispatcher(oldStat) if err := c.cleanupLargeTxnState(oldStat); err != nil { log.Warn("cleanup large txn state failed when retrying dispatcher reset, scheduled retry", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Stringer("dispatcherID", dispatcherID), zap.Error(err)) } } log.Info("reset dispatcher", - zap.Stringer("changefeedID", newStat.changefeedStat.changefeedID), - zap.Stringer("dispatcherID", newStat.id), zap.Int64("tableID", newStat.info.GetTableSpan().GetTableID()), + zap.String("keyspace", newStat.changefeedStat.changefeedID.Keyspace()), + zap.String("changefeed", newStat.changefeedStat.changefeedID.Name()), + zap.Stringer("dispatcherID", newStat.id), + zap.Int64("tableID", newStat.info.GetTableSpan().GetTableID()), + zap.String("tableSpan", common.FormatTableSpan(newStat.info.GetTableSpan())), zap.Uint64("originStartTs", oldStat.info.GetStartTs()), zap.Uint64("newStartTs", dispatcherInfo.GetStartTs()), zap.Uint64("newEpoch", newStat.epoch), @@ -1740,7 +1777,9 @@ func (c *eventBroker) tryGetOrSetChangefeedStatus(info DispatcherInfo) (*changef default: } } - log.Info("new changefeed status", zap.Stringer("changefeedID", changefeedID)) + log.Info("new changefeed status", + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name())) if status.scanWindowController != nil { initializeScanWindowMetrics(changefeedID.String()) } @@ -1777,7 +1816,8 @@ func (c *eventBroker) handleDispatcherHeartbeat(heartbeat *DispatcherHeartBeatWi dispatcher := dispatcherPtr.Load() if checkEpoch && heartbeatEpoch != dispatcher.epoch { fields := []zap.Field{ - zap.Stringer("changefeedID", dispatcher.changefeedStat.changefeedID), + zap.String("keyspace", dispatcher.changefeedStat.changefeedID.Keyspace()), + zap.String("changefeed", dispatcher.changefeedStat.changefeedID.Name()), zap.Stringer("dispatcherID", dispatcher.id), zap.Uint64("heartbeatEpoch", heartbeatEpoch), zap.Uint64("dispatcherEpoch", dispatcher.epoch), diff --git a/pkg/eventservice/event_broker_failpoint.go b/pkg/eventservice/event_broker_failpoint.go index 30437fd32d..c2bb7dfa01 100644 --- a/pkg/eventservice/event_broker_failpoint.go +++ b/pkg/eventservice/event_broker_failpoint.go @@ -85,7 +85,13 @@ func testShouldDelayCursorRound(task scanTask, specification string) bool { until = firstUntil } if changed { - log.Info("test cursor scheduling delay", zap.Stringer("changefeedID", task.changefeedStat.changefeedID), zap.Stringer("dispatcherID", task.id), zap.Int64("tableID", task.info.GetTableSpan().TableID), zap.Int("cursorRound", count), zap.Int64("untilMillis", until)) + log.Info("test cursor scheduling delay", + zap.String("keyspace", task.changefeedStat.changefeedID.Keyspace()), + zap.String("changefeed", task.changefeedStat.changefeedID.Name()), + zap.Stringer("dispatcherID", task.id), + zap.Int64("tableID", task.info.GetTableSpan().TableID), + zap.Int("cursorRound", count), + zap.Int64("untilMillis", until)) } return time.Now().UnixMilli() < until } diff --git a/pkg/eventservice/event_service.go b/pkg/eventservice/event_service.go index b94820bcc3..7b3d5f28a9 100644 --- a/pkg/eventservice/event_service.go +++ b/pkg/eventservice/event_service.go @@ -321,7 +321,9 @@ func (s *eventService) registerDispatcher(ctx context.Context, info DispatcherIn // FIXME: Send message to the dispatcherManager to handle the error. err := c.addDispatcher(info) if err != nil { - log.Error("add dispatcher to eventBroker failed", zap.Stringer("dispatcherID", info.GetID()), zap.Error(err)) + log.Error("add dispatcher failed", + zap.Stringer("dispatcherID", info.GetID()), + zap.Error(err)) } } diff --git a/pkg/eventservice/metrics_collector.go b/pkg/eventservice/metrics_collector.go index 2c0ea11fed..3d0fb4f53a 100644 --- a/pkg/eventservice/metrics_collector.go +++ b/pkg/eventservice/metrics_collector.go @@ -323,7 +323,8 @@ func (mc *metricsCollector) logSlowDispatchers(snapshot *metricsSnapshot) { } log.Warn("slow dispatcher by checkpointTs", - zap.Stringer("changefeedID", dispatcher.changefeedStat.changefeedID), + zap.String("keyspace", dispatcher.changefeedStat.changefeedID.Keyspace()), + zap.String("changefeed", dispatcher.changefeedStat.changefeedID.Name()), zap.Stringer("dispatcherID", dispatcher.id), zap.Stringer("tableName", dispatcher.startTableInfo.TableName), zap.Int64("tableID", dispatcher.startTableInfo.TableName.TableID), diff --git a/pkg/eventservice/scan_window.go b/pkg/eventservice/scan_window.go index 3cf36f6932..14e7ace20c 100644 --- a/pkg/eventservice/scan_window.go +++ b/pkg/eventservice/scan_window.go @@ -314,7 +314,8 @@ func (c *changefeedStatus) updateMemoryUsage(now time.Time, usageRatio float64, eventServiceScanWindowIntervalGaugeVec.WithLabelValues(c.changefeedID.String()).Set(decision.newInterval.Seconds()) log.Info("scan interval adjusted", - zap.Stringer("changefeedID", c.changefeedID), + zap.String("keyspace", c.changefeedID.Keyspace()), + zap.String("changefeed", c.changefeedID.Name()), zap.String("reason", string(decision.reason)), zap.Duration("oldInterval", current), zap.Duration("newInterval", decision.newInterval), @@ -834,7 +835,10 @@ func (c *changefeedStatus) refreshMinSentResolvedTs() { lastHeartbeatTime := dispatcher.lastReceivedHeartbeatTime.Load() if lastHeartbeatTime > 0 && now.Sub(time.Unix(lastHeartbeatTime, 0)) > scanWindowStaleDispatcherHeartbeatThreshold { - log.Info("dispatcher is stale, skip it's sent resolved ts", zap.Stringer("changefeedID", c.changefeedID), zap.Stringer("dispatcherID", dispatcher.id)) + log.Info("dispatcher is stale, skip it's sent resolved ts", + zap.String("keyspace", c.changefeedID.Keyspace()), + zap.String("changefeed", c.changefeedID.Name()), + zap.Stringer("dispatcherID", dispatcher.id)) return true } diff --git a/pkg/pdutil/api_client.go b/pkg/pdutil/api_client.go index 65eb8af1a7..75fcd625c6 100644 --- a/pkg/pdutil/api_client.go +++ b/pkg/pdutil/api_client.go @@ -280,18 +280,19 @@ func (pc *pdAPIClient) scanRegions( return nil, errors.ErrInternalServerError.GenWithStack("fail to scan region, missing region") } if r[0].StartKey != startKeyHex { + originalStartKey := r[0].StartKey r[0].StartKey = strings.ToUpper(hex.EncodeToString(startKey)) log.Info("start key mismatch, adjust start key", - zap.String("startKey", util.RedactValue(startKeyHex)), - zap.String("regionStartKey", util.RedactValue(r[0].StartKey)), - zap.Uint64("regionID", r[0].ID)) + zap.Uint64("regionID", r[0].ID), + zap.String("startKey", util.RedactKey(startKey)), + zap.String("regionStartKey", redactHexKey(originalStartKey))) } regions = append(regions, r...) key, err := hex.DecodeString(regions[len(regions)-1].EndKey) if err != nil { log.Info("fail to decode region end key", - zap.String("endKey", util.RedactValue(regions[len(regions)-1].EndKey)), - zap.Uint64("regionID", r[len(regions)-1].ID)) + zap.Uint64("regionID", r[len(regions)-1].ID), + zap.String("endKey", util.RedactValue(regions[len(regions)-1].EndKey))) return nil, errors.Trace(err) } startKey = key @@ -301,16 +302,26 @@ func (pc *pdAPIClient) scanRegions( } } if regions[len(regions)-1].EndKey != string(span.EndKey) { + originalEndKey := regions[len(regions)-1].EndKey regions[len(regions)-1].EndKey = strings.ToUpper(hex.EncodeToString(span.EndKey)) log.Info("end key mismatch, adjust end key", + zap.Uint64("regionID", regions[len(regions)-1].ID), zap.String("endKey", util.RedactKey(span.EndKey)), - zap.String("regionEndKey", util.RedactValue(regions[len(regions)-1].EndKey)), - zap.Uint64("regionID", regions[len(regions)-1].ID)) + zap.String("regionEndKey", redactHexKey(originalEndKey))) } return regions, nil } +// redactHexKey redacts a hex encoded key for logging. +func redactHexKey(hexKey string) string { + key, err := hex.DecodeString(hexKey) + if err != nil { + return util.RedactValue(hexKey) + } + return util.RedactKey(key) +} + func (pc *pdAPIClient) LoadKeyspace(ctx context.Context, name string) (*keyspacepb.KeyspaceMeta, error) { if kerneltype.IsClassic() { return &keyspacepb.KeyspaceMeta{}, nil diff --git a/pkg/redo/reader/reader.go b/pkg/redo/reader/reader.go index 5a2a918380..0e67bec50a 100644 --- a/pkg/redo/reader/reader.go +++ b/pkg/redo/reader/reader.go @@ -312,8 +312,8 @@ func (l *LogReader) initMeta(ctx context.Context) error { misc.ParseMeta(metas, &checkpointTs, &resolvedTs) if resolvedTs < checkpointTs { log.Panic("in all meta files, resolvedTs is less than checkpointTs", - zap.Uint64("resolvedTs", resolvedTs), - zap.Uint64("checkpointTs", checkpointTs)) + zap.Uint64("checkpointTs", checkpointTs), + zap.Uint64("resolvedTs", resolvedTs)) } l.meta = &misc.LogMeta{CheckpointTs: checkpointTs, ResolvedTs: resolvedTs, Version: metas[0].Version} return nil diff --git a/pkg/routing/admin.go b/pkg/routing/admin.go index c3c4043ce1..31f86b826f 100644 --- a/pkg/routing/admin.go +++ b/pkg/routing/admin.go @@ -184,6 +184,7 @@ func (a *Admin) Apply(commitTs uint64, admissions []Admission) bool { } if len(a.pendingQueue) == 0 || a.pendingQueue[0] != commitTs { log.Panic("route pending queue head mismatch", + zap.String("keyspace", a.changefeedID.Keyspace()), zap.String("changefeed", a.changefeedID.Name()), zap.Uint64("expected", commitTs), zap.Any("actual", a.pendingQueue)) diff --git a/pkg/sink/codec/bootstraper.go b/pkg/sink/codec/bootstraper.go index 976b795d0b..45b88814c9 100644 --- a/pkg/sink/codec/bootstraper.go +++ b/pkg/sink/codec/bootstraper.go @@ -60,7 +60,8 @@ func newBootstrapWorker( ) *bootstrapWorker { log.Info("Sending bootstrap event is enabled for simple protocol. "+ "Both send-bootstrap-interval-in-sec and send-bootstrap-in-msg-count are > 0.", - zap.Stringer("changefeed", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Int64("sendBootstrapIntervalInSec", sendBootstrapInterval), zap.Int32("sendBootstrapInMsgCount", sendBootstrapInMsgCount)) return &bootstrapWorker{ @@ -193,9 +194,10 @@ func (b *bootstrapWorker) gcInactiveTables() { table := value.(*tableStatistic) if table.isInactive(b.maxInactiveDuration) { log.Info("A table is removed from the bootstrap worker", + zap.String("keyspace", b.changefeedID.Keyspace()), + zap.String("changefeed", b.changefeedID.Name()), zap.Int64("tableID", table.id), - zap.String("topic", table.topic), - zap.Stringer("changefeed", b.changefeedID)) + zap.String("topic", table.topic)) b.activeTables.Delete(key) } return true diff --git a/pkg/sink/codec/schemamanager/confluent_schema_registry.go b/pkg/sink/codec/schemamanager/confluent_schema_registry.go index d45e14e9a5..1c1c5836cf 100644 --- a/pkg/sink/codec/schemamanager/confluent_schema_registry.go +++ b/pkg/sink/codec/schemamanager/confluent_schema_registry.go @@ -160,7 +160,6 @@ func (m *confluentSchemaManager) Register( schemaDefinition string, ) (SchemaID, error) { id := SchemaID{} - reqBody := registerRequest{ Schema: schemaDefinition, } @@ -170,7 +169,6 @@ func (m *confluentSchemaManager) Register( return id, errors.WrapError(errors.ErrAvroSchemaAPIError, err) } uri := m.registryURL + "/subjects/" + url.QueryEscape(schemaName) + "/versions" - req, err := http.NewRequestWithContext(ctx, "POST", uri, bytes.NewReader(payload)) if err != nil { err = util.MaskSensitiveDataInURLError(err) @@ -199,10 +197,22 @@ func (m *confluentSchemaManager) Register( // https://docs.confluent.io/platform/current/schema-registry/develop/api.html \ // #post--subjects-(string-%20subject)-versions // 409 for incompatible schema - log.Error( - "Failed to register schema to the Registry, HTTP error", + fields := []zap.Field{ + zap.String("schemaName", schemaName), zap.Int("status", resp.StatusCode), - ) + } + var registryErr struct { + ErrorCode int `json:"error_code"` + Message string `json:"message"` + } + if err := json.Unmarshal(body, ®istryErr); err == nil && registryErr.Message != "" { + fields = append(fields, + zap.Int("errorCode", registryErr.ErrorCode), + zap.String("message", registryErr.Message)) + } else { + fields = append(fields, zap.Int("responseLength", len(body))) + } + log.Error("Failed to register schema to the Registry, HTTP error", fields...) return id, errors.ErrAvroSchemaAPIError.GenWithStackByArgs( "register schema failed with status " + strconv.Itoa(resp.StatusCode), ) diff --git a/pkg/sink/kafka/franz_sync_producer.go b/pkg/sink/kafka/franz_sync_producer.go index 5626b931f4..e01184e34c 100644 --- a/pkg/sink/kafka/franz_sync_producer.go +++ b/pkg/sink/kafka/franz_sync_producer.go @@ -67,7 +67,8 @@ func (p *syncProducer) sendRecords(ctx context.Context, message *codecCommon.Mes } log.Error("kafka message send failed", - zap.String("keyspace", p.id.Keyspace()), zap.String("changefeed", p.id.Name()), + zap.String("keyspace", p.id.Keyspace()), + zap.String("changefeed", p.id.Name()), zap.String("eventContext", BuildEventLogContext(message.LogInfo)), zap.Error(err)) return errors.WrapError(errors.ErrKafkaSendMessage, err) @@ -76,10 +77,12 @@ func (p *syncProducer) sendRecords(ctx context.Context, message *codecCommon.Mes func (p *syncProducer) Close() { if !p.closed.CompareAndSwap(false, true) { log.Warn("kafka ddl producer already closed", - zap.String("keyspace", p.id.Keyspace()), zap.String("changefeed", p.id.Name())) + zap.String("keyspace", p.id.Keyspace()), + zap.String("changefeed", p.id.Name())) return } log.Info("kafka ddl producer closed", - zap.String("keyspace", p.id.Keyspace()), zap.String("changefeed", p.id.Name())) + zap.String("keyspace", p.id.Keyspace()), + zap.String("changefeed", p.id.Name())) } diff --git a/pkg/sink/kafka/options.go b/pkg/sink/kafka/options.go index b124b8ec5e..652e5f96ee 100644 --- a/pkg/sink/kafka/options.go +++ b/pkg/sink/kafka/options.go @@ -229,7 +229,8 @@ func (o *options) setPartitionNum(changefeedID common.ChangeFeedID, realPartitio if o.PartitionNum < realPartitionCount { log.Warn("configured kafka partition count is lower than topic partition count", - zap.String("namespace", changefeedID.Keyspace()), zap.String("changefeed", changefeedID.Name()), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Int32("configuredPartitionNum", o.PartitionNum), zap.Int32("topicPartitionNum", realPartitionCount)) return nil @@ -750,8 +751,10 @@ func adjustExistingTopicOption(ctx context.Context, changefeedID common.ChangeFe maxMessageBytes, found, err := getTopicMaxMessageBytes(ctx, admin, info.Name) if err != nil || !found { log.Warn("kafka topic `max.message.bytes` unavailable, using configured value", - zap.String("namespace", changefeedID.Keyspace()), zap.String("changefeed", changefeedID.Name()), - zap.Int("maxMessageBytes", options.MaxMessageBytes), zap.Error(err)) + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), + zap.Int("maxMessageBytes", options.MaxMessageBytes), + zap.Error(err)) maxMessageBytes = options.MaxMessageBytes } options.MaxMessageBytes = maxMessageBytes @@ -765,8 +768,10 @@ func adjustNewTopicOptions(ctx context.Context, admin AdminClient, changefeedID messageMaxBytes, found, err := getBrokerMaxMessageBytes(ctx, admin) if err != nil || !found { log.Warn("kafka broker `message.max.bytes` unavailable, using configured value", - zap.String("namespace", changefeedID.Keyspace()), zap.String("changefeed", changefeedID.Name()), - zap.Int("maxMessageBytes", options.MaxMessageBytes), zap.Error(err)) + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), + zap.Int("maxMessageBytes", options.MaxMessageBytes), + zap.Error(err)) messageMaxBytes = options.MaxMessageBytes } options.MaxMessageBytes = messageMaxBytes diff --git a/pkg/sink/kafka/sarama_factory.go b/pkg/sink/kafka/sarama_factory.go index 8d5a8c3f6d..a09daba0cc 100644 --- a/pkg/sink/kafka/sarama_factory.go +++ b/pkg/sink/kafka/sarama_factory.go @@ -63,8 +63,9 @@ func newSaramaFactory(ctx context.Context, o *options, changefeedID common.Chang return nil, err } log.Info("kafka sink configuration resolved", - zap.String("namespace", changefeedID.Keyspace()), + zap.String("keyspace", changefeedID.Keyspace()), zap.String("changefeed", changefeedID.Name()), + zap.String("namespace", changefeedID.Keyspace()), zap.String("topic", o.Topic), zap.Int32("partitionNum", o.PartitionNum), zap.Int("maxMessageBytes", o.MaxMessageBytes), diff --git a/pkg/sink/mysql/mysql_writer_ddl.go b/pkg/sink/mysql/mysql_writer_ddl.go index bddb9a1ce7..125a5fdb7c 100644 --- a/pkg/sink/mysql/mysql_writer_ddl.go +++ b/pkg/sink/mysql/mysql_writer_ddl.go @@ -27,6 +27,7 @@ import ( commonEvent "github.com/pingcap/ticdc/pkg/common/event" "github.com/pingcap/ticdc/pkg/errors" "github.com/pingcap/ticdc/pkg/retry" + "github.com/pingcap/ticdc/pkg/util" "github.com/pingcap/tidb/dumpling/export" timodel "github.com/pingcap/tidb/pkg/meta/model" "go.uber.org/zap" @@ -39,7 +40,7 @@ func (w *Writer) execDDL(event *commonEvent.DDLEvent) error { log.Info("dry run DDL", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("ddlQuery", event.GetDDLQuery())) + zap.String("ddlQuery", util.RedactValue(event.GetDDLQuery()))) time.Sleep(w.cfg.DryRunDelay) return nil } @@ -59,7 +60,7 @@ func (w *Writer) execDDL(event *commonEvent.DDLEvent) error { zap.Int64("tableID", tableID), zap.Uint64("startTs", event.GetStartTs()), zap.Uint64("commitTs", ddlTs), - zap.String("ddlQuery", event.GetDDLQuery())) + zap.String("ddlQuery", util.RedactValue(event.GetDDLQuery()))) return nil } } @@ -80,14 +81,14 @@ func (w *Writer) execDDL(event *commonEvent.DDLEvent) error { log.Warn("restore anonymous index name failed", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("ddlQuery", event.Query), + zap.String("ddlQuery", util.RedactValue(event.Query)), zap.Error(err)) } else if changed { log.Info("restore anonymous index to named index", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("ddlQuery", event.Query), - zap.String("newQuery", newQuery)) + zap.String("ddlQuery", util.RedactValue(event.Query)), + zap.String("newQuery", util.RedactValue(newQuery))) event.Query = newQuery } } @@ -101,8 +102,8 @@ func (w *Writer) execDDL(event *commonEvent.DDLEvent) error { log.Info("format DDL query", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("newQuery", newQuery), - zap.String("ddlQuery", event.Query)) + zap.String("newQuery", util.RedactValue(newQuery)), + zap.String("ddlQuery", util.RedactValue(event.Query))) event.Query = newQuery } } @@ -152,7 +153,7 @@ func (w *Writer) execDDL(event *commonEvent.DDLEvent) error { log.Error("rollback DDL txn failed", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("ddlQuery", query), + zap.String("ddlQuery", util.RedactValue(query)), zap.Error(rbErr)) } return err @@ -164,13 +165,13 @@ func (w *Writer) execDDL(event *commonEvent.DDLEvent) error { log.Error("reset session timestamp failed before DDL execution", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("ddlQuery", query), + zap.String("ddlQuery", util.RedactValue(query)), zap.Error(err)) if rbErr := tx.Rollback(); rbErr != nil { log.Error("rollback DDL txn failed", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("ddlQuery", query), + zap.String("ddlQuery", util.RedactValue(query)), zap.Error(rbErr)) } return err @@ -190,7 +191,7 @@ func (w *Writer) execDDL(event *commonEvent.DDLEvent) error { log.Warn("skip setting session timestamp due to failpoint", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("ddlQuery", query)) + zap.String("ddlQuery", util.RedactValue(query))) } if useSessionTimestamp && !skipSetTimestamp { // set the session timestamp to match upstream DDL execution time @@ -199,13 +200,13 @@ func (w *Writer) execDDL(event *commonEvent.DDLEvent) error { zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), zap.Float64("timestamp", ddlTimestamp), - zap.String("ddlQuery", query), + zap.String("ddlQuery", util.RedactValue(query)), zap.Error(err)) if rbErr := tx.Rollback(); rbErr != nil { log.Error("rollback DDL txn failed", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("ddlQuery", query), + zap.String("ddlQuery", util.RedactValue(query)), zap.Error(rbErr)) } return err @@ -219,12 +220,12 @@ func (w *Writer) execDDL(event *commonEvent.DDLEvent) error { log.Warn("skip resetting session timestamp after DDL execution failure due to failpoint", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("ddlQuery", query)) + zap.String("ddlQuery", util.RedactValue(query))) } else if tsErr := resetSessionTimestamp(ctx, tx); tsErr != nil { log.Warn("reset session timestamp failed after DDL execution failure", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("ddlQuery", query), + zap.String("ddlQuery", util.RedactValue(query)), zap.Error(tsErr)) } } @@ -232,7 +233,7 @@ func (w *Writer) execDDL(event *commonEvent.DDLEvent) error { log.Error("rollback DDL txn failed", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("ddlQuery", query), + zap.String("ddlQuery", util.RedactValue(query)), zap.Error(rbErr)) } return err @@ -244,18 +245,18 @@ func (w *Writer) execDDL(event *commonEvent.DDLEvent) error { log.Warn("skip resetting session timestamp after DDL execution due to failpoint", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("ddlQuery", query)) + zap.String("ddlQuery", util.RedactValue(query))) } else if err := resetSessionTimestamp(ctx, tx); err != nil { log.Error("reset session timestamp failed after DDL execution", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("ddlQuery", query), + zap.String("ddlQuery", util.RedactValue(query)), zap.Error(err)) if rbErr := tx.Rollback(); rbErr != nil { log.Error("rollback DDL txn failed", zap.String("keyspace", w.ChangefeedID.Keyspace()), zap.String("changefeedID", w.ChangefeedID.Name()), - zap.String("ddlQuery", query), + zap.String("ddlQuery", util.RedactValue(query)), zap.Error(rbErr)) } return errors.WrapError(errors.ErrMySQLTxnError, err) @@ -272,7 +273,7 @@ func (w *Writer) execDDL(event *commonEvent.DDLEvent) error { zap.Int64("tableID", event.GetTableID()), zap.Uint64("startTs", event.GetStartTs()), zap.Uint64("commitTs", event.GetCommitTs()), - zap.String("ddlQuery", query), + zap.String("ddlQuery", util.RedactValue(query)), } if useSessionTimestamp { @@ -310,7 +311,7 @@ func (w *Writer) execDDLWithMaxRetries(event *commonEvent.DDLEvent) error { zap.String("changefeedID", w.ChangefeedID.Name()), zap.Int64("tableID", event.GetTableID()), zap.Uint64("commitTs", event.GetCommitTs()), - zap.String("ddlQuery", event.GetDDLQuery()), + zap.String("ddlQuery", util.RedactValue(event.GetDDLQuery())), zap.Error(err)) } } @@ -326,7 +327,7 @@ func (w *Writer) execDDLWithMaxRetries(event *commonEvent.DDLEvent) error { zap.Int64("tableID", event.GetTableID()), zap.Uint64("startTs", event.GetStartTs()), zap.Uint64("commitTs", event.GetCommitTs()), - zap.String("ddlQuery", event.Query), + zap.String("ddlQuery", util.RedactValue(event.Query)), zap.Error(err)) // If the error is ignorable, we will ignore the error directly. return nil @@ -338,7 +339,7 @@ func (w *Writer) execDDLWithMaxRetries(event *commonEvent.DDLEvent) error { zap.Int64("tableID", event.GetTableID()), zap.Uint64("startTs", event.GetStartTs()), zap.Uint64("commitTs", event.GetCommitTs()), - zap.String("ddlQuery", event.Query), + zap.String("ddlQuery", util.RedactValue(event.Query)), zap.String("ddlCreateTime", ddlCreateTime), zap.String("readTimeout", w.getDDLReadTimeout(event)), zap.Error(err)) @@ -352,7 +353,7 @@ func (w *Writer) execDDLWithMaxRetries(event *commonEvent.DDLEvent) error { zap.Int64("tableID", event.GetTableID()), zap.Uint64("startTs", event.GetStartTs()), zap.Uint64("commitTs", event.GetCommitTs()), - zap.String("ddlQuery", event.Query), + zap.String("ddlQuery", util.RedactValue(event.Query)), zap.String("ddlCreateTime", ddlCreateTime), zap.Error(err)) } else { @@ -362,7 +363,7 @@ func (w *Writer) execDDLWithMaxRetries(event *commonEvent.DDLEvent) error { zap.Int64("tableID", event.GetTableID()), zap.Uint64("startTs", event.GetStartTs()), zap.Uint64("commitTs", event.GetCommitTs()), - zap.String("ddlQuery", event.Query), + zap.String("ddlQuery", util.RedactValue(event.Query)), zap.String("ddlCreateTime", ddlCreateTime), zap.Error(err)) } @@ -425,7 +426,7 @@ func (w *Writer) waitDDLDone(ctx context.Context, ddl *commonEvent.DDLEvent, ddl zap.Int64("tableID", ddl.GetTableID()), zap.Uint64("startTs", ddl.GetStartTs()), zap.Uint64("commitTs", ddl.GetCommitTs()), - zap.String("ddlQuery", query), + zap.String("ddlQuery", util.RedactValue(query)), zap.String("ddlCreateTime", ddlCreateTime)) } @@ -444,7 +445,7 @@ func (w *Writer) waitDDLDone(ctx context.Context, ddl *commonEvent.DDLEvent, ddl zap.Int64("tableID", ddl.GetTableID()), zap.Uint64("startTs", ddl.GetStartTs()), zap.Uint64("commitTs", ddl.GetCommitTs()), - zap.String("ddlQuery", query), + zap.String("ddlQuery", util.RedactValue(query)), zap.String("ddlCreateTime", ddlCreateTime)) return nil case timodel.JobStateCancelled, timodel.JobStateRollingback, timodel.JobStateRollbackDone, timodel.JobStateCancelling: @@ -459,7 +460,7 @@ func (w *Writer) waitDDLDone(ctx context.Context, ddl *commonEvent.DDLEvent, ddl zap.Int64("tableID", ddl.GetTableID()), zap.Uint64("startTs", ddl.GetStartTs()), zap.Uint64("commitTs", ddl.GetCommitTs()), - zap.String("ddlQuery", query), + zap.String("ddlQuery", util.RedactValue(query)), zap.String("ddlCreateTime", ddlCreateTime), zap.Any("ddlState", state)) return nil @@ -488,7 +489,7 @@ func (w *Writer) waitAsyncDDLDone(event *commonEvent.DDLEvent) { zap.String("changefeedID", w.ChangefeedID.Name()), zap.String("schemaName", blockedTable.SchemaName), zap.String("tableName", blockedTable.TableName), - zap.String("ddlQuery", event.GetDDLQuery()), + zap.String("ddlQuery", util.RedactValue(event.GetDDLQuery())), zap.Error(err)) } } @@ -520,7 +521,7 @@ func (w *Writer) doQueryAsyncDDL(query, schemaName, tableName string, shouldLog zap.String("jobType", jobType), zap.String("schemaState", schemaState), zap.String("state", state), - zap.String("ddlQuery", runningDDL)) + zap.String("ddlQuery", util.RedactValue(runningDDL))) } return true, nil diff --git a/pkg/sink/mysql/mysql_writer_dml_exec.go b/pkg/sink/mysql/mysql_writer_dml_exec.go index f38c7b3ce0..3e22346c93 100644 --- a/pkg/sink/mysql/mysql_writer_dml_exec.go +++ b/pkg/sink/mysql/mysql_writer_dml_exec.go @@ -284,7 +284,7 @@ func (w *Writer) logDMLTxnErr( zap.Int("count", dmls.rowCount), zap.String("dmls", dmlSummary), zap.Int("writerID", w.id), - zap.Error(err)) + zap.Error(util.RedactError(err))) } else { if !w.checkIsDuplicateEntryError(err) { log.Error("execute DMLs with error, can not retry", @@ -295,7 +295,7 @@ func (w *Writer) logDMLTxnErr( zap.Int("count", dmls.rowCount), zap.String("dmls", dmls.String()), zap.Int("writerID", w.id), - zap.Error(err)) + zap.Error(util.RedactError(err))) } } return err diff --git a/pkg/sink/mysql/sql_builder.go b/pkg/sink/mysql/sql_builder.go index f6d287faf1..1de30f57f0 100644 --- a/pkg/sink/mysql/sql_builder.go +++ b/pkg/sink/mysql/sql_builder.go @@ -220,7 +220,7 @@ func buildActiveActiveUpsertSQL( } if len(commitTs) != len(rows) { log.Panic("mismatched commitTs and rows length", - zap.Int("rows", len(rows)), zap.Int("commitTs", len(commitTs))) + zap.Int("commitTs", len(commitTs)), zap.Int("rows", len(rows))) } columns := tableInfo.GetColumns() diff --git a/pkg/sink/pulsar/factory.go b/pkg/sink/pulsar/factory.go index 577aa593f6..f039831d93 100644 --- a/pkg/sink/pulsar/factory.go +++ b/pkg/sink/pulsar/factory.go @@ -50,7 +50,8 @@ func NewCreatorFactory(config *config.PulsarConfig, changefeedID commonType.Chan Logger: NewPulsarLogger(log.L()), } log.Info("pulsar client factory created", - zap.Stringer("changefeedID", changefeedID), + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name()), zap.Any("clientOptions", option)) var err error @@ -139,6 +140,8 @@ func SetupAuthentication(config *config.PulsarConfig) (bool, pulsar.Authenticati func NewMockCreatorFactory(config *config.PulsarConfig, changefeedID commonType.ChangeFeedID, sinkConfig *config.SinkConfig, ) (pulsar.Client, error) { - log.Info("mock pulsar client factory created", zap.Any("changefeedID", changefeedID)) + log.Info("mock pulsar client factory created", + zap.String("keyspace", changefeedID.Keyspace()), + zap.String("changefeed", changefeedID.Name())) return nil, nil } diff --git a/pkg/sink/pulsar/logger_test.go b/pkg/sink/pulsar/logger_test.go deleted file mode 100644 index 952b6f4e3d..0000000000 --- a/pkg/sink/pulsar/logger_test.go +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2024 PingCAP, Inc. -// -// 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, -// See the License for the specific language governing permissions and -// limitations under the License. - -package pulsar - -import ( - "errors" - "runtime" - "testing" - - "github.com/apache/pulsar-client-go/pulsar/log" - "github.com/stretchr/testify/assert" - "go.uber.org/zap" - "go.uber.org/zap/zapcore" - "go.uber.org/zap/zaptest/observer" -) - -// TestPulsarLog ensures Pulsar's use of our logger behaves as expected of a typical zap logger: -// 1. all fields injected via .With*() are present in the final log -// 2. the [file:line] points to the actual call site rather than `logger.go`. -func TestPulsarLog(t *testing.T) { - core, observedLogs := observer.New(zapcore.DebugLevel) - logger := NewPulsarLogger(zap.New(core).WithOptions(zap.AddCaller())) - - pc, file, line, ok := runtime.Caller(0) - assert.True(t, ok) - functionName := runtime.FuncForPC(pc).Name() - - logger.Infof("1 + 2 = %d", 1+2) - logger.WithError(errors.ErrUnsupported).Warn("3", "+", "4", "=", 3+4) - logger.WithFields(log.Fields{"x": 1234, "y": 9.75}).Info("connected") - - allEntries := observedLogs.AllUntimed() - // we can't reliably test the `pc` address of the caller information. remove them. - for i := range allEntries { - allEntries[i].Caller.PC = 0 - } - - assert.Len(t, allEntries, 3) - assert.Equal(t, allEntries[0:2], []observer.LoggedEntry{ - { - Entry: zapcore.Entry{ - Level: zapcore.InfoLevel, - Message: "1 + 2 = 3", - Caller: zapcore.EntryCaller{ - Defined: true, - File: file, - Line: line + 4, - Function: functionName, - }, - }, - Context: []zap.Field{}, - }, - { - Entry: zapcore.Entry{ - Level: zapcore.WarnLevel, - Message: "3+4=7", - Caller: zapcore.EntryCaller{ - Defined: true, - File: file, - Line: line + 5, - Function: functionName, - }, - }, - Context: []zap.Field{zap.Error(errors.ErrUnsupported)}, - }, - }) - assert.Equal(t, allEntries[2].Entry, zapcore.Entry{ - Level: zapcore.InfoLevel, - Message: "connected", - Caller: zapcore.EntryCaller{ - Defined: true, - File: file, - Line: line + 6, - Function: functionName, - }, - }) - assert.ElementsMatch(t, allEntries[2].Context, []zap.Field{ - zap.Int("x", 1234), - zap.Float64("y", 9.75), - }) -} diff --git a/pkg/sink/spool/spool.go b/pkg/sink/spool/spool.go index c79f6766b6..39565647ec 100644 --- a/pkg/sink/spool/spool.go +++ b/pkg/sink/spool/spool.go @@ -758,8 +758,10 @@ func (s *Spool) Close() { if seg.file != nil { if err := seg.file.Close(); err != nil { log.Warn("close spool segment failed", - zap.String("keyspace", s.keyspace), zap.String("changefeed", s.changefeed), - zap.String("path", seg.path), zap.Error(err)) + zap.String("keyspace", s.keyspace), + zap.String("changefeed", s.changefeed), + zap.String("path", seg.path), + zap.Error(err)) } } } @@ -767,8 +769,10 @@ func (s *Spool) Close() { if err := os.RemoveAll(s.workDir); err != nil { log.Warn("remove spool files failed", - zap.String("keyspace", s.keyspace), zap.String("changefeed", s.changefeed), - zap.String("path", s.workDir), zap.Error(err)) + zap.String("keyspace", s.keyspace), + zap.String("changefeed", s.changefeed), + zap.String("path", s.workDir), + zap.Error(err)) } s.quota.deleteMetrics() } @@ -872,10 +876,11 @@ func (s *Spool) truncateSegmentLocked(seg *segment) (int64, bool) { } releasedBytes := seg.size if err := s.truncateFile(seg.file, 0); err != nil { - log.Warn( - "truncate active spool segment file failed", - zap.String("keyspace", s.keyspace), zap.String("changefeed", s.changefeed), - zap.String("path", seg.path), zap.Error(err), + log.Warn("truncate active spool segment file failed", + zap.String("keyspace", s.keyspace), + zap.String("changefeed", s.changefeed), + zap.String("path", seg.path), + zap.Error(err), ) return 0, false } @@ -890,16 +895,18 @@ func (s *Spool) removeSegmentLocked(seg *segment) bool { if seg.file != nil { if err := seg.file.Close(); err != nil { log.Warn("close spool segment file failed", - zap.String("keyspace", s.keyspace), zap.String("changefeed", s.changefeed), + zap.String("keyspace", s.keyspace), + zap.String("changefeed", s.changefeed), zap.Error(err)) } seg.file = nil } if err := s.removeFile(seg.path); err != nil && !os.IsNotExist(err) { - log.Warn( - "remove spool segment file failed", - zap.String("keyspace", s.keyspace), zap.String("changefeed", s.changefeed), - zap.String("path", seg.path), zap.Error(err)) + log.Warn("remove spool segment file failed", + zap.String("keyspace", s.keyspace), + zap.String("changefeed", s.changefeed), + zap.String("path", seg.path), + zap.Error(err)) return false } delete(s.segments, seg.id) diff --git a/pkg/txnutil/gc/gc_manager.go b/pkg/txnutil/gc/gc_manager.go index bcda96d632..9102245774 100644 --- a/pkg/txnutil/gc/gc_manager.go +++ b/pkg/txnutil/gc/gc_manager.go @@ -88,8 +88,8 @@ func (m *gcManager) TryUpdateServiceGCSafepoint( }) log.Debug("update gc safe point", - zap.String("gcServiceID", m.gcServiceID), zap.Uint64("checkpointTs", checkpointTs), + zap.String("gcServiceID", m.gcServiceID), zap.Uint64("minServiceGCSafepoint", minServiceGCSafepoint)) if minServiceGCSafepoint == checkpointTs { @@ -98,7 +98,7 @@ func (m *gcManager) TryUpdateServiceGCSafepoint( if checkpointTs < minServiceGCSafepoint { log.Warn("checkpointTs is smaller than the minimum service gc safepoint", - zap.Uint64("minServiceGCSafepoint", minServiceGCSafepoint), zap.Uint64("checkpointTs", checkpointTs), + zap.Uint64("checkpointTs", checkpointTs), zap.Uint64("minServiceGCSafepoint", minServiceGCSafepoint), zap.String("serviceID", m.gcServiceID)) } diff --git a/pkg/util/redact.go b/pkg/util/redact.go index 4f94259e04..c8dace8fde 100644 --- a/pkg/util/redact.go +++ b/pkg/util/redact.go @@ -135,6 +135,37 @@ func RedactKey(key []byte) string { } } +// FormatKeyRange formats a raw key range for logging. It is the single entry +// point for printing raw key ranges, so redaction applies consistently. +func FormatKeyRange(startKey, endKey []byte) string { + return fmt.Sprintf("[%s, %s)", RedactKey(startKey), RedactKey(endKey)) +} + +// RedactError returns an error suitable for logging. Pass it to zap.Error only; +// control flow must keep using the original error. The SQL error code prefix, if +// any, is kept so the failure stays identifiable. +func RedactError(err error) error { + if err == nil { + return nil + } + mode := perrors.RedactLogEnabled.Load() + if mode == perrors.RedactLogDisable { + return err + } + msg := err.Error() + prefix := "" + if strings.HasPrefix(msg, "Error ") { + if idx := strings.Index(msg, ": "); idx > 0 { + prefix = msg[:idx+2] + msg = msg[idx+2:] + } + } + if mode == perrors.RedactLogMarker { + return fmt.Errorf("%s‹%s›", prefix, msg) + } + return fmt.Errorf("%s?", prefix) +} + // RedactBytes redacts a byte slice (like Kafka message content) using the current redaction mode. // Returns "?" for ON mode, string value wrapped with ‹› for MARKER mode, string for OFF. // In MARKER mode, embedded markers are escaped using TiDB's redact.String(). diff --git a/tests/integration_tests/bank/case.go b/tests/integration_tests/bank/case.go index 81ca200755..ea79c2c5fb 100644 --- a/tests/integration_tests/bank/case.go +++ b/tests/integration_tests/bank/case.go @@ -667,9 +667,9 @@ func tryGetEndTsFromLog(db *sql.DB, tableName string) (result uint64, ok bool) { } log.Info("total files", zap.Any("file", cdcLogFiles)) - logRegex := regexp.MustCompile(`handle a ddl job`) + logRegex := regexp.MustCompile(`ddl job applied`) tableNameRegex := regexp.MustCompile(tableName + "`") - timeStampRegex := regexp.MustCompile(`jobFinishTs=([0-9]+)`) + timeStampRegex := regexp.MustCompile(`commitTs=([0-9]+)`) for _, f := range cdcLogFiles { file, err := os.Open(f) if err != nil {