github.com/m3db/m3@v1.5.0/src/m3ninx/index/segment/builder/options.go (about)

     1  // Copyright (c) 2018 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 builder
    22  
    23  import (
    24  	"runtime"
    25  
    26  	"github.com/m3db/m3/src/m3ninx/postings"
    27  	"github.com/m3db/m3/src/m3ninx/postings/roaring"
    28  	"github.com/m3db/m3/src/m3ninx/util"
    29  )
    30  
    31  const (
    32  	defaultInitialCapacity = 128
    33  )
    34  
    35  var (
    36  	defaultConcurrency = runtime.GOMAXPROCS(0)
    37  )
    38  
    39  // Options is a collection of options for segment building.
    40  type Options interface {
    41  	// SetNewUUIDFn sets the function used to generate new UUIDs.
    42  	SetNewUUIDFn(value util.NewUUIDFn) Options
    43  
    44  	// NewUUIDFn returns the function used to generate new UUIDs.
    45  	NewUUIDFn() util.NewUUIDFn
    46  
    47  	// SetInitialCapacity sets the initial capacity.
    48  	SetInitialCapacity(value int) Options
    49  
    50  	// InitialCapacity returns the initial capacity.
    51  	InitialCapacity() int
    52  
    53  	// SetPostingsListPool sets the postings list pool.
    54  	SetPostingsListPool(value postings.Pool) Options
    55  
    56  	// PostingsListPool returns the postings list pool.
    57  	PostingsListPool() postings.Pool
    58  
    59  	// SetConcurrency sets the indexing concurrency.
    60  	SetConcurrency(value int) Options
    61  
    62  	// Concurrency returns the indexing concurrency.
    63  	Concurrency() int
    64  }
    65  
    66  type opts struct {
    67  	newUUIDFn       util.NewUUIDFn
    68  	initialCapacity int
    69  	postingsPool    postings.Pool
    70  	concurrency     int
    71  }
    72  
    73  // NewOptions returns new options.
    74  func NewOptions() Options {
    75  	return &opts{
    76  		newUUIDFn:       util.NewUUID,
    77  		initialCapacity: defaultInitialCapacity,
    78  		postingsPool:    postings.NewPool(nil, roaring.NewPostingsList),
    79  		concurrency:     defaultConcurrency,
    80  	}
    81  }
    82  
    83  func (o *opts) SetNewUUIDFn(v util.NewUUIDFn) Options {
    84  	opts := *o
    85  	opts.newUUIDFn = v
    86  	return &opts
    87  }
    88  
    89  func (o *opts) NewUUIDFn() util.NewUUIDFn {
    90  	return o.newUUIDFn
    91  }
    92  
    93  func (o *opts) SetInitialCapacity(v int) Options {
    94  	opts := *o
    95  	opts.initialCapacity = v
    96  	return &opts
    97  }
    98  
    99  func (o *opts) InitialCapacity() int {
   100  	return o.initialCapacity
   101  }
   102  
   103  func (o *opts) SetPostingsListPool(v postings.Pool) Options {
   104  	opts := *o
   105  	opts.postingsPool = v
   106  	return &opts
   107  }
   108  
   109  func (o *opts) PostingsListPool() postings.Pool {
   110  	return o.postingsPool
   111  }
   112  
   113  func (o *opts) SetConcurrency(v int) Options {
   114  	opts := *o
   115  	opts.concurrency = v
   116  	return &opts
   117  }
   118  
   119  func (o *opts) Concurrency() int {
   120  	return o.concurrency
   121  }