github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/txn/txnimpl/basenode.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 txnimpl 16 17 import ( 18 "context" 19 "fmt" 20 "io" 21 "unsafe" 22 23 "github.com/matrixorigin/matrixone/pkg/common/mpool" 24 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/catalog" 25 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common" 26 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers" 27 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/txnif" 28 ) 29 30 const MaxNodeRows = 10000 31 32 type InsertNode interface { 33 Close() error 34 Append(data *containers.Batch, offset uint32) (appended uint32, err error) 35 RangeDelete(start, end uint32) error 36 IsRowDeleted(row uint32) bool 37 IsPersisted() bool 38 PrintDeletes() string 39 GetColumnDataByIds([]int, *mpool.MPool) (*containers.BlockView, error) 40 GetColumnDataById(context.Context, int, *mpool.MPool) (*containers.ColumnView, error) 41 Prefetch(idxes []uint16) error 42 FillBlockView(view *containers.BlockView, colIdxes []int, mp *mpool.MPool) (err error) 43 FillColumnView(*containers.ColumnView, *mpool.MPool) error 44 Window(start, end uint32) (*containers.Batch, error) 45 WindowColumn(start, end uint32, pos int) (containers.Vector, error) 46 Rows() uint32 47 GetValue(col int, row uint32) (any, bool, error) 48 MakeCommand(uint32) (txnif.TxnCmd, error) 49 AddApplyInfo(srcOff, srcLen, destOff, destLen uint32, dest *common.ID) *appendInfo 50 GetAppends() []*appendInfo 51 GetTxn() txnif.AsyncTxn 52 } 53 54 type appendInfo struct { 55 seq uint32 56 srcOff, srcLen uint32 57 dest common.ID 58 destOff, destLen uint32 59 } 60 61 const ( 62 AppendInfoSize int64 = int64(unsafe.Sizeof(appendInfo{})) 63 ) 64 65 func EncodeAppendInfo(info *appendInfo) []byte { 66 return unsafe.Slice((*byte)(unsafe.Pointer(info)), AppendInfoSize) 67 } 68 69 func (info *appendInfo) GetDest() *common.ID { 70 return &info.dest 71 } 72 func (info *appendInfo) GetSrcOff() uint32 { 73 return info.srcOff 74 } 75 func (info *appendInfo) GetSrcLen() uint32 { 76 return info.srcLen 77 } 78 func (info *appendInfo) GetDestOff() uint32 { 79 return info.destOff 80 } 81 func (info *appendInfo) GetDestLen() uint32 { 82 return info.destLen 83 } 84 func (info *appendInfo) Desc() string { 85 return info.dest.BlockString() 86 } 87 func (info *appendInfo) String() string { 88 s := fmt.Sprintf("[From=[%d:%d];To=%s[%d:%d]]", 89 info.srcOff, info.srcLen+info.srcOff, info.dest.BlockString(), info.destOff, info.destLen+info.destOff) 90 return s 91 } 92 func (info *appendInfo) WriteTo(w io.Writer) (n int64, err error) { 93 _, err = w.Write(EncodeAppendInfo(info)) 94 n = AppendInfoSize 95 return 96 } 97 func (info *appendInfo) ReadFrom(r io.Reader) (n int64, err error) { 98 _, err = r.Read(EncodeAppendInfo(info)) 99 n = AppendInfoSize 100 return 101 } 102 103 type baseNode struct { 104 meta *catalog.ObjectEntry 105 table *txnTable 106 } 107 108 func newBaseNode( 109 tbl *txnTable, 110 meta *catalog.ObjectEntry, 111 ) *baseNode { 112 return &baseNode{ 113 meta: meta, 114 table: tbl, 115 } 116 } 117 118 func (n *baseNode) IsPersisted() bool { 119 return n.meta.HasPersistedData() 120 } 121 122 func (n *baseNode) GetTxn() txnif.AsyncTxn { 123 return n.table.store.txn 124 }