Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

engine: unit status use cached source status #7618

Merged
merged 5 commits into from
Nov 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions engine/executor/dm/unitholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ func (u *unitHolderImpl) Stage() (metadata.TaskStage, *pb.ProcessResult) {
// Status implement UnitHolder.Status. Each invocation will try to query upstream
// once and calculate the status.
func (u *unitHolderImpl) Status(ctx context.Context) interface{} {
// nil sourceStatus is supported
return u.unit.Status(u.getSourceStatus())
}

func (u *unitHolderImpl) updateSourceStatus(ctx context.Context) interface{} {
sourceStatus, err := binlog.GetSourceStatus(
tcontext.NewContext(ctx, u.logger),
u.upstreamDB,
Expand All @@ -243,22 +248,28 @@ func (u *unitHolderImpl) Status(ctx context.Context) interface{} {
if err != nil {
u.logger.Warn("failed to get source status", zap.Error(err))
}
u.sourceStatusMu.Lock()
u.sourceStatus = sourceStatus
u.sourceStatusMu.Unlock()

// nil sourceStatus is supported
u.setSourceStatus(sourceStatus)
return u.unit.Status(sourceStatus)
}

func (u *unitHolderImpl) getSourceStatus() *binlog.SourceStatus {
u.sourceStatusMu.RLock()
defer u.sourceStatusMu.RUnlock()
return u.sourceStatus
}

func (u *unitHolderImpl) setSourceStatus(in *binlog.SourceStatus) {
u.sourceStatusMu.Lock()
defer u.sourceStatusMu.Unlock()
u.sourceStatus = in
}

// CheckAndUpdateStatus implement UnitHolder.CheckAndUpdateStatus.
func (u *unitHolderImpl) CheckAndUpdateStatus(ctx context.Context) {
u.sourceStatusMu.RLock()
sourceStatus := u.sourceStatus
u.sourceStatusMu.RUnlock()
sourceStatus := u.getSourceStatus()

if sourceStatus == nil || time.Since(sourceStatus.UpdateTime) > sourceStatusRefreshInterval {
u.Status(ctx)
u.updateSourceStatus(ctx)
Copy link
Contributor

@lance6716 lance6716 Nov 15, 2022

Choose a reason for hiding this comment

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

Still need to call u.unit.Status here, because the metrics related variables are updated in u.unit.Status

Copy link
Contributor Author

@D3Hunter D3Hunter Nov 15, 2022

Choose a reason for hiding this comment

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

which variables?

Copy link
Contributor

Choose a reason for hiding this comment

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

for example

			s.metricsProxies.Metrics.RemainingTimeGauge.Set(float64(remainingSeconds))

this line is contained in (*Syncer).printStatus <- (*Syncer).Status

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed here c55d42d

bad idea to have a status getter to have such side effects.

}
}

Expand Down