github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/catalog/basemvccnode.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 catalog 16 17 import ( 18 "encoding/binary" 19 "fmt" 20 "io" 21 22 "github.com/matrixorigin/matrixone/pkg/container/types" 23 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/txnif" 24 ) 25 26 type EntryMVCCNode struct { 27 CreatedAt, DeletedAt types.TS 28 } 29 30 // Dropped committed 31 func (un *EntryMVCCNode) HasDropCommitted() bool { 32 return !un.DeletedAt.IsEmpty() && un.DeletedAt != txnif.UncommitTS 33 } 34 35 // Dropped committed or uncommitted 36 func (un *EntryMVCCNode) HasDropIntent() bool { 37 return !un.DeletedAt.IsEmpty() 38 } 39 40 func (un *EntryMVCCNode) GetCreatedAt() types.TS { 41 return un.CreatedAt 42 } 43 44 func (un *EntryMVCCNode) GetDeletedAt() types.TS { 45 return un.DeletedAt 46 } 47 48 func (un *EntryMVCCNode) IsCreating() bool { 49 return un.CreatedAt.Equal(txnif.UncommitTS) 50 } 51 52 func (un *EntryMVCCNode) Clone() *EntryMVCCNode { 53 return &EntryMVCCNode{ 54 CreatedAt: un.CreatedAt, 55 DeletedAt: un.DeletedAt, 56 } 57 } 58 59 func (un *EntryMVCCNode) CloneData() *EntryMVCCNode { 60 return &EntryMVCCNode{ 61 CreatedAt: un.CreatedAt, 62 DeletedAt: un.DeletedAt, 63 } 64 } 65 66 func (un *EntryMVCCNode) Delete() { 67 un.DeletedAt = txnif.UncommitTS 68 } 69 70 func (un *EntryMVCCNode) ReadFrom(r io.Reader) (n int64, err error) { 71 if err = binary.Read(r, binary.BigEndian, &un.CreatedAt); err != nil { 72 return 73 } 74 n += 12 75 if err = binary.Read(r, binary.BigEndian, &un.DeletedAt); err != nil { 76 return 77 } 78 n += 12 79 return 80 } 81 func (un *EntryMVCCNode) WriteTo(w io.Writer) (n int64, err error) { 82 if err = binary.Write(w, binary.BigEndian, un.CreatedAt); err != nil { 83 return 84 } 85 n += 12 86 if err = binary.Write(w, binary.BigEndian, un.DeletedAt); err != nil { 87 return 88 } 89 n += 12 90 return 91 } 92 func (un *EntryMVCCNode) PrepareCommit() (err error) { 93 return nil 94 } 95 func (un *EntryMVCCNode) String() string { 96 return fmt.Sprintf("[C@%s,D@%s]", un.CreatedAt.ToString(), un.DeletedAt.ToString()) 97 } 98 func (un *EntryMVCCNode) ApplyCommit(ts types.TS) (err error) { 99 if un.CreatedAt == txnif.UncommitTS { 100 un.CreatedAt = ts 101 } 102 if un.DeletedAt == txnif.UncommitTS { 103 un.DeletedAt = ts 104 } 105 return nil 106 }