github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/dbnode/sharding/types.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 sharding
    22  
    23  import (
    24  	"github.com/m3db/m3/src/cluster/shard"
    25  	"github.com/m3db/m3/src/x/ident"
    26  )
    27  
    28  // HashGen generates HashFn based on the length of shards.
    29  type HashGen func(length int) HashFn
    30  
    31  // HashFn is a sharding hash function.
    32  type HashFn func(id ident.ID) uint32
    33  
    34  // ShardSet contains a sharding function and a set of shards, this interface
    35  // allows for potentially out of order shard sets.
    36  type ShardSet interface {
    37  	// All returns a slice to the shards in this set.
    38  	All() []shard.Shard
    39  
    40  	// AllIDs returns a slice to the shard IDs in this set.
    41  	AllIDs() []uint32
    42  
    43  	// Lookup will return a shard for a given identifier.
    44  	Lookup(id ident.ID) uint32
    45  
    46  	// LookupShard will return a shard for a given shard id.
    47  	LookupShard(id uint32) (shard.Shard, error)
    48  
    49  	// LookupStateByID returns the state of the shard with a given ID.
    50  	LookupStateByID(shardID uint32) (shard.State, error)
    51  
    52  	// Min returns the smallest shard owned by this shard set.
    53  	Min() uint32
    54  
    55  	// Max returns the largest shard owned by this shard set.
    56  	Max() uint32
    57  
    58  	// HashFn returns the sharding hash function.
    59  	HashFn() HashFn
    60  }