github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/tables/evictable/colmeta.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  
    20  	"github.com/matrixorigin/matrixone/pkg/container/types"
    21  	"github.com/matrixorigin/matrixone/pkg/objectio"
    22  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/buffer"
    23  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/buffer/base"
    24  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/dataio/blockio"
    25  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/index"
    26  )
    27  
    28  type ColumnMetaNode struct {
    29  	*buffer.Node
    30  	// data
    31  	objectio.ColumnObject
    32  	Zonemap *index.ZoneMap
    33  	typ     types.Type
    34  	// the index number of the column
    35  	idx     uint16
    36  	metaloc string
    37  	fs      *objectio.ObjectFS
    38  }
    39  
    40  func NewColumnMetaNode(
    41  	idx uint16,
    42  	typ types.Type,
    43  	metaloc string,
    44  	metaKey string,
    45  	mgr base.INodeManager,
    46  	fs *objectio.ObjectFS) *ColumnMetaNode {
    47  	node := &ColumnMetaNode{
    48  		idx:     idx,
    49  		metaloc: metaloc,
    50  		typ:     typ,
    51  		fs:      fs,
    52  	}
    53  	_, ext, _ := blockio.DecodeMetaLoc(metaloc)
    54  	baseNode := buffer.NewNode(node, mgr, metaKey, uint64(ext.OriginSize()))
    55  	node.Node = baseNode
    56  	node.LoadFunc = node.onLoad
    57  	node.UnloadFunc = node.onUnLoad
    58  	node.HardEvictableFunc = func() bool { return true }
    59  	return node
    60  }
    61  
    62  func (n *ColumnMetaNode) onLoad() {
    63  	if n.ColumnObject != nil {
    64  		return
    65  	}
    66  	// Do IO, fetch columnData
    67  	reader, err := blockio.NewReader(context.Background(), n.fs, n.metaloc)
    68  	if err != nil {
    69  		panic(err)
    70  	}
    71  	meta := reader.GetDataObject(n.idx, nil)
    72  	n.ColumnObject = meta
    73  
    74  	// deserialize zonemap
    75  	zmData, err := meta.GetIndex(context.Background(), objectio.ZoneMapType, nil)
    76  
    77  	// TODOa: Error Handling?
    78  	if err != nil {
    79  		panic(err)
    80  	}
    81  	data := zmData.(*objectio.ZoneMap)
    82  	n.Zonemap = index.NewZoneMap(n.typ)
    83  	err = n.Zonemap.Unmarshal(data.GetData())
    84  	if err != nil {
    85  		panic(err)
    86  	}
    87  }
    88  
    89  func (n *ColumnMetaNode) onUnLoad() {
    90  	n.Zonemap = nil
    91  	n.ColumnObject = nil
    92  }