github.com/matrixorigin/matrixone@v0.7.0/pkg/vm/engine/tae/options/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 options
    16  
    17  import (
    18  	"runtime"
    19  	"time"
    20  
    21  	"github.com/matrixorigin/matrixone/pkg/txn/clock"
    22  )
    23  
    24  func WithTransferTableTTL(ttl time.Duration) func(*Options) {
    25  	return func(opts *Options) {
    26  		opts.TransferTableTTL = ttl
    27  	}
    28  }
    29  
    30  func WithCheckpointMinCount(count int64) func(*Options) {
    31  	return func(opts *Options) {
    32  		if opts.CheckpointCfg == nil {
    33  			opts.CheckpointCfg = new(CheckpointCfg)
    34  		}
    35  		opts.CheckpointCfg.MinCount = count
    36  	}
    37  }
    38  
    39  func WithFlushInterval(interval time.Duration) func(*Options) {
    40  	return func(opts *Options) {
    41  		if opts.CheckpointCfg == nil {
    42  			opts.CheckpointCfg = new(CheckpointCfg)
    43  		}
    44  		opts.CheckpointCfg.FlushInterval = interval
    45  	}
    46  }
    47  
    48  func WithCheckpointScanInterval(interval time.Duration) func(*Options) {
    49  	return func(opts *Options) {
    50  		if opts.CheckpointCfg == nil {
    51  			opts.CheckpointCfg = new(CheckpointCfg)
    52  		}
    53  		opts.CheckpointCfg.ScanInterval = interval
    54  	}
    55  }
    56  
    57  func WithCheckpointIncrementaInterval(interval time.Duration) func(*Options) {
    58  	return func(opts *Options) {
    59  		if opts.CheckpointCfg == nil {
    60  			opts.CheckpointCfg = new(CheckpointCfg)
    61  		}
    62  		opts.CheckpointCfg.IncrementalInterval = interval
    63  	}
    64  }
    65  
    66  func WithCheckpointGlobalMinCount(count int64) func(*Options) {
    67  	return func(opts *Options) {
    68  		if opts.CheckpointCfg == nil {
    69  			opts.CheckpointCfg = new(CheckpointCfg)
    70  		}
    71  		opts.CheckpointCfg.GlobalMinCount = count
    72  	}
    73  }
    74  
    75  func WithGlobalVersionInterval(interval time.Duration) func(*Options) {
    76  	return func(opts *Options) {
    77  		if opts.CheckpointCfg == nil {
    78  			opts.CheckpointCfg = new(CheckpointCfg)
    79  		}
    80  		opts.CheckpointCfg.GlobalVersionInterval = interval
    81  	}
    82  }
    83  
    84  func WithGCCheckpointInterval(interval time.Duration) func(*Options) {
    85  	return func(opts *Options) {
    86  		if opts.CheckpointCfg == nil {
    87  			opts.CheckpointCfg = new(CheckpointCfg)
    88  		}
    89  		opts.CheckpointCfg.GCCheckpointInterval = interval
    90  	}
    91  }
    92  
    93  func WithDisableGCCheckpoint() func(*Options) {
    94  	return func(opts *Options) {
    95  		if opts.CheckpointCfg == nil {
    96  			opts.CheckpointCfg = new(CheckpointCfg)
    97  		}
    98  		opts.CheckpointCfg.DisableGCCheckpoint = true
    99  	}
   100  }
   101  
   102  func WithCatalogGCInterval(internal time.Duration) func(*Options) {
   103  	return func(o *Options) {
   104  		if o.CatalogCfg == nil {
   105  			o.CatalogCfg = new(CatalogCfg)
   106  		}
   107  		o.CatalogCfg.GCInterval = internal
   108  	}
   109  }
   110  
   111  func WithDisableGCCatalog() func(*Options) {
   112  	return func(o *Options) {
   113  		if o.CatalogCfg == nil {
   114  			o.CatalogCfg = new(CatalogCfg)
   115  		}
   116  		o.CatalogCfg.DisableGC = true
   117  	}
   118  }
   119  
   120  func (o *Options) FillDefaults(dirname string) *Options {
   121  	if o == nil {
   122  		o = &Options{}
   123  	}
   124  
   125  	if o.TransferTableTTL == time.Duration(0) {
   126  		o.TransferTableTTL = time.Second * 120
   127  	}
   128  
   129  	if o.CacheCfg == nil {
   130  		o.CacheCfg = &CacheCfg{
   131  			IndexCapacity:  DefaultIndexCacheSize,
   132  			InsertCapacity: DefaultMTCacheSize,
   133  			TxnCapacity:    DefaultTxnCacheSize,
   134  		}
   135  	}
   136  
   137  	if o.StorageCfg == nil {
   138  		o.StorageCfg = &StorageCfg{
   139  			BlockMaxRows:     DefaultBlockMaxRows,
   140  			SegmentMaxBlocks: DefaultBlocksPerSegment,
   141  		}
   142  	}
   143  
   144  	if o.CheckpointCfg == nil {
   145  		o.CheckpointCfg = new(CheckpointCfg)
   146  	}
   147  	if o.CheckpointCfg.ScanInterval <= 0 {
   148  		o.CheckpointCfg.ScanInterval = DefaultScannerInterval
   149  	}
   150  	if o.CheckpointCfg.FlushInterval <= 0 {
   151  		o.CheckpointCfg.FlushInterval = DefaultCheckpointFlushInterval
   152  	}
   153  	if o.CheckpointCfg.IncrementalInterval <= 0 {
   154  		o.CheckpointCfg.IncrementalInterval = DefaultCheckpointIncremetalInterval
   155  	}
   156  	if o.CheckpointCfg.GlobalMinCount <= 0 {
   157  		o.CheckpointCfg.GlobalMinCount = DefaultCheckpointMinCount
   158  	}
   159  	if o.CheckpointCfg.MinCount <= 0 {
   160  		o.CheckpointCfg.MinCount = DefaultCheckpointMinCount
   161  	}
   162  	if o.CheckpointCfg.GlobalVersionInterval <= 0 {
   163  		o.CheckpointCfg.GlobalVersionInterval = DefaultGlobalVersionInterval
   164  	}
   165  	if o.CheckpointCfg.GCCheckpointInterval <= 0 {
   166  		o.CheckpointCfg.GCCheckpointInterval = DefaultGCCheckpointInterval
   167  	}
   168  
   169  	if o.CatalogCfg == nil {
   170  		o.CatalogCfg = new(CatalogCfg)
   171  	}
   172  	if o.CatalogCfg.GCInterval <= 0 {
   173  		o.CatalogCfg.GCInterval = DefaultCatalogGCInterval
   174  	}
   175  
   176  	if o.GCCfg == nil {
   177  		o.GCCfg = new(GCCfg)
   178  	}
   179  
   180  	if o.GCCfg.GCTTL <= 0 {
   181  		o.GCCfg.GCTTL = DefaultGCTTL
   182  	}
   183  
   184  	if o.GCCfg.ScanGCInterval <= 0 {
   185  		o.GCCfg.ScanGCInterval = DefaultScanGCInterval
   186  	}
   187  
   188  	if o.SchedulerCfg == nil {
   189  		ioworkers := DefaultIOWorkers
   190  		if ioworkers < runtime.NumCPU() {
   191  			ioworkers = runtime.NumCPU()
   192  		}
   193  		o.SchedulerCfg = &SchedulerCfg{
   194  			IOWorkers:    ioworkers,
   195  			AsyncWorkers: DefaultAsyncWorkers,
   196  		}
   197  	}
   198  
   199  	if o.Clock == nil {
   200  		o.Clock = clock.NewHLCClock(func() int64 {
   201  			return time.Now().UTC().UnixNano()
   202  		}, 0)
   203  	}
   204  
   205  	if o.LogtailCfg == nil {
   206  		o.LogtailCfg = &LogtailCfg{
   207  			PageSize: DefaultLogtailTxnPageSize,
   208  		}
   209  	}
   210  
   211  	if o.LogStoreT == "" {
   212  		o.LogStoreT = DefaultLogstoreType
   213  	}
   214  
   215  	return o
   216  }