github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/model/pages.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 model 16 17 import ( 18 "bytes" 19 "fmt" 20 "time" 21 22 "github.com/matrixorigin/matrixone/pkg/container/types" 23 "github.com/matrixorigin/matrixone/pkg/logutil" 24 "github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common" 25 ) 26 27 type HashPageTable = TransferTable[*TransferHashPage] 28 29 type TransferHashPage struct { 30 common.RefHelper 31 bornTS time.Time 32 id *common.ID 33 hashmap map[uint32]types.Rowid 34 } 35 36 func NewTransferHashPage(id *common.ID, ts time.Time) *TransferHashPage { 37 page := &TransferHashPage{ 38 bornTS: ts, 39 id: id, 40 hashmap: make(map[uint32]types.Rowid), 41 } 42 page.OnZeroCB = page.Close 43 return page 44 } 45 46 func (page *TransferHashPage) ID() *common.ID { return page.id } 47 func (page *TransferHashPage) BornTS() time.Time { return page.bornTS } 48 49 func (page *TransferHashPage) TTL(now time.Time, ttl time.Duration) bool { 50 return now.After(page.bornTS.Add(ttl)) 51 } 52 53 func (page *TransferHashPage) Close() { 54 logutil.Infof("Closing %s", page.String()) 55 page.hashmap = make(map[uint32]types.Rowid) 56 } 57 58 func (page *TransferHashPage) String() string { 59 var w bytes.Buffer 60 _, _ = w.WriteString(fmt.Sprintf("hashpage[%s][%s][Len=%d]", 61 page.id.BlockString(), 62 page.bornTS.String(), 63 len(page.hashmap))) 64 return w.String() 65 } 66 67 func (page *TransferHashPage) Pin() *common.PinnedItem[*TransferHashPage] { 68 page.Ref() 69 return &common.PinnedItem[*TransferHashPage]{ 70 Val: page, 71 } 72 } 73 74 func (page *TransferHashPage) Train(from uint32, to types.Rowid) { 75 page.hashmap[from] = to 76 } 77 78 func (page *TransferHashPage) Transfer(from uint32) (dest types.Rowid, ok bool) { 79 dest, ok = page.hashmap[from] 80 return 81 }