github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/testutils/config/options.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 config
    16  
    17  import (
    18  	"time"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/options"
    21  )
    22  
    23  type CacheSizeType uint8
    24  
    25  const (
    26  	CST_None CacheSizeType = iota
    27  	CST_Customize
    28  )
    29  
    30  type BlockSizeType uint8
    31  
    32  const (
    33  	BST_None BlockSizeType = iota
    34  	BST_S
    35  	BST_M
    36  	BST_L
    37  )
    38  
    39  var blockSizes map[BlockSizeType]uint32 = map[BlockSizeType]uint32{
    40  	BST_None: options.DefaultBlockMaxRows,
    41  	BST_S:    uint32(16),
    42  	BST_M:    uint32(1600),
    43  	BST_L:    uint32(160000),
    44  }
    45  
    46  type SegmentSizeType uint8
    47  
    48  const (
    49  	SST_None SegmentSizeType = iota
    50  	SST_S
    51  	SST_M
    52  	SST_L
    53  )
    54  
    55  var segmentSizes map[SegmentSizeType]uint16 = map[SegmentSizeType]uint16{
    56  	SST_None: options.DefaultBlocksPerSegment,
    57  	SST_S:    uint16(4),
    58  	SST_M:    uint16(40),
    59  	SST_L:    uint16(400),
    60  }
    61  
    62  func NewOptions(dir string, cst CacheSizeType, bst BlockSizeType, sst SegmentSizeType) *options.Options {
    63  	blockSize := blockSizes[bst]
    64  	blockCnt := segmentSizes[sst]
    65  	opts := new(options.Options)
    66  	storageCfg := new(options.StorageCfg)
    67  	storageCfg.BlockMaxRows = blockSize
    68  	storageCfg.SegmentMaxBlocks = blockCnt
    69  	opts.StorageCfg = storageCfg
    70  
    71  	if cst == CST_Customize {
    72  		cacheCfg := new(options.CacheCfg)
    73  		cacheCfg.IndexCapacity = uint64(blockSize) * uint64(blockCnt) * 80
    74  		cacheCfg.InsertCapacity = uint64(blockSize) * uint64(blockCnt) * 800
    75  		cacheCfg.TxnCapacity = uint64(blockSize) * uint64(blockCnt) * 10
    76  		opts.CacheCfg = cacheCfg
    77  	}
    78  	opts.FillDefaults(dir)
    79  	return opts
    80  }
    81  
    82  func NewCustomizedMetaOptions(dir string, cst CacheSizeType, blockRows uint32, blockCnt uint16, opts *options.Options) *options.Options {
    83  	if opts == nil {
    84  		opts = new(options.Options)
    85  	}
    86  	storageCfg := &options.StorageCfg{
    87  		BlockMaxRows:     blockRows,
    88  		SegmentMaxBlocks: blockCnt,
    89  	}
    90  	opts.StorageCfg = storageCfg
    91  	if cst == CST_Customize {
    92  		cacheCfg := new(options.CacheCfg)
    93  		cacheCfg.IndexCapacity = uint64(blockRows) * uint64(blockCnt) * 2000
    94  		cacheCfg.InsertCapacity = uint64(blockRows) * uint64(blockCnt) * 1000
    95  		cacheCfg.TxnCapacity = uint64(blockRows) * uint64(blockCnt) * 100
    96  		opts.CacheCfg = cacheCfg
    97  	}
    98  	opts.FillDefaults(dir)
    99  	return opts
   100  }
   101  
   102  func WithQuickScanAndCKPOpts2(in *options.Options, factor int) (opts *options.Options) {
   103  	opts = WithQuickScanAndCKPOpts(in)
   104  	opts.CheckpointCfg.ScanInterval *= time.Duration(factor)
   105  	opts.CheckpointCfg.FlushInterval *= time.Duration(factor)
   106  	opts.CheckpointCfg.MinCount = int64(factor)
   107  	opts.CheckpointCfg.IncrementalInterval *= time.Duration(factor)
   108  	return opts
   109  }
   110  
   111  func WithQuickScanAndCKPOpts(in *options.Options) (opts *options.Options) {
   112  	if in == nil {
   113  		opts = new(options.Options)
   114  	} else {
   115  		opts = in
   116  	}
   117  	opts.CheckpointCfg = new(options.CheckpointCfg)
   118  	opts.CheckpointCfg.ScanInterval = time.Millisecond * 10
   119  	opts.CheckpointCfg.FlushInterval = time.Millisecond * 10
   120  	opts.CheckpointCfg.MinCount = 1
   121  	opts.CheckpointCfg.IncrementalInterval = time.Millisecond * 20
   122  	opts.CheckpointCfg.GlobalMinCount = 1
   123  	opts.CheckpointCfg.GCCheckpointInterval = time.Millisecond * 10
   124  	opts.GCCfg = new(options.GCCfg)
   125  	opts.GCCfg.ScanGCInterval = time.Millisecond * 10
   126  	opts.GCCfg.GCTTL = time.Millisecond * 1
   127  	opts.CatalogCfg = new(options.CatalogCfg)
   128  	opts.CatalogCfg.GCInterval = time.Millisecond * 1
   129  	return opts
   130  }
   131  
   132  func WithQuickScanAndCKPAndGCOpts(in *options.Options) (opts *options.Options) {
   133  	if in == nil {
   134  		opts = new(options.Options)
   135  	} else {
   136  		opts = in
   137  	}
   138  	opts.CheckpointCfg = new(options.CheckpointCfg)
   139  	opts.CheckpointCfg.ScanInterval = time.Millisecond * 10
   140  	opts.CheckpointCfg.FlushInterval = time.Millisecond * 10
   141  	opts.CheckpointCfg.MinCount = 1
   142  	opts.CheckpointCfg.IncrementalInterval = time.Millisecond * 20
   143  	opts.CheckpointCfg.GlobalMinCount = 1
   144  
   145  	opts.GCCfg = new(options.GCCfg)
   146  	// ScanGCInterval does not need to be too fast, because manual gc will be performed in the case
   147  	opts.GCCfg.ScanGCInterval = time.Second * 10
   148  	opts.CatalogCfg = new(options.CatalogCfg)
   149  	opts.CatalogCfg.GCInterval = time.Millisecond * 1
   150  	opts.GCCfg.GCTTL = time.Millisecond * 1
   151  	return opts
   152  }
   153  
   154  func WithOpts(in *options.Options, factor float64) (opts *options.Options) {
   155  	if in == nil {
   156  		opts = new(options.Options)
   157  	} else {
   158  		opts = in
   159  	}
   160  	opts.CheckpointCfg = new(options.CheckpointCfg)
   161  	opts.CheckpointCfg.ScanInterval = time.Second * time.Duration(factor)
   162  	opts.CheckpointCfg.FlushInterval = time.Second * time.Duration(factor)
   163  	opts.CheckpointCfg.MinCount = 1 * int64(factor)
   164  	opts.CheckpointCfg.IncrementalInterval = time.Second * 2 * time.Duration(factor)
   165  	opts.CheckpointCfg.GlobalMinCount = 10
   166  	return opts
   167  }
   168  
   169  func WithLongScanAndCKPOpts(in *options.Options) (opts *options.Options) {
   170  	if in == nil {
   171  		opts = new(options.Options)
   172  	} else {
   173  		opts = in
   174  	}
   175  	opts.CheckpointCfg = new(options.CheckpointCfg)
   176  	opts.CheckpointCfg.ScanInterval = time.Hour
   177  	opts.CheckpointCfg.MinCount = 100000000
   178  	opts.CheckpointCfg.IncrementalInterval = time.Hour
   179  	opts.CheckpointCfg.GlobalMinCount = 10000000
   180  	return opts
   181  }