github.com/m3db/m3@v1.5.0/src/dbnode/storage/bootstrap/bootstrapper/noop.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 bootstrapper
    22  
    23  import (
    24  	"fmt"
    25  
    26  	"github.com/m3db/m3/src/dbnode/storage/bootstrap"
    27  	"github.com/m3db/m3/src/x/context"
    28  )
    29  
    30  const (
    31  	// NoOpNoneBootstrapperName is the name of the noOpNoneBootstrapper
    32  	NoOpNoneBootstrapperName = "noop-none"
    33  
    34  	// NoOpAllBootstrapperName is the name of the noOpAllBootstrapperProvider
    35  	NoOpAllBootstrapperName = "noop-all"
    36  )
    37  
    38  // noOpNoneBootstrapperProvider is the no-op bootstrapper provider that doesn't
    39  // know how to bootstrap any time ranges.
    40  type noOpNoneBootstrapperProvider struct{}
    41  
    42  // NewNoOpNoneBootstrapperProvider creates a new noOpNoneBootstrapper.
    43  func NewNoOpNoneBootstrapperProvider() bootstrap.BootstrapperProvider {
    44  	return noOpNoneBootstrapperProvider{}
    45  }
    46  
    47  func (noop noOpNoneBootstrapperProvider) Provide() (bootstrap.Bootstrapper, error) {
    48  	return noOpNoneBootstrapper{}, nil
    49  }
    50  
    51  func (noop noOpNoneBootstrapperProvider) String() string {
    52  	return NoOpNoneBootstrapperName
    53  }
    54  
    55  // Compilation of this statement ensures struct implements the interface.
    56  var _ bootstrap.Bootstrapper = noOpNoneBootstrapper{}
    57  
    58  type noOpNoneBootstrapper struct{}
    59  
    60  func (noop noOpNoneBootstrapper) String() string {
    61  	return NoOpNoneBootstrapperName
    62  }
    63  
    64  func (noop noOpNoneBootstrapper) Bootstrap(
    65  	_ context.Context,
    66  	namespaces bootstrap.Namespaces,
    67  	_ bootstrap.Cache,
    68  ) (bootstrap.NamespaceResults, error) {
    69  	results := bootstrap.NewNamespaceResults(namespaces)
    70  	for _, elem := range results.Results.Iter() {
    71  		id := elem.Key()
    72  		namespace := elem.Value()
    73  
    74  		requested, ok := namespaces.Namespaces.Get(id)
    75  		if !ok {
    76  			return bootstrap.NamespaceResults{},
    77  				fmt.Errorf("missing request namespace: %s", id.String())
    78  		}
    79  
    80  		// Set everything as unfulfilled.
    81  		shardTimeRanges := requested.DataRunOptions.ShardTimeRanges
    82  		namespace.DataResult = shardTimeRanges.ToUnfulfilledDataResult()
    83  
    84  		if namespace.Metadata.Options().IndexOptions().Enabled() {
    85  			shardTimeRanges := requested.IndexRunOptions.ShardTimeRanges
    86  			namespace.IndexResult = shardTimeRanges.ToUnfulfilledIndexResult()
    87  		}
    88  
    89  		// Set value after modifications (map is by value).
    90  		results.Results.Set(id, namespace)
    91  	}
    92  
    93  	return results, nil
    94  }
    95  
    96  // noOpAllBootstrapperProvider is the no-op bootstrapper provider that pretends
    97  // it can bootstrap any time ranges.
    98  type noOpAllBootstrapperProvider struct{}
    99  
   100  // NewNoOpAllBootstrapperProvider creates a new noOpAllBootstrapperProvider.
   101  func NewNoOpAllBootstrapperProvider() bootstrap.BootstrapperProvider {
   102  	return noOpAllBootstrapperProvider{}
   103  }
   104  
   105  func (noop noOpAllBootstrapperProvider) Provide() (bootstrap.Bootstrapper, error) {
   106  	return noOpAllBootstrapper{}, nil
   107  }
   108  
   109  func (noop noOpAllBootstrapperProvider) String() string {
   110  	return NoOpAllBootstrapperName
   111  }
   112  
   113  // Compilation of this statement ensures struct implements the interface.
   114  var _ bootstrap.Bootstrapper = noOpAllBootstrapper{}
   115  
   116  type noOpAllBootstrapper struct{}
   117  
   118  func (noop noOpAllBootstrapper) String() string {
   119  	return NoOpAllBootstrapperName
   120  }
   121  
   122  func (noop noOpAllBootstrapper) Bootstrap(
   123  	_ context.Context,
   124  	namespaces bootstrap.Namespaces,
   125  	_ bootstrap.Cache,
   126  ) (bootstrap.NamespaceResults, error) {
   127  	return bootstrap.NewNamespaceResults(namespaces), nil
   128  }