Skip to content

Commit 5b14000

Browse files
committed
Simplified code, reused similar function.
1 parent ace2802 commit 5b14000

File tree

2 files changed

+16
-42
lines changed

2 files changed

+16
-42
lines changed

pkg/ddl/partition.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,8 +2035,8 @@ func CheckDropTablePartition(meta *model.TableInfo, partLowerNames []string) err
20352035
return nil
20362036
}
20372037

2038-
// updateDroppingPartitionInfo move dropping partitions to DroppingDefinitions, and return partitionIDs
2039-
func updateDroppingPartitionInfo(tblInfo *model.TableInfo, partLowerNames []string) []int64 {
2038+
// updateDroppingPartitionInfo move dropping partitions to DroppingDefinitions
2039+
func updateDroppingPartitionInfo(tblInfo *model.TableInfo, partLowerNames []string) {
20402040
oldDefs := tblInfo.Partition.Definitions
20412041
newDefs := make([]model.PartitionDefinition, 0, len(oldDefs)-len(partLowerNames))
20422042
droppingDefs := make([]model.PartitionDefinition, 0, len(partLowerNames))
@@ -2061,7 +2061,6 @@ func updateDroppingPartitionInfo(tblInfo *model.TableInfo, partLowerNames []stri
20612061

20622062
tblInfo.Partition.Definitions = newDefs
20632063
tblInfo.Partition.DroppingDefinitions = droppingDefs
2064-
return pids
20652064
}
20662065

20672066
func getPartitionDef(tblInfo *model.TableInfo, partName string) (index int, def *model.PartitionDefinition, _ error) {
@@ -2237,7 +2236,7 @@ func (w *worker) onDropTablePartition(jobCtx *jobContext, job *model.Job) (ver i
22372236
// Reason, see https://github.com/pingcap/tidb/issues/55888
22382237
// Only mark the partitions as to be dropped, so they are not used, but not yet removed.
22392238
originalDefs := tblInfo.Partition.Definitions
2240-
_ = updateDroppingPartitionInfo(tblInfo, partNames)
2239+
updateDroppingPartitionInfo(tblInfo, partNames)
22412240
tblInfo.Partition.Definitions = originalDefs
22422241
job.SchemaState = model.StateWriteOnly
22432242
tblInfo.Partition.DDLState = job.SchemaState
@@ -2248,7 +2247,7 @@ func (w *worker) onDropTablePartition(jobCtx *jobContext, job *model.Job) (ver i
22482247
// Since the previous state do not use the dropping partitions,
22492248
// we can now actually remove them, allowing to write into the overlapping range
22502249
// of the higher range partition or LIST default partition.
2251-
_ = updateDroppingPartitionInfo(tblInfo, partNames)
2250+
updateDroppingPartitionInfo(tblInfo, partNames)
22522251
err = dropLabelRules(jobCtx.stepCtx, job.SchemaName, tblInfo.Name.L, partNames)
22532252
if err != nil {
22542253
// TODO: Add failpoint error/cancel injection and test failure/rollback and cancellation!
@@ -3164,7 +3163,7 @@ func (w *worker) onReorganizePartition(jobCtx *jobContext, job *model.Job) (ver
31643163
// move the adding definition into tableInfo.
31653164
updateAddingPartitionInfo(partInfo, tblInfo)
31663165
orgDefs := tblInfo.Partition.Definitions
3167-
_ = updateDroppingPartitionInfo(tblInfo, partNames)
3166+
updateDroppingPartitionInfo(tblInfo, partNames)
31683167
// Reset original partitions, and keep DroppedDefinitions
31693168
tblInfo.Partition.Definitions = orgDefs
31703169

pkg/table/tables/index.go

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/pingcap/tidb/pkg/tablecodec"
2929
"github.com/pingcap/tidb/pkg/types"
3030
"github.com/pingcap/tidb/pkg/util"
31-
"github.com/pingcap/tidb/pkg/util/codec"
3231
"github.com/pingcap/tidb/pkg/util/intest"
3332
"github.com/pingcap/tidb/pkg/util/rowcodec"
3433
"github.com/pingcap/tidb/pkg/util/tracing"
@@ -297,19 +296,21 @@ func (c *index) create(sctx table.MutateContext, txn kv.Transaction, indexedValu
297296
// Note that a partitioned table cannot be temporary table
298297
value, err = txn.Get(ctx, key)
299298
if err == nil && len(value) != 0 {
300-
partHandle, errPart := GetPartitionHandleFromVal(value)
299+
handle, errPart := tablecodec.DecodeHandleInIndexValue(value)
301300
if errPart != nil {
302301
return nil, errPart
303302
}
304-
for _, id := range c.tblInfo.Partition.IDsInDDLToIgnore() {
305-
if id == partHandle.PartitionID {
306-
// Simply overwrite it
307-
err = txn.SetAssertion(key, kv.SetAssertUnknown)
308-
if err != nil {
309-
return nil, err
303+
if partHandle, ok := handle.(kv.PartitionHandle); ok {
304+
for _, id := range c.tblInfo.Partition.IDsInDDLToIgnore() {
305+
if id == partHandle.PartitionID {
306+
// Simply overwrite it
307+
err = txn.SetAssertion(key, kv.SetAssertUnknown)
308+
if err != nil {
309+
return nil, err
310+
}
311+
value = nil
312+
break
310313
}
311-
value = nil
312-
break
313314
}
314315
}
315316
}
@@ -583,32 +584,6 @@ func FetchDuplicatedHandle(ctx context.Context, key kv.Key, distinct bool,
583584
return true, nil, nil
584585
}
585586

586-
// GetPartitionHandleFromVal creates a PartitionHandle from a global index value
587-
func GetPartitionHandleFromVal(val []byte) (*kv.PartitionHandle, error) {
588-
seg := tablecodec.SplitIndexValue(val)
589-
var handle kv.Handle
590-
if len(seg.IntHandle) != 0 {
591-
handle = tablecodec.DecodeIntHandleInIndexValue(seg.IntHandle)
592-
}
593-
if len(seg.CommonHandle) != 0 {
594-
var err error
595-
handle, err = kv.NewCommonHandle(seg.CommonHandle)
596-
if err != nil {
597-
return nil, err
598-
}
599-
}
600-
if len(seg.PartitionID) != 0 {
601-
_, pid, err := codec.DecodeInt(seg.PartitionID)
602-
if err != nil {
603-
return nil, err
604-
}
605-
partHandle := kv.NewPartitionHandle(pid, handle)
606-
return &partHandle, nil
607-
}
608-
609-
return nil, nil
610-
}
611-
612587
func fetchDuplicatedHandleForTempIndexKey(ctx context.Context, tempKey kv.Key, distinct bool,
613588
txn kv.Transaction, tableID int64) (foundKey bool, dupHandle kv.Handle, err error) {
614589
tempRawVal, err := getKeyInTxn(ctx, txn, tempKey)

0 commit comments

Comments
 (0)