github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/tables/evictable/deltameta.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  	"context"
    19  	"github.com/matrixorigin/matrixone/pkg/objectio"
    20  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/buffer"
    21  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/buffer/base"
    22  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/dataio/blockio"
    23  )
    24  
    25  type DeltaMetaNode struct {
    26  	*buffer.Node
    27  	// data
    28  	objectio.BlockObject
    29  	// used to load data
    30  	fs       *objectio.ObjectFS
    31  	deltaloc string
    32  }
    33  
    34  func NewDeltaMetaNode(mgr base.INodeManager, metaKey string, fs *objectio.ObjectFS, deltaloc string) *DeltaMetaNode {
    35  	node := &DeltaMetaNode{
    36  		fs:       fs,
    37  		deltaloc: deltaloc,
    38  	}
    39  	_, ext, _ := blockio.DecodeMetaLoc(deltaloc)
    40  	baseNode := buffer.NewNode(node, mgr, metaKey, uint64(ext.OriginSize()))
    41  	node.Node = baseNode
    42  	node.LoadFunc = node.onLoad
    43  	node.UnloadFunc = node.onUnLoad
    44  	node.HardEvictableFunc = func() bool { return true }
    45  	return node
    46  }
    47  
    48  func (n *DeltaMetaNode) onLoad() {
    49  	if n.BlockObject != nil {
    50  		return
    51  	}
    52  	// Do IO, fetch columnData
    53  	reader, err := blockio.NewReader(context.Background(), n.fs, n.deltaloc)
    54  	if err != nil {
    55  		panic(err)
    56  	}
    57  	meta, err := reader.ReadMeta(nil)
    58  	if err != nil {
    59  		panic(err)
    60  	}
    61  	n.BlockObject = meta
    62  }
    63  
    64  func (n *DeltaMetaNode) onUnLoad() {
    65  	n.BlockObject = nil
    66  }