Skip to content

Commit

Permalink
try to fix blocking test TestAddIndexDistPauseAndResume
Browse files Browse the repository at this point in the history
  • Loading branch information
tangenta committed Dec 20, 2023
1 parent 06ab684 commit ee0399a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
10 changes: 6 additions & 4 deletions pkg/ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,17 +513,19 @@ func (dc *ddlCtx) getReorgCtx(jobID int64) *reorgCtx {
return dc.reorgCtx.reorgCtxMap[jobID]
}

func (dc *ddlCtx) newReorgCtx(jobID int64, rowCount int64) *reorgCtx {
func (dc *ddlCtx) newReorgCtx(jobID int64, jobState model.JobState, rowCount int64) *reorgCtx {
dc.reorgCtx.Lock()
defer dc.reorgCtx.Unlock()
existedRC, ok := dc.reorgCtx.reorgCtxMap[jobID]
if ok {
existedRC.references.Add(1)
return existedRC
}
rc := &reorgCtx{}
rc.doneCh = make(chan error, 1)
// initial reorgCtx
rc := &reorgCtx{
doneCh: make(chan error, 1),
rowCount: rowCount,
jobState: jobState,
}
rc.setRowCount(rowCount)
rc.mu.warnings = make(map[errors.ErrorID]*terror.Error)
rc.mu.warningsCount = make(map[errors.ErrorID]int64)
Expand Down
6 changes: 3 additions & 3 deletions pkg/ddl/ddl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (
type DDLForTest interface {
// SetInterceptor sets the interceptor.
SetInterceptor(h Interceptor)
NewReorgCtx(jobID int64, rowCount int64) *reorgCtx
NewReorgCtx(jobID int64, jobState model.JobState, rowCount int64) *reorgCtx
GetReorgCtx(jobID int64) *reorgCtx
RemoveReorgCtx(id int64)
}
Expand All @@ -59,8 +59,8 @@ func (rc *reorgCtx) IsReorgCanceled() bool {
}

// NewReorgCtx exports for testing.
func (d *ddl) NewReorgCtx(jobID int64, rowCount int64) *reorgCtx {
return d.newReorgCtx(jobID, rowCount)
func (d *ddl) NewReorgCtx(jobID int64, jobState model.JobState, rowCount int64) *reorgCtx {
return d.newReorgCtx(jobID, jobState, rowCount)
}

// GetReorgCtx exports for testing.
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddl/ddl_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,15 @@ func TestUsingReorgCtx(t *testing.T) {
wg.Run(func() {
jobID := int64(1)
for i := 0; i < 500; i++ {
d.(ddl.DDLForTest).NewReorgCtx(jobID, 0)
d.(ddl.DDLForTest).NewReorgCtx(jobID, model.JobStateRunning, 0)
d.(ddl.DDLForTest).GetReorgCtx(jobID).IsReorgCanceled()
d.(ddl.DDLForTest).RemoveReorgCtx(jobID)
}
})
wg.Run(func() {
jobID := int64(1)
for i := 0; i < 500; i++ {
d.(ddl.DDLForTest).NewReorgCtx(jobID, 0)
d.(ddl.DDLForTest).NewReorgCtx(jobID, model.JobStateRunning, 0)
d.(ddl.DDLForTest).GetReorgCtx(jobID).IsReorgCanceled()
d.(ddl.DDLForTest).RemoveReorgCtx(jobID)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/reorg.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (w *worker) runReorgJob(reorgInfo *reorgInfo, tblInfo *model.TableInfo,
return dbterror.ErrCancelledDDLJob
}

rc = w.newReorgCtx(reorgInfo.Job.ID, reorgInfo.Job.GetRowCount())
rc = w.newReorgCtx(job.ID, job.State, job.GetRowCount())
w.wg.Add(1)
go func() {
defer w.wg.Done()
Expand Down

0 comments on commit ee0399a

Please sign in to comment.