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

gcjob: fix race in gc job test #46792

Merged
merged 1 commit into from
Mar 31, 2020
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
51 changes: 23 additions & 28 deletions pkg/sql/gcjob_test/gc_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ func TestSchemaChangeGCJob(t *testing.T) {
},
ParentID: myTableID,
}
myTableDesc.Indexes = myTableDesc.Indexes[:0]
myTableDesc.GCMutations = append(myTableDesc.GCMutations, sqlbase.TableDescriptor_GCDescriptorMutation{
IndexID: sqlbase.IndexID(2),
})
case TABLE:
details = jobspb.SchemaChangeGCDetails{
Tables: []jobspb.SchemaChangeGCDetails_DroppedID{
Expand All @@ -117,6 +121,8 @@ func TestSchemaChangeGCJob(t *testing.T) {
},
},
}
myTableDesc.State = sqlbase.TableDescriptor_DROP
myTableDesc.DropTime = dropTime
case DATABASE:
details = jobspb.SchemaChangeGCDetails{
Tables: []jobspb.SchemaChangeGCDetails_DroppedID{
Expand All @@ -131,6 +137,23 @@ func TestSchemaChangeGCJob(t *testing.T) {
},
ParentID: myDBID,
}
myTableDesc.State = sqlbase.TableDescriptor_DROP
myTableDesc.DropTime = dropTime
myOtherTableDesc.State = sqlbase.TableDescriptor_DROP
myOtherTableDesc.DropTime = dropTime
}

if err := kvDB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
b := txn.NewBatch()
descKey := sqlbase.MakeDescMetadataKey(myTableID)
descDesc := sqlbase.WrapDescriptor(myTableDesc)
b.Put(descKey, descDesc)
descKey2 := sqlbase.MakeDescMetadataKey(myOtherTableID)
descDesc2 := sqlbase.WrapDescriptor(myOtherTableDesc)
b.Put(descKey2, descDesc2)
return txn.Run(ctx, b)
}); err != nil {
t.Fatal(err)
}

jobRecord := jobs.Record{
Expand All @@ -156,34 +179,6 @@ func TestSchemaChangeGCJob(t *testing.T) {
t.Fatal(err)
}

switch dropItem {
case INDEX:
myTableDesc.Indexes = myTableDesc.Indexes[:0]
myTableDesc.GCMutations = append(myTableDesc.GCMutations, sqlbase.TableDescriptor_GCDescriptorMutation{
IndexID: sqlbase.IndexID(2),
})
case DATABASE:
myOtherTableDesc.State = sqlbase.TableDescriptor_DROP
myOtherTableDesc.DropTime = dropTime
fallthrough
case TABLE:
myTableDesc.State = sqlbase.TableDescriptor_DROP
myTableDesc.DropTime = dropTime
}

if err := kvDB.Txn(ctx, func(ctx context.Context, txn *kv.Txn) error {
b := txn.NewBatch()
descKey := sqlbase.MakeDescMetadataKey(myTableID)
descDesc := sqlbase.WrapDescriptor(myTableDesc)
b.Put(descKey, descDesc)
descKey2 := sqlbase.MakeDescMetadataKey(myOtherTableID)
descDesc2 := sqlbase.WrapDescriptor(myOtherTableDesc)
b.Put(descKey2, descDesc2)
return txn.Run(ctx, b)
}); err != nil {
t.Fatal(err)
}

// Check that the job started.
jobIDStr := strconv.Itoa(int(*job.ID()))
if err := jobutils.VerifySystemJob(t, sqlDB, 0, jobspb.TypeSchemaChangeGC, jobs.StatusRunning, lookupJR); err != nil {
Expand Down