Skip to content

Commit

Permalink
*: Add some PD tests for placement and fix some bug found (#30621)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcwangchao authored Dec 12, 2021
1 parent 626dee7 commit 7555536
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var _ = Suite(&testDBSuite2{&testDBSuite{}})
var _ = Suite(&testDBSuite3{&testDBSuite{}})
var _ = Suite(&testDBSuite4{&testDBSuite{}})
var _ = Suite(&testDBSuite5{&testDBSuite{}})
var _ = Suite(&testDBSuite6{&testDBSuite{}})
var _ = SerialSuites(&testDBSuite6{&testDBSuite{}})
var _ = Suite(&testDBSuite7{&testDBSuite{}})
var _ = Suite(&testDBSuite8{&testDBSuite{}})
var _ = SerialSuites(&testSerialDBSuite{&testDBSuite{}})
Expand Down
18 changes: 10 additions & 8 deletions ddl/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (w *worker) onAddTablePartition(d *ddlCtx, t *meta.Meta, job *model.Job) (v
return ver, nil
}

// notice: addingDefinitions is empty when job is in state model.StateNone
tblInfo, partInfo, addingDefinitions, err := checkAddPartition(t, job)
if err != nil {
return ver, err
Expand Down Expand Up @@ -117,14 +118,21 @@ func (w *worker) onAddTablePartition(d *ddlCtx, t *meta.Meta, job *model.Job) (v
return ver, errors.Trace(err)
}

// move the adding definition into tableInfo.
updateAddingPartitionInfo(partInfo, tblInfo)
ver, err = updateVersionAndTableInfoWithCheck(t, job, tblInfo, true)
if err != nil {
return ver, errors.Trace(err)
}

// modify placement settings
for _, def := range addingDefinitions {
for _, def := range tblInfo.Partition.AddingDefinitions {
if _, err = checkPlacementPolicyRefValidAndCanNonValidJob(t, job, def.PlacementPolicyRef); err != nil {
return ver, errors.Trace(err)
}
}

bundles, err := alterTablePartitionBundles(t, tblInfo, addingDefinitions)
bundles, err := alterTablePartitionBundles(t, tblInfo, tblInfo.Partition.AddingDefinitions)
if err != nil {
job.State = model.JobStateCancelled
return ver, errors.Trace(err)
Expand All @@ -135,12 +143,6 @@ func (w *worker) onAddTablePartition(d *ddlCtx, t *meta.Meta, job *model.Job) (v
return ver, errors.Wrapf(err, "failed to notify PD the placement rules")
}

// move the adding definition into tableInfo.
updateAddingPartitionInfo(partInfo, tblInfo)
ver, err = updateVersionAndTableInfoWithCheck(t, job, tblInfo, true)
if err != nil {
return ver, errors.Trace(err)
}
// none -> replica only
job.SchemaState = model.StateReplicaOnly
case model.StateReplicaOnly:
Expand Down
2 changes: 1 addition & 1 deletion ddl/placement_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func getPlacementPolicyDependedObjectsIDs(t *meta.Meta, policy *model.PolicyInfo
}
if tblInfo.Partition != nil {
for _, part := range tblInfo.Partition.Definitions {
if part.PlacementPolicyRef != nil && part.PlacementPolicyRef.ID == part.ID {
if part.PlacementPolicyRef != nil && part.PlacementPolicyRef.ID == policy.ID {
partIDs = append(partIDs, part.ID)
}
}
Expand Down
Loading

0 comments on commit 7555536

Please sign in to comment.