Skip to content

Commit 71661a4

Browse files
authored
fix data copy in replaying from checkpoint - main (#21233)
- Copy bytes to target fields Approved by: @XuPeng-SH
1 parent 18910d4 commit 71661a4

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

pkg/container/vector/vector.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ func GetFixedAtWithTypeCheck[T any](v *Vector, idx int) T {
278278
return slice[idx]
279279
}
280280

281+
func (v *Vector) CloneBytesAt(i int) []byte {
282+
bs := v.GetBytesAt(i)
283+
ret := make([]byte, len(bs))
284+
copy(ret, bs)
285+
return ret
286+
}
287+
281288
func (v *Vector) GetBytesAt(i int) []byte {
282289
if v.IsConst() {
283290
i = 0

pkg/vm/engine/tae/catalog/catalogreplay.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,13 @@ func (catalog *Catalog) ReplayMOTables(ctx context.Context, txnNode *txnbase.Txn
387387
schema.Relkind = tblBat.GetVectorByName(pkgcatalog.SystemRelAttr_Kind).GetDownstreamVector().GetStringAt(i)
388388
schema.Createsql = tblBat.GetVectorByName(pkgcatalog.SystemRelAttr_CreateSQL).GetDownstreamVector().GetStringAt(i)
389389
schema.View = tblBat.GetVectorByName(pkgcatalog.SystemRelAttr_ViewDef).GetDownstreamVector().GetStringAt(i)
390-
schema.Constraint = tblBat.GetVectorByName(pkgcatalog.SystemRelAttr_Constraint).GetDownstreamVector().GetBytesAt(i)
390+
schema.Constraint = tblBat.GetVectorByName(pkgcatalog.SystemRelAttr_Constraint).GetDownstreamVector().CloneBytesAt(i)
391391
schema.AcInfo = accessInfo{}
392392
schema.AcInfo.RoleID = roleIDs[i]
393393
schema.AcInfo.UserID = userIDs[i]
394394
schema.AcInfo.CreateAt = createAts[i]
395395
schema.AcInfo.TenantID = tenantIDs[i]
396+
// unmarshal before releasing, no need to copy
396397
extra := tblBat.GetVectorByName(pkgcatalog.SystemRelAttr_ExtraInfo).GetDownstreamVector().GetBytesAt(i)
397398
schema.MustRestoreExtra(extra)
398399
if err := schema.Finalize(true); err != nil {

pkg/vm/engine/tae/catalog/schema.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ func (s *Schema) ReadFromBatch(
622622
}
623623
def := new(ColDef)
624624
def.Name = bat.GetVectorByName((pkgcatalog.SystemColAttr_Name)).GetDownstreamVector().GetStringAt(offset)
625+
// unmarshal before releasing, no need to copy
625626
data := bat.GetVectorByName((pkgcatalog.SystemColAttr_Type)).GetDownstreamVector().GetBytesAt(offset)
626627
types.Decode(data, &def.Type)
627628
nullable := nullables[offset]
@@ -636,8 +637,8 @@ func (s *Schema) ReadFromBatch(
636637
isAutoIncrement := autoIncrements[offset]
637638
def.AutoIncrement = i82bool(isAutoIncrement)
638639
def.Comment = bat.GetVectorByName((pkgcatalog.SystemColAttr_Comment)).GetDownstreamVector().GetStringAt(offset)
639-
def.OnUpdate = bat.GetVectorByName((pkgcatalog.SystemColAttr_Update)).GetDownstreamVector().GetBytesAt(offset)
640-
def.Default = bat.GetVectorByName((pkgcatalog.SystemColAttr_DefaultExpr)).GetDownstreamVector().GetBytesAt(offset)
640+
def.OnUpdate = bat.GetVectorByName((pkgcatalog.SystemColAttr_Update)).GetDownstreamVector().CloneBytesAt(offset)
641+
def.Default = bat.GetVectorByName((pkgcatalog.SystemColAttr_DefaultExpr)).GetDownstreamVector().CloneBytesAt(offset)
641642
def.Idx = int(idxes[offset]) - 1
642643
def.SeqNum = seqNums[offset]
643644
def.EnumValues = bat.GetVectorByName((pkgcatalog.SystemColAttr_EnumValues)).GetDownstreamVector().GetStringAt(offset)

0 commit comments

Comments
 (0)