github.com/m3db/m3@v1.5.0/src/dbnode/storage/bootstrap/bootstrapper/commitlog/options.go (about)

     1  // Copyright (c) 2016 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package commitlog
    22  
    23  import (
    24  	"errors"
    25  	"math"
    26  	goruntime "runtime"
    27  
    28  	"github.com/m3db/m3/src/dbnode/persist/fs/commitlog"
    29  	"github.com/m3db/m3/src/dbnode/runtime"
    30  	"github.com/m3db/m3/src/dbnode/storage/bootstrap/result"
    31  )
    32  
    33  const (
    34  	// DefaultReturnUnfulfilledForCorruptCommitLogFiles is the default
    35  	// value for whether to return unfulfilled when encountering corrupt
    36  	// commit log files.
    37  	DefaultReturnUnfulfilledForCorruptCommitLogFiles = false
    38  )
    39  
    40  var (
    41  	errAccumulateConcurrencyPositive = errors.New("accumulate concurrency must be positive")
    42  	errRuntimeOptsMgrNotSet          = errors.New("runtime options manager is not set")
    43  
    44  	// defaultAccumulateConcurrency determines how fast to accumulate results.
    45  	defaultAccumulateConcurrency = int(math.Max(float64(goruntime.GOMAXPROCS(0))*0.75, 1))
    46  )
    47  
    48  type options struct {
    49  	resultOpts                                result.Options
    50  	commitLogOpts                             commitlog.Options
    51  	accumulateConcurrency                     int
    52  	runtimeOptsMgr                            runtime.OptionsManager
    53  	returnUnfulfilledForCorruptCommitLogFiles bool
    54  }
    55  
    56  // NewOptions creates new bootstrap options
    57  func NewOptions() Options {
    58  	return &options{
    59  		resultOpts:            result.NewOptions(),
    60  		commitLogOpts:         commitlog.NewOptions(),
    61  		accumulateConcurrency: defaultAccumulateConcurrency,
    62  		returnUnfulfilledForCorruptCommitLogFiles: DefaultReturnUnfulfilledForCorruptCommitLogFiles,
    63  	}
    64  }
    65  
    66  func (o *options) Validate() error {
    67  	if o.accumulateConcurrency <= 0 {
    68  		return errAccumulateConcurrencyPositive
    69  	}
    70  	if o.runtimeOptsMgr == nil {
    71  		return errRuntimeOptsMgrNotSet
    72  	}
    73  	return o.commitLogOpts.Validate()
    74  }
    75  
    76  func (o *options) SetResultOptions(value result.Options) Options {
    77  	opts := *o
    78  	opts.resultOpts = value
    79  	return &opts
    80  }
    81  
    82  func (o *options) ResultOptions() result.Options {
    83  	return o.resultOpts
    84  }
    85  
    86  func (o *options) SetCommitLogOptions(value commitlog.Options) Options {
    87  	opts := *o
    88  	opts.commitLogOpts = value
    89  	return &opts
    90  }
    91  
    92  func (o *options) CommitLogOptions() commitlog.Options {
    93  	return o.commitLogOpts
    94  }
    95  
    96  func (o *options) SetAccumulateConcurrency(value int) Options {
    97  	opts := *o
    98  	opts.accumulateConcurrency = value
    99  	return &opts
   100  }
   101  
   102  func (o *options) AccumulateConcurrency() int {
   103  	return o.accumulateConcurrency
   104  }
   105  
   106  func (o *options) SetRuntimeOptionsManager(value runtime.OptionsManager) Options {
   107  	opts := *o
   108  	opts.runtimeOptsMgr = value
   109  	return &opts
   110  }
   111  
   112  func (o *options) RuntimeOptionsManager() runtime.OptionsManager {
   113  	return o.runtimeOptsMgr
   114  }
   115  
   116  func (o *options) SetReturnUnfulfilledForCorruptCommitLogFiles(value bool) Options {
   117  	opts := *o
   118  	opts.returnUnfulfilledForCorruptCommitLogFiles = value
   119  	return &opts
   120  }
   121  
   122  func (o *options) ReturnUnfulfilledForCorruptCommitLogFiles() bool {
   123  	return o.returnUnfulfilledForCorruptCommitLogFiles
   124  }