github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/disttae/cache/table_guard.go (about) 1 // Copyright 2021 - 2023 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 cache 16 17 import ( 18 "sync" 19 20 "github.com/matrixorigin/matrixone/pkg/pb/timestamp" 21 ) 22 23 // tableGuard helps to track the version of table. It is global unique and is 24 // kept in CatalogCache, which is kept in disttae.Engine. 25 type tableGuard struct { 26 mu struct { 27 sync.RWMutex 28 schema_version map[TableKey]*TableVersion 29 } 30 } 31 32 // newTableGuard creates a new tableGuard instance. 33 func newTableGuard() *tableGuard { 34 t := &tableGuard{} 35 t.mu.schema_version = make(map[TableKey]*TableVersion) 36 return t 37 } 38 39 // setSchemaVersion 40 func (g *tableGuard) setSchemaVersion(name TableKey, val *TableVersion) { 41 g.mu.Lock() 42 defer g.mu.Unlock() 43 g.mu.schema_version[name] = val 44 } 45 46 // getSchemaVersion 47 func (g *tableGuard) getSchemaVersion(name TableKey) *TableVersion { 48 g.mu.Lock() 49 defer g.mu.Unlock() 50 return g.mu.schema_version[name] 51 } 52 53 // GC do the garbage collection job for tableGuard 54 func (g *tableGuard) GC(ts timestamp.Timestamp) { 55 g.mu.Lock() 56 defer g.mu.Unlock() 57 g.mu.schema_version = make(map[TableKey]*TableVersion) 58 }