github.com/m3db/m3@v1.5.0/src/dbnode/storage/bootstrap/bootstrapper/fs/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 fs
    22  
    23  import (
    24  	"errors"
    25  	"fmt"
    26  	"math"
    27  	goruntime "runtime"
    28  
    29  	"github.com/m3db/m3/src/dbnode/persist"
    30  	"github.com/m3db/m3/src/dbnode/persist/fs"
    31  	"github.com/m3db/m3/src/dbnode/persist/fs/migration"
    32  	"github.com/m3db/m3/src/dbnode/runtime"
    33  	"github.com/m3db/m3/src/dbnode/storage"
    34  	"github.com/m3db/m3/src/dbnode/storage/bootstrap/result"
    35  	"github.com/m3db/m3/src/dbnode/storage/index"
    36  	"github.com/m3db/m3/src/dbnode/storage/index/compaction"
    37  	"github.com/m3db/m3/src/x/ident"
    38  	"github.com/m3db/m3/src/x/instrument"
    39  	"github.com/m3db/m3/src/x/pool"
    40  )
    41  
    42  var (
    43  	errPersistManagerNotSet     = errors.New("persist manager not set")
    44  	errIndexClaimsManagerNotSet = errors.New("index claims manager not set")
    45  	errCompactorNotSet          = errors.New("compactor not set")
    46  	errIndexOptionsNotSet       = errors.New("index options not set")
    47  	errFilesystemOptionsNotSet  = errors.New("filesystem options not set")
    48  	errMigrationOptionsNotSet   = errors.New("migration options not set")
    49  
    50  	// DefaultIndexSegmentConcurrency defines the default index segment building concurrency.
    51  	DefaultIndexSegmentConcurrency = int(math.Min(2, float64(goruntime.GOMAXPROCS(0))))
    52  
    53  	// defaultIndexSegmentsVerify defines default for index segments validation.
    54  	defaultIndexSegmentsVerify = false
    55  )
    56  
    57  type options struct {
    58  	instrumentOpts          instrument.Options
    59  	resultOpts              result.Options
    60  	fsOpts                  fs.Options
    61  	indexOpts               index.Options
    62  	persistManager          persist.Manager
    63  	indexClaimsManager      fs.IndexClaimsManager
    64  	compactor               *compaction.Compactor
    65  	indexSegmentConcurrency int
    66  	indexSegmentsVerify     bool
    67  	runtimeOptsMgr          runtime.OptionsManager
    68  	identifierPool          ident.Pool
    69  	migrationOpts           migration.Options
    70  	storageOpts             storage.Options
    71  }
    72  
    73  // NewOptions creates new bootstrap options
    74  func NewOptions() Options {
    75  	bytesPool := pool.NewCheckedBytesPool(nil, nil, func(s []pool.Bucket) pool.BytesPool {
    76  		return pool.NewBytesPool(s, nil)
    77  	})
    78  	bytesPool.Init()
    79  	idPool := ident.NewPool(bytesPool, ident.PoolOptions{})
    80  
    81  	return &options{
    82  		instrumentOpts:          instrument.NewOptions(),
    83  		resultOpts:              result.NewOptions(),
    84  		indexSegmentConcurrency: DefaultIndexSegmentConcurrency,
    85  		indexSegmentsVerify:     defaultIndexSegmentsVerify,
    86  		runtimeOptsMgr:          runtime.NewOptionsManager(),
    87  		identifierPool:          idPool,
    88  		migrationOpts:           migration.NewOptions(),
    89  		storageOpts:             storage.NewOptions(),
    90  	}
    91  }
    92  
    93  func (o *options) Validate() error {
    94  	if o.persistManager == nil {
    95  		return errPersistManagerNotSet
    96  	}
    97  	if o.indexClaimsManager == nil {
    98  		return errIndexClaimsManagerNotSet
    99  	}
   100  	if o.compactor == nil {
   101  		return errCompactorNotSet
   102  	}
   103  	if o.indexOpts == nil {
   104  		return errIndexOptionsNotSet
   105  	}
   106  	if o.fsOpts == nil {
   107  		return errFilesystemOptionsNotSet
   108  	}
   109  	if o.migrationOpts == nil {
   110  		return errMigrationOptionsNotSet
   111  	}
   112  	if err := o.migrationOpts.Validate(); err != nil {
   113  		return err
   114  	}
   115  	if n := o.indexSegmentConcurrency; n <= 0 {
   116  		return fmt.Errorf("index segment concurrency not >= 1: actual=%d", n)
   117  	}
   118  	return nil
   119  }
   120  
   121  func (o *options) SetInstrumentOptions(value instrument.Options) Options {
   122  	opts := *o
   123  	opts.instrumentOpts = value
   124  	return &opts
   125  }
   126  
   127  func (o *options) InstrumentOptions() instrument.Options {
   128  	return o.instrumentOpts
   129  }
   130  
   131  func (o *options) SetResultOptions(value result.Options) Options {
   132  	opts := *o
   133  	opts.resultOpts = value
   134  	return &opts
   135  }
   136  
   137  func (o *options) ResultOptions() result.Options {
   138  	return o.resultOpts
   139  }
   140  
   141  func (o *options) SetFilesystemOptions(value fs.Options) Options {
   142  	opts := *o
   143  	opts.fsOpts = value
   144  	return &opts
   145  }
   146  
   147  func (o *options) FilesystemOptions() fs.Options {
   148  	return o.fsOpts
   149  }
   150  
   151  func (o *options) SetIndexOptions(value index.Options) Options {
   152  	opts := *o
   153  	opts.indexOpts = value
   154  	return &opts
   155  }
   156  
   157  func (o *options) IndexOptions() index.Options {
   158  	return o.indexOpts
   159  }
   160  
   161  func (o *options) SetPersistManager(value persist.Manager) Options {
   162  	opts := *o
   163  	opts.persistManager = value
   164  	return &opts
   165  }
   166  
   167  func (o *options) PersistManager() persist.Manager {
   168  	return o.persistManager
   169  }
   170  
   171  func (o *options) SetIndexClaimsManager(value fs.IndexClaimsManager) Options {
   172  	opts := *o
   173  	opts.indexClaimsManager = value
   174  	return &opts
   175  }
   176  
   177  func (o *options) IndexClaimsManager() fs.IndexClaimsManager {
   178  	return o.indexClaimsManager
   179  }
   180  
   181  func (o *options) SetCompactor(value *compaction.Compactor) Options {
   182  	opts := *o
   183  	opts.compactor = value
   184  	return &opts
   185  }
   186  
   187  func (o *options) Compactor() *compaction.Compactor {
   188  	return o.compactor
   189  }
   190  
   191  func (o *options) SetIndexSegmentConcurrency(value int) Options {
   192  	opts := *o
   193  	opts.indexSegmentConcurrency = value
   194  	return &opts
   195  }
   196  
   197  func (o *options) IndexSegmentConcurrency() int {
   198  	return o.indexSegmentConcurrency
   199  }
   200  
   201  func (o *options) SetIndexSegmentsVerify(value bool) Options {
   202  	opts := *o
   203  	opts.indexSegmentsVerify = value
   204  	return &opts
   205  }
   206  
   207  func (o *options) IndexSegmentsVerify() bool {
   208  	return o.indexSegmentsVerify
   209  }
   210  
   211  func (o *options) SetRuntimeOptionsManager(value runtime.OptionsManager) Options {
   212  	opts := *o
   213  	opts.runtimeOptsMgr = value
   214  	return &opts
   215  }
   216  
   217  func (o *options) RuntimeOptionsManager() runtime.OptionsManager {
   218  	return o.runtimeOptsMgr
   219  }
   220  
   221  func (o *options) SetIdentifierPool(value ident.Pool) Options {
   222  	opts := *o
   223  	opts.identifierPool = value
   224  	return &opts
   225  }
   226  
   227  func (o *options) IdentifierPool() ident.Pool {
   228  	return o.identifierPool
   229  }
   230  
   231  func (o *options) SetMigrationOptions(value migration.Options) Options {
   232  	opts := *o
   233  	opts.migrationOpts = value
   234  	return &opts
   235  }
   236  
   237  func (o *options) MigrationOptions() migration.Options {
   238  	return o.migrationOpts
   239  }
   240  
   241  func (o *options) SetStorageOptions(value storage.Options) Options {
   242  	opts := *o
   243  	opts.storageOpts = value
   244  	return &opts
   245  }
   246  
   247  func (o *options) StorageOptions() storage.Options {
   248  	return o.storageOpts
   249  }