github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/tables/evictable/utils.go (about) 1 // Copyright 2022 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 evictable 16 17 import ( 18 "bytes" 19 "fmt" 20 "time" 21 22 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/buffer/base" 23 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common" 24 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers" 25 ) 26 27 const ( 28 ConstPinDuration = 5 * time.Second 29 ) 30 31 func EncodeColMetaKey(idx uint16, metaloc string) string { 32 return fmt.Sprintf("colMeta-%d-%s", idx, metaloc) 33 } 34 35 func EncodeColBfKey(idx uint16, metaloc string) string { 36 return fmt.Sprintf("colBf-%d-%s", idx, metaloc) 37 } 38 39 func EncodeColDataKey(idx uint16, metaloc string) string { 40 return fmt.Sprintf("colData-%d-%s", idx, metaloc) 41 } 42 43 func EncodeDeltaDataKey(idx uint16, deltaloc string) string { 44 return fmt.Sprintf("deltaData-%d-%s", idx, deltaloc) 45 } 46 47 func EncodeDeltaMetaKey(deltaloc string) string { 48 return fmt.Sprintf("deltaMeta-%s", deltaloc) 49 } 50 51 type EvictableNodeFactory = func() (base.INode, error) 52 53 func PinEvictableNode(mgr base.INodeManager, key string, factory EvictableNodeFactory) (base.INodeHandle, error) { 54 var h base.INodeHandle 55 var err error 56 h, err = mgr.TryPinByKey(key, ConstPinDuration) 57 if err == base.ErrNotFound { 58 node, newerr := factory() 59 if newerr != nil { 60 return nil, newerr 61 } 62 // Ignore duplicate node and TODO: maybe handle no space 63 mgr.Add(node) 64 h, err = mgr.TryPinByKey(key, ConstPinDuration) 65 } 66 return h, err 67 } 68 69 func copyVector(data containers.Vector, buf *bytes.Buffer) containers.Vector { 70 if buf != nil { 71 return containers.CloneWithBuffer(data, buf, common.DefaultAllocator) 72 } else { 73 return data.CloneWindow(0, data.Length(), common.DefaultAllocator) 74 } 75 }