github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/logtail/mgr.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 "context" 19 20 "github.com/matrixorigin/matrixone/pkg/container/types" 21 "github.com/matrixorigin/matrixone/pkg/logutil" 22 "github.com/matrixorigin/matrixone/pkg/txn/clock" 23 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/catalog" 24 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/txnif" 25 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/txn/txnbase" 26 "go.uber.org/zap" 27 ) 28 29 type Manager struct { 30 txnbase.NoopCommitListener 31 table *TxnTable 32 truncated types.TS 33 } 34 35 func NewManager(blockSize int, clock clock.Clock) *Manager { 36 tsAlloc := types.NewTsAlloctor(clock) 37 return &Manager{ 38 table: NewTxnTable( 39 blockSize, 40 tsAlloc, 41 ), 42 } 43 } 44 45 func (mgr *Manager) OnEndPrePrepare(txn txnif.AsyncTxn) { 46 mgr.table.AddTxn(txn) 47 } 48 49 func (mgr *Manager) GetReader(from, to types.TS) *Reader { 50 return &Reader{ 51 from: from, 52 to: to, 53 table: mgr.table, 54 } 55 } 56 57 func (mgr *Manager) GCByTS(ctx context.Context, ts types.TS) { 58 if ts.Equal(mgr.truncated) { 59 return 60 } 61 mgr.truncated = ts 62 cnt := mgr.table.TruncateByTimeStamp(ts) 63 logutil.Info("[logtail] GC", zap.String("ts", ts.ToString()), zap.Int("deleted", cnt)) 64 } 65 66 func (mgr *Manager) GetTableOperator( 67 from, to types.TS, 68 catalog *catalog.Catalog, 69 dbID, tableID uint64, 70 scope Scope, 71 visitor catalog.Processor, 72 ) *BoundTableOperator { 73 reader := mgr.GetReader(from, to) 74 return NewBoundTableOperator( 75 catalog, 76 reader, 77 scope, 78 dbID, 79 tableID, 80 visitor, 81 ) 82 }