github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/tables/factory.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 tables
    16  
    17  import (
    18  	"github.com/matrixorigin/matrixone/pkg/objectio"
    19  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/buffer/base"
    20  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/catalog"
    21  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/iface/data"
    22  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/tasks"
    23  )
    24  
    25  type DataFactory struct {
    26  	AppendBufMgr base.INodeManager
    27  	Scheduler    tasks.TaskScheduler
    28  	dir          string
    29  	Fs           *objectio.ObjectFS
    30  }
    31  
    32  func NewDataFactory(fs *objectio.ObjectFS,
    33  	appendBufMgr base.INodeManager,
    34  	scheduler tasks.TaskScheduler,
    35  	dir string) *DataFactory {
    36  	return &DataFactory{
    37  		AppendBufMgr: appendBufMgr,
    38  		Scheduler:    scheduler,
    39  		dir:          dir,
    40  		Fs:           fs,
    41  	}
    42  }
    43  
    44  func (factory *DataFactory) MakeTableFactory() catalog.TableDataFactory {
    45  	return func(meta *catalog.TableEntry) data.Table {
    46  		return newTable(meta, factory.AppendBufMgr)
    47  	}
    48  }
    49  
    50  func (factory *DataFactory) MakeSegmentFactory() catalog.SegmentDataFactory {
    51  	return func(meta *catalog.SegmentEntry) data.Segment {
    52  		return newSegment(meta, factory.AppendBufMgr, factory.dir)
    53  	}
    54  }
    55  
    56  func (factory *DataFactory) MakeBlockFactory() catalog.BlockDataFactory {
    57  	return func(meta *catalog.BlockEntry) data.Block {
    58  		if meta.IsAppendable() {
    59  			return newABlock(meta, factory.Fs, factory.AppendBufMgr, factory.Scheduler)
    60  		} else {
    61  			return newBlock(meta, factory.Fs, factory.AppendBufMgr, factory.Scheduler)
    62  		}
    63  	}
    64  }