Skip to content

some code cleanup #21828

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
1 change: 0 additions & 1 deletion pkg/frontend/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ func TestSession_TxnCompilerContext(t *testing.T) {
table.EXPECT().GetTableDef(gomock.Any()).Return(&plan.TableDef{}).AnyTimes()
table.EXPECT().CopyTableDef(gomock.Any()).Return(&plan.TableDef{}).AnyTimes()
table.EXPECT().GetPrimaryKeys(gomock.Any()).Return(nil, nil).AnyTimes()
table.EXPECT().GetHideKeys(gomock.Any()).Return(nil, nil).AnyTimes()
table.EXPECT().Stats(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes()
table.EXPECT().TableColumns(gomock.Any()).Return(nil, nil).AnyTimes()
table.EXPECT().GetTableID(gomock.Any()).Return(uint64(10)).AnyTimes()
Expand Down
30 changes: 0 additions & 30 deletions pkg/frontend/test/engine_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions pkg/objectio/ioutil/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,6 @@ func (r *BlockReader) LoadOneBF(
return r.reader.ReadOneBF(ctx, blk)
}

func (r *BlockReader) LoadAllBF(
ctx context.Context,
) (objectio.BloomFilter, uint32, error) {
return r.reader.ReadAllBF(ctx)
}

func (r *BlockReader) GetObjectName() *objectio.ObjectName {
return r.reader.GetObjectName()
}

func (r *BlockReader) GetName() string {
return r.reader.GetName()
}

func (r *BlockReader) GetObjectReader() *objectio.ObjectReader {
return r.reader
}
16 changes: 0 additions & 16 deletions pkg/objectio/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,22 +251,6 @@ func (r *objectReaderV1) ReadOneBF(
return bf, size, nil
}

func (r *objectReaderV1) ReadAllBF(
ctx context.Context,
) (bfs BloomFilter, size uint32, err error) {
var metaHeader ObjectMeta
var buf []byte
if metaHeader, err = r.ReadMeta(ctx, nil); err != nil {
return
}
meta := metaHeader.MustDataMeta()
extent := meta.BlockHeader().BFExtent()
if buf, err = ReadBloomFilter(ctx, r.name, &extent, r.dataReadPolicy, r.fs); err != nil {
return
}
return buf, extent.OriginSize(), nil
}

func (r *objectReaderV1) ReadExtent(
ctx context.Context,
extent Extent,
Expand Down
1 change: 0 additions & 1 deletion pkg/util/test/cron_task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ func TestCalculateStorageUsage(t *testing.T) {
table.EXPECT().Ranges(gomock.Any(), gomock.Any()).Return(nil, nil).AnyTimes()
table.EXPECT().TableDefs(gomock.Any()).Return(nil, nil).AnyTimes()
table.EXPECT().GetPrimaryKeys(gomock.Any()).Return(nil, nil).AnyTimes()
table.EXPECT().GetHideKeys(gomock.Any()).Return(nil, nil).AnyTimes()
table.EXPECT().TableColumns(gomock.Any()).Return(nil, nil).AnyTimes()
table.EXPECT().GetTableID(gomock.Any()).Return(uint64(10)).AnyTimes()
db := mock_frontend.NewMockDatabase(ctrl)
Expand Down
117 changes: 24 additions & 93 deletions pkg/vm/engine/disttae/txn_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -1006,68 +1006,6 @@ func (tbl *txnTable) collectUnCommittedDataObjs(txnOffset int) ([]objectio.Objec
return unCommittedObjects, unCommittedObjNames
}

//func (tbl *txnTable) collectDirtyBlocks(
// state *logtailreplay.PartitionState,
// uncommittedObjects []objectio.ObjectStats,
// txnOffset int, // Transaction writes offset used to specify the starting position for reading data.
//) map[types.Blockid]struct{} {
// dirtyBlks := make(map[types.Blockid]struct{})
// //collect partitionState.dirtyBlocks which may be invisible to this txn into dirtyBlks.
// {
// iter := state.NewDirtyBlocksIter()
// for iter.Next() {
// entry := iter.Entry()
// //lazy load deletes for block.
// dirtyBlks[entry] = struct{}{}
// }
// iter.Close()
//
// }
//
// //only collect dirty blocks in PartitionState.blocks into dirtyBlks.
// for _, bid := range tbl.GetDirtyPersistedBlks(state) {
// dirtyBlks[bid] = struct{}{}
// }
//
// if tbl.getTxn().hasDeletesOnUncommitedObject() {
// ForeachBlkInObjStatsList(true, nil, func(blk objectio.BlockInfo, _ objectio.BlockObject) bool {
// if tbl.getTxn().hasUncommittedDeletesOnBlock(&blk.BlockID) {
// dirtyBlks[blk.BlockID] = struct{}{}
// }
// return true
// }, uncommittedObjects...)
// }
//
// if tbl.db.op.IsSnapOp() {
// txnOffset = tbl.getTxn().GetSnapshotWriteOffset()
// }
//
// tbl.getTxn().ForEachTableWrites(
// tbl.db.databaseId,
// tbl.tableId,
// txnOffset,
// func(entry Entry) {
// // the CN workspace can only handle `INSERT` and `DELETE` operations. Other operations will be skipped,
// // TODO Adjustments will be made here in the future
// if entry.typ == DELETE || entry.typ == DELETE_TXN {
// if entry.IsGeneratedByTruncate() {
// return
// }
// //deletes in tbl.writes maybe comes from PartitionState.rows or PartitionState.blocks.
// if entry.fileName == "" &&
// entry.tableId != catalog.MO_DATABASE_ID && entry.tableId != catalog.MO_TABLES_ID && entry.tableId != catalog.MO_COLUMNS_ID {
// vs := vector.MustFixedColWithTypeCheck[types.Rowid](entry.bat.GetVector(0))
// for _, v := range vs {
// id, _ := v.Decode()
// dirtyBlks[id] = struct{}{}
// }
// }
// }
// })
//
// return dirtyBlks
//}

// the return defs has no rowid column
func (tbl *txnTable) TableDefs(ctx context.Context) ([]engine.TableDef, error) {
//return tbl.defs, nil
Expand Down Expand Up @@ -1493,18 +1431,6 @@ func (tbl *txnTable) GetPrimaryKeys(ctx context.Context) ([]*engine.Attribute, e
return attrs, nil
}

func (tbl *txnTable) GetHideKeys(ctx context.Context) ([]*engine.Attribute, error) {
attrs := make([]*engine.Attribute, 0, 1)
attrs = append(attrs, &engine.Attribute{
IsHidden: true,
IsRowId: true,
Name: objectio.PhysicalAddr_Attr,
Type: types.New(types.T_Rowid, 0, 0),
Primary: true,
})
return attrs, nil
}

func (tbl *txnTable) Write(ctx context.Context, bat *batch.Batch) error {
if tbl.db.op.IsSnapOp() {
return moerr.NewInternalErrorNoCtx("write operation is not allowed in snapshot transaction")
Expand Down Expand Up @@ -1549,13 +1475,6 @@ func (tbl *txnTable) Write(ctx context.Context, bat *batch.Batch) error {
return tbl.getTxn().dumpBatch(ctx, tbl.getTxn().GetSnapshotWriteOffset())
}

func (tbl *txnTable) Update(ctx context.Context, bat *batch.Batch) error {
if tbl.db.op.IsSnapOp() {
return moerr.NewInternalErrorNoCtx("update operation is not allowed in snapshot transaction")
}
return nil
}

func (tbl *txnTable) ensureSeqnumsAndTypesExpectRowid() {
if tbl.seqnums != nil && tbl.typs != nil {
return
Expand All @@ -1575,7 +1494,7 @@ func (tbl *txnTable) ensureSeqnumsAndTypesExpectRowid() {
func (tbl *txnTable) rewriteObjectByDeletion(
ctx context.Context,
obj objectio.ObjectStats,
deletes map[objectio.Blockid][]int64,
blockDeletes map[objectio.Blockid][]int64,
) (*batch.Batch, string, error) {

proc := tbl.proc.Load()
Expand All @@ -1599,20 +1518,33 @@ func (tbl *txnTable) rewriteObjectByDeletion(
fileName string
)

objectio.ForeachBlkInObjStatsList(true, nil,
defer func() {
if bat != nil {
bat.Clean(proc.Mp())
}
}()

objectio.ForeachBlkInObjStatsList(
true,
nil,
func(blk objectio.BlockInfo, blkMeta objectio.BlockObject) bool {
deletes := blockDeletes[blk.BlockID]
slices.Sort(deletes)
if bat == nil {
bat = batch.NewWithSize(len(tbl.seqnums))
}
bat.CleanOnlyData()

del := deletes[blk.BlockID]
slices.Sort(del)
if bat, err = blockio.BlockCompactionRead(
if err = blockio.CopyBlockData(
tbl.getTxn().proc.Ctx,
blk.MetaLoc[:],
del,
deletes,
tbl.seqnums,
tbl.typs,
bat,
tbl.getTxn().engine.fs,
tbl.getTxn().proc.GetMPool()); err != nil {

tbl.getTxn().proc.GetMPool(),
); err != nil {
return false
}

Expand All @@ -1624,11 +1556,10 @@ func (tbl *txnTable) rewriteObjectByDeletion(
return false
}

bat.Clean(tbl.getTxn().proc.GetMPool())

return true

}, obj)
},
obj,
)

if err != nil {
return nil, fileName, err
Expand Down
19 changes: 0 additions & 19 deletions pkg/vm/engine/disttae/txn_table_delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,15 +903,6 @@ func (tbl *txnTableDelegate) GetPrimaryKeys(
return tbl.origin.GetPrimaryKeys(ctx)
}

func (tbl *txnTableDelegate) GetHideKeys(
ctx context.Context,
) ([]*engine.Attribute, error) {
if tbl.partition.is {
return tbl.partition.tbl.GetHideKeys(ctx)
}
return tbl.origin.GetHideKeys(ctx)
}

func (tbl *txnTableDelegate) Write(
ctx context.Context,
bat *batch.Batch,
Expand All @@ -922,16 +913,6 @@ func (tbl *txnTableDelegate) Write(
return tbl.origin.Write(ctx, bat)
}

func (tbl *txnTableDelegate) Update(
ctx context.Context,
bat *batch.Batch,
) error {
if tbl.partition.is {
return tbl.partition.tbl.Update(ctx, bat)
}
return tbl.origin.Update(ctx, bat)
}

func (tbl *txnTableDelegate) Delete(
ctx context.Context,
bat *batch.Batch,
Expand Down
8 changes: 0 additions & 8 deletions pkg/vm/engine/disttae/txn_table_partition.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,6 @@ func (t *partitionTxnTable) GetPrimaryKeys(ctx context.Context) ([]*engine.Attri
return t.primary.GetPrimaryKeys(ctx)
}

func (t *partitionTxnTable) GetHideKeys(ctx context.Context) ([]*engine.Attribute, error) {
return t.primary.GetHideKeys(ctx)
}

func (t *partitionTxnTable) AddTableDef(context.Context, engine.TableDef) error {
return nil
}
Expand Down Expand Up @@ -432,10 +428,6 @@ func (t *partitionTxnTable) Write(context.Context, *batch.Batch) error {
panic("BUG: cannot write data to partition primary table")
}

func (t *partitionTxnTable) Update(context.Context, *batch.Batch) error {
panic("BUG: cannot update data to partition primary table")
}

func (t *partitionTxnTable) Delete(context.Context, *batch.Batch, string) error {
panic("BUG: cannot delete data to partition primary table")
}
Expand Down
Loading
Loading