github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/logtail/reader.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 logtail 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/container/types" 19 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common" 20 ) 21 22 type Reader struct { 23 from, to types.TS 24 table *TxnTable 25 } 26 27 func (r *Reader) GetDirty() (tree *common.Tree, count int) { 28 tree = common.NewTree() 29 op := func(row RowT) (moveOn bool) { 30 if memo := row.GetMemo(); memo.HasAnyTableDataChanges() { 31 tree.Merge(memo.GetDirty()) 32 } 33 count++ 34 return true 35 } 36 r.table.ForeachRowInBetween(r.from, r.to, nil, op) 37 return 38 } 39 40 func (r *Reader) HasCatalogChanges() bool { 41 changed := false 42 op := func(row RowT) (moveOn bool) { 43 if row.GetMemo().HasCatalogChanges() { 44 changed = true 45 return false 46 } 47 return true 48 } 49 skipFn := func(blk BlockT) bool { 50 summary := blk.summary.Load() 51 return summary != nil && !summary.hasCatalogChanges 52 } 53 r.table.ForeachRowInBetween(r.from, r.to, skipFn, op) 54 return changed 55 } 56 57 func (r *Reader) GetDirtyByTable( 58 dbID, id uint64, 59 ) (tree *common.TableTree) { 60 tree = common.NewTableTree(dbID, id) 61 op := func(row RowT) (moveOn bool) { 62 if memo := row.GetMemo(); memo.HasTableDataChanges(id) { 63 tree.Merge(memo.GetDirtyTableByID(id)) 64 } 65 return true 66 } 67 r.table.ForeachRowInBetween(r.from, r.to, nil, op) 68 return 69 } 70 71 // TODO: optimize 72 func (r *Reader) GetMaxLSN() (maxLsn uint64) { 73 r.table.ForeachRowInBetween( 74 r.from, 75 r.to, 76 nil, 77 func(row RowT) (moveOn bool) { 78 lsn := row.GetLSN() 79 if lsn > maxLsn { 80 maxLsn = lsn 81 } 82 return true 83 }) 84 return 85 }