github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/iface/data/object.go (about)

     1  // Copyright 2021 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package data
    16  
    17  import (
    18  	"context"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/common/bitmap"
    21  	"github.com/matrixorigin/matrixone/pkg/common/mpool"
    22  	"github.com/matrixorigin/matrixone/pkg/objectio"
    23  
    24  	"github.com/matrixorigin/matrixone/pkg/container/types"
    25  
    26  	"github.com/RoaringBitmap/roaring"
    27  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common"
    28  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers"
    29  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/db/dbutils"
    30  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/handle"
    31  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/txnif"
    32  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/index"
    33  )
    34  
    35  type CheckpointUnit interface {
    36  	MutationInfo() string
    37  	RunCalibration() (int, error)
    38  	// EstimateScore(time.Duration, bool) int
    39  }
    40  
    41  type ObjectAppender interface {
    42  	GetID() *common.ID
    43  	GetMeta() any
    44  	// see more notes in flushtabletail.go
    45  	LockFreeze()
    46  	UnlockFreeze()
    47  	CheckFreeze() bool
    48  	IsSameColumns(otherSchema any /*avoid import cycle*/) bool
    49  	PrepareAppend(rows uint32,
    50  		txn txnif.AsyncTxn) (
    51  		node txnif.AppendNode, created bool, n uint32, err error)
    52  	ApplyAppend(bat *containers.Batch,
    53  		txn txnif.AsyncTxn,
    54  	) (int, error)
    55  	IsAppendable() bool
    56  	ReplayAppend(bat *containers.Batch,
    57  		txn txnif.AsyncTxn) (int, error)
    58  	Close()
    59  }
    60  
    61  type ObjectReplayer interface {
    62  	OnReplayDelete(blkID uint16, node txnif.DeleteNode) (err error)
    63  	OnReplayAppend(node txnif.AppendNode) (err error)
    64  	OnReplayAppendPayload(bat *containers.Batch) (err error)
    65  }
    66  
    67  type Object interface {
    68  	CheckpointUnit
    69  	ObjectReplayer
    70  
    71  	DeletesInfo() string
    72  
    73  	GetRowsOnReplay() uint64
    74  	GetID() *common.ID
    75  	IsAppendable() bool
    76  	PrepareCompact() bool
    77  	PrepareCompactInfo() (bool, string)
    78  	GetDeltaPersistedTS() types.TS
    79  
    80  	Rows() (int, error)
    81  	CheckFlushTaskRetry(startts types.TS) bool
    82  
    83  	GetColumnDataById(
    84  		ctx context.Context, txn txnif.AsyncTxn, readSchema any /*avoid import cycle*/, blkID uint16, colIdx int, mp *mpool.MPool,
    85  	) (*containers.ColumnView, error)
    86  	GetColumnDataByIds(
    87  		ctx context.Context, txn txnif.AsyncTxn, readSchema any, blkID uint16, colIdxes []int, mp *mpool.MPool,
    88  	) (*containers.BlockView, error)
    89  	Prefetch(idxes []uint16, blkID uint16) error
    90  	GetMeta() any
    91  
    92  	MakeAppender() (ObjectAppender, error)
    93  	RangeDelete(txn txnif.AsyncTxn, blkID uint16, start, end uint32, pk containers.Vector, dt handle.DeleteType) (txnif.DeleteNode, error)
    94  	TryDeleteByDeltaloc(txn txnif.AsyncTxn, blkID uint16, deltaLoc objectio.Location) (node txnif.TxnEntry, ok bool, err error)
    95  
    96  	GetTotalChanges() int
    97  	CollectChangesInRange(ctx context.Context, blkID uint16, startTs, endTs types.TS, mp *mpool.MPool) (*containers.BlockView, error)
    98  
    99  	// check wether any delete intents with prepared ts within [from, to]
   100  	HasDeleteIntentsPreparedIn(from, to types.TS) (bool, bool)
   101  	HasDeleteIntentsPreparedInByBlock(blockID uint16, from, to types.TS) (bool, bool)
   102  
   103  	// check if all rows are committed before ts
   104  	// NOTE: here we assume that the object is visible to the ts
   105  	// if the object is an appendable object:
   106  	// 1. if the object is not frozen, return false
   107  	// 2. if the object is frozen and in-memory, check with the max ts committed
   108  	// 3. if the object is persisted, return false
   109  	// if the object is not an appendable object:
   110  	// only check with the created ts
   111  	CoarseCheckAllRowsCommittedBefore(ts types.TS) bool
   112  
   113  	BatchDedup(ctx context.Context,
   114  		txn txnif.AsyncTxn,
   115  		pks containers.Vector,
   116  		pksZM index.ZM,
   117  		rowmask *roaring.Bitmap,
   118  		precommit bool,
   119  		bf objectio.BloomFilter,
   120  		mp *mpool.MPool,
   121  	) error
   122  	//TODO::
   123  	//BatchDedupByMetaLoc(txn txnif.AsyncTxn, fs *objectio.ObjectFS,
   124  	//	metaLoc objectio.Location, rowmask *roaring.Bitmap, precommit bool) error
   125  
   126  	GetByFilter(ctx context.Context, txn txnif.AsyncTxn, filter *handle.Filter, mp *mpool.MPool) (uint16, uint32, error)
   127  	GetValue(ctx context.Context, txn txnif.AsyncTxn, readSchema any, blkID uint16, row, col int, mp *mpool.MPool) (any, bool, error)
   128  	Foreach(
   129  		ctx context.Context,
   130  		readSchema any,
   131  		blkID uint16,
   132  		colIdx int,
   133  		op func(v any, isNull bool, row int) error,
   134  		sels []uint32,
   135  		mp *mpool.MPool,
   136  	) error
   137  	PPString(level common.PPLevel, depth int, prefix string, blkid int) string
   138  	EstimateMemSize() (int, int)
   139  	GetRuntime() *dbutils.Runtime
   140  
   141  	Init() error
   142  	TryUpgrade() error
   143  	GCInMemeoryDeletesByTSForTest(types.TS)
   144  	UpgradeAllDeleteChain()
   145  	CollectAppendInRange(start, end types.TS, withAborted bool, mp *mpool.MPool) (*containers.BatchWithVersion, error)
   146  	CollectDeleteInRange(ctx context.Context, start, end types.TS, withAborted bool, mp *mpool.MPool) (*containers.Batch, *bitmap.Bitmap, error)
   147  	CollectDeleteInRangeByBlock(ctx context.Context, blkID uint16, start, end types.TS, withAborted bool, mp *mpool.MPool) (*containers.Batch, error)
   148  	PersistedCollectDeleteInRange(
   149  		ctx context.Context,
   150  		b *containers.Batch,
   151  		blkID uint16,
   152  		start, end types.TS,
   153  		withAborted bool,
   154  		mp *mpool.MPool,
   155  	) (bat *containers.Batch, err error)
   156  	// GetAppendNodeByRow(row uint32) (an txnif.AppendNode)
   157  	// GetDeleteNodeByRow(row uint32) (an txnif.DeleteNode)
   158  	GetFs() *objectio.ObjectFS
   159  	FreezeAppend()
   160  	UpdateDeltaLoc(txn txnif.TxnReader, blkID uint16, deltaLoc objectio.Location) (bool, txnif.TxnEntry, error)
   161  
   162  	Close()
   163  }
   164  
   165  type Tombstone interface {
   166  	EstimateMemSizeLocked() (dsize int)
   167  	GetChangeIntentionCntLocked() uint32
   168  	GetDeleteCnt() uint32
   169  	GetDeletesListener() func(uint64, types.TS) error
   170  	GetDeltaLocAndCommitTSByTxn(blkID uint16, txn txnif.TxnReader) (objectio.Location, types.TS)
   171  	GetDeltaLocAndCommitTS(blkID uint16) (objectio.Location, types.TS, types.TS)
   172  	GetDeltaPersistedTS() types.TS
   173  	// GetOrCreateDeleteChain(blkID uint16) *updates.MVCCHandle
   174  	HasDeleteIntentsPreparedIn(from types.TS, to types.TS) (found bool, isPersist bool)
   175  	HasInMemoryDeleteIntentsPreparedInByBlock(blockID uint16, from, to types.TS) (bool, bool)
   176  	IsDeletedLocked(row uint32, txn txnif.TxnReader, blkID uint16) (bool, error)
   177  	SetDeletesListener(l func(uint64, types.TS) error)
   178  	StringLocked(level common.PPLevel, depth int, prefix string) string
   179  	// TryGetDeleteChain(blkID uint16) *updates.MVCCHandle
   180  	UpgradeAllDeleteChain()
   181  	UpgradeDeleteChain(blkID uint16)
   182  	UpgradeDeleteChainByTSLocked(ts types.TS)
   183  	ReplayDeltaLoc(any, uint16)
   184  	VisitDeletes(ctx context.Context, start, end types.TS, bat, tnBatch *containers.Batch, skipMemory bool) (*containers.Batch, int, int, error)
   185  	GetObject() any
   186  	InMemoryDeletesExisted() bool
   187  	// for test
   188  	GetLatestDeltaloc(uint16) objectio.Location
   189  }