Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 committed Apr 10, 2024
1 parent 152a13b commit b648100
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions pkg/table/tables/partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -1763,24 +1763,19 @@ func partitionedTableUpdateRecord(gctx context.Context, ctx table.MutateContext,
}
}

txn, err := ctx.Txn(true)
if err != nil {
return errors.Trace(err)
}
memBuffer := txn.GetMemBuffer()
sh := memBuffer.Staging()
defer func() {
memBuffer.Cleanup(sh)
}()

// The old and new data locate in different partitions.
// Remove record from old partition and add record to new partition.
if from != to {
txn, err := ctx.Txn(true)
if err != nil {
return errors.Trace(err)
}
memBuffer := txn.GetMemBuffer()
sh := memBuffer.Staging()
defer func() {
// NOTICE: Don't create a new `err` in this branch.
if err == nil {
memBuffer.Release(sh)
} else {
memBuffer.Cleanup(sh)
}
}()

err = t.GetPartition(from).RemoveRecord(ctx, h, currData)
if err != nil {
return errors.Trace(err)
Expand Down Expand Up @@ -1808,8 +1803,12 @@ func partitionedTableUpdateRecord(gctx context.Context, ctx table.MutateContext,
}
if newTo == newFrom && newTo != 0 {
// Update needs to be done in StateDeleteOnly as well
tbl := t.GetPartition(newTo)
return tbl.UpdateRecord(gctx, ctx, h, currData, newData, touched)
err = t.GetPartition(newTo).UpdateRecord(gctx, ctx, h, currData, newData, touched)
if err != nil {
return errors.Trace(err)
}
memBuffer.Release(sh)
return nil
}

if newFrom != 0 {
Expand All @@ -1825,6 +1824,7 @@ func partitionedTableUpdateRecord(gctx context.Context, ctx table.MutateContext,
return errors.Trace(err)
}
}
memBuffer.Release(sh)
return nil
}
tbl := t.GetPartition(to)
Expand Down Expand Up @@ -1853,6 +1853,7 @@ func partitionedTableUpdateRecord(gctx context.Context, ctx table.MutateContext,
if err != nil {
return errors.Trace(err)
}
memBuffer.Release(sh)
return nil
}
if t.Meta().GetPartitionInfo().DDLState != model.StateDeleteOnly {
Expand All @@ -1868,6 +1869,7 @@ func partitionedTableUpdateRecord(gctx context.Context, ctx table.MutateContext,
return errors.Trace(err)
}
}
memBuffer.Release(sh)
return nil
}

Expand Down

0 comments on commit b648100

Please sign in to comment.