github.com/matrixorigin/matrixone@v1.2.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  	"context"
    19  	"runtime"
    20  	"time"
    21  
    22  	"github.com/matrixorigin/matrixone/pkg/txn/clock"
    23  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/common"
    24  )
    25  
    26  func WithTransferTableTTL(ttl time.Duration) func(*Options) {
    27  	return func(opts *Options) {
    28  		opts.TransferTableTTL = ttl
    29  	}
    30  }
    31  
    32  func WithCheckpointMinCount(count int64) func(*Options) {
    33  	return func(opts *Options) {
    34  		if opts.CheckpointCfg == nil {
    35  			opts.CheckpointCfg = new(CheckpointCfg)
    36  		}
    37  		opts.CheckpointCfg.MinCount = count
    38  	}
    39  }
    40  
    41  func WithFlushInterval(interval time.Duration) func(*Options) {
    42  	return func(opts *Options) {
    43  		if opts.CheckpointCfg == nil {
    44  			opts.CheckpointCfg = new(CheckpointCfg)
    45  		}
    46  		opts.CheckpointCfg.FlushInterval = interval
    47  	}
    48  }
    49  
    50  func WithCheckpointScanInterval(interval time.Duration) func(*Options) {
    51  	return func(opts *Options) {
    52  		if opts.CheckpointCfg == nil {
    53  			opts.CheckpointCfg = new(CheckpointCfg)
    54  		}
    55  		opts.CheckpointCfg.ScanInterval = interval
    56  	}
    57  }
    58  
    59  func WithCheckpointIncrementaInterval(interval time.Duration) func(*Options) {
    60  	return func(opts *Options) {
    61  		if opts.CheckpointCfg == nil {
    62  			opts.CheckpointCfg = new(CheckpointCfg)
    63  		}
    64  		opts.CheckpointCfg.IncrementalInterval = interval
    65  	}
    66  }
    67  
    68  func WithCheckpointGlobalMinCount(count int64) func(*Options) {
    69  	return func(opts *Options) {
    70  		if opts.CheckpointCfg == nil {
    71  			opts.CheckpointCfg = new(CheckpointCfg)
    72  		}
    73  		opts.CheckpointCfg.GlobalMinCount = count
    74  	}
    75  }
    76  
    77  func WithGlobalVersionInterval(interval time.Duration) func(*Options) {
    78  	return func(opts *Options) {
    79  		if opts.CheckpointCfg == nil {
    80  			opts.CheckpointCfg = new(CheckpointCfg)
    81  		}
    82  		opts.CheckpointCfg.GlobalVersionInterval = interval
    83  	}
    84  }
    85  
    86  func WithGCCheckpointInterval(interval time.Duration) func(*Options) {
    87  	return func(opts *Options) {
    88  		if opts.CheckpointCfg == nil {
    89  			opts.CheckpointCfg = new(CheckpointCfg)
    90  		}
    91  		opts.CheckpointCfg.GCCheckpointInterval = interval
    92  	}
    93  }
    94  
    95  func WithDisableGCCheckpoint() func(*Options) {
    96  	return func(opts *Options) {
    97  		if opts.CheckpointCfg == nil {
    98  			opts.CheckpointCfg = new(CheckpointCfg)
    99  		}
   100  		opts.CheckpointCfg.DisableGCCheckpoint = true
   101  	}
   102  }
   103  
   104  func WithCatalogGCInterval(internal time.Duration) func(*Options) {
   105  	return func(o *Options) {
   106  		if o.CatalogCfg == nil {
   107  			o.CatalogCfg = new(CatalogCfg)
   108  		}
   109  		o.CatalogCfg.GCInterval = internal
   110  	}
   111  }
   112  
   113  func WithDisableGCCatalog() func(*Options) {
   114  	return func(o *Options) {
   115  		if o.CatalogCfg == nil {
   116  			o.CatalogCfg = new(CatalogCfg)
   117  		}
   118  		o.CatalogCfg.DisableGC = true
   119  	}
   120  }
   121  
   122  func WithReserveWALEntryCount(count uint64) func(*Options) {
   123  	return func(r *Options) {
   124  		r.CheckpointCfg.ReservedWALEntryCount = count
   125  	}
   126  }
   127  
   128  func (o *Options) FillDefaults(dirname string) *Options {
   129  	if o == nil {
   130  		o = &Options{}
   131  	}
   132  
   133  	if o.TransferTableTTL == time.Duration(0) {
   134  		o.TransferTableTTL = time.Second * 90
   135  	}
   136  
   137  	if o.StorageCfg == nil {
   138  		o.StorageCfg = &StorageCfg{
   139  			BlockMaxRows:    DefaultBlockMaxRows,
   140  			ObjectMaxBlocks: DefaultBlocksPerObject,
   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.OverallFlushMemControl <= 0 {
   160  		o.CheckpointCfg.OverallFlushMemControl = DefaultOverallFlushMemControl
   161  	}
   162  	if o.CheckpointCfg.MinCount <= 0 {
   163  		o.CheckpointCfg.MinCount = DefaultCheckpointMinCount
   164  	}
   165  	if o.CheckpointCfg.GlobalVersionInterval <= 0 {
   166  		o.CheckpointCfg.GlobalVersionInterval = DefaultGlobalVersionInterval
   167  	}
   168  	if o.CheckpointCfg.GCCheckpointInterval <= 0 {
   169  		o.CheckpointCfg.GCCheckpointInterval = DefaultGCCheckpointInterval
   170  	}
   171  
   172  	if o.MergeCfg == nil {
   173  		o.MergeCfg = new(MergeConfig)
   174  	}
   175  	if o.MergeCfg.CNMergeMemControlHint == 0 {
   176  		o.MergeCfg.CNMergeMemControlHint = common.DefaultCNMergeMemControlHint * common.Const1MBytes
   177  	}
   178  
   179  	if o.MergeCfg.CNTakeOverExceed == 0 {
   180  		o.MergeCfg.CNTakeOverExceed = common.DefaultMinCNMergeSize * common.Const1MBytes
   181  	}
   182  
   183  	if o.CatalogCfg == nil {
   184  		o.CatalogCfg = new(CatalogCfg)
   185  	}
   186  	if o.CatalogCfg.GCInterval <= 0 {
   187  		o.CatalogCfg.GCInterval = DefaultCatalogGCInterval
   188  	}
   189  
   190  	if o.GCCfg == nil {
   191  		o.GCCfg = new(GCCfg)
   192  	}
   193  
   194  	if o.GCCfg.GCTTL <= 0 {
   195  		o.GCCfg.GCTTL = DefaultGCTTL
   196  	}
   197  
   198  	if o.GCCfg.ScanGCInterval <= 0 {
   199  		o.GCCfg.ScanGCInterval = DefaultScanGCInterval
   200  	}
   201  
   202  	if o.SchedulerCfg == nil {
   203  		ioworkers := DefaultIOWorkers
   204  		procs := runtime.GOMAXPROCS(0)
   205  		if ioworkers < procs {
   206  			ioworkers = min(procs, 100)
   207  		}
   208  		workers := min(procs/2, 100)
   209  		if workers < 1 {
   210  			workers = 1
   211  		}
   212  		o.SchedulerCfg = &SchedulerCfg{
   213  			IOWorkers:    ioworkers,
   214  			AsyncWorkers: workers,
   215  		}
   216  	}
   217  
   218  	if o.Clock == nil {
   219  		o.Clock = clock.NewHLCClock(func() int64 {
   220  			return time.Now().UTC().UnixNano()
   221  		}, 0)
   222  	}
   223  
   224  	if o.LogtailCfg == nil {
   225  		o.LogtailCfg = &LogtailCfg{
   226  			PageSize: DefaultLogtailTxnPageSize,
   227  		}
   228  	}
   229  
   230  	if o.LogStoreT == "" {
   231  		o.LogStoreT = DefaultLogstoreType
   232  	}
   233  
   234  	if o.Ctx == nil {
   235  		o.Ctx = context.Background()
   236  	}
   237  
   238  	return o
   239  }