github.com/m3db/m3@v1.5.0/src/cluster/shard/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 shard 22 23 import ( 24 "math" 25 26 "github.com/m3db/m3/src/cluster/generated/proto/placementpb" 27 ) 28 29 const ( 30 // UnInitializedValue is the unintialized value used in proto. 31 UnInitializedValue int64 = 0 32 33 // DefaultShardCutoverNanos is the default shard-level cutover nanos 34 // if the value is not set in the proto message. 35 DefaultShardCutoverNanos int64 = 0 36 37 // DefaultShardCutoffNanos is the default shard-level cutoff nanos 38 // if the value is not set in the proto message. 39 DefaultShardCutoffNanos int64 = math.MaxInt64 40 ) 41 42 // State represents the state of a shard. 43 type State int 44 45 const ( 46 // Unknown represents a shard in unknown state. 47 Unknown State = iota 48 // Initializing represents a shard newly assigned to an instance. 49 Initializing 50 // Available represents a shard bootstraped and ready to serve. 51 Available 52 // Leaving represents a shard that is intending to be removed. 53 Leaving 54 ) 55 56 // A Shard represents a piece of data owned by the service. 57 type Shard interface { 58 // ID returns the ID of the shard. 59 ID() uint32 60 61 // CutoverNanos returns when shard traffic is cut over. 62 CutoverNanos() int64 63 64 // SetCutoverNanos sets when shard traffic is cut over. 65 SetCutoverNanos(value int64) Shard 66 67 // CutoffNanos returns when shard traffic is cut off. 68 CutoffNanos() int64 69 70 // SetCutoffNanos sets when shard traffic is cut off. 71 SetCutoffNanos(value int64) Shard 72 73 // State returns the state of the shard. 74 State() State 75 76 // SetState sets the state of the shard. 77 SetState(s State) Shard 78 79 // SourceID returns the source of the shard. 80 SourceID() string 81 82 // SetSourceID sets the source of the shard. 83 SetSourceID(sourceID string) Shard 84 85 // RedirectToShardID returns optional shard to redirect incoming writes to. 86 RedirectToShardID() *uint32 87 88 // SetRedirectToShardID sets optional shard to redirect incoming writes to. 89 SetRedirectToShardID(*uint32) Shard 90 91 // Equals returns whether the shard equals to another shard. 92 Equals(s Shard) bool 93 94 // Proto returns the proto representation for the shard. 95 Proto() (*placementpb.Shard, error) 96 97 // Clone returns a clone of the Shard. 98 Clone() Shard 99 } 100 101 // Shards is a collection of shards owned by one ServiceInstance. 102 type Shards interface { 103 // All returns the shards sorted ascending. 104 All() []Shard 105 106 // AllIDs returns the shard IDs sorted ascending. 107 AllIDs() []uint32 108 109 // NumShards returns the number of the shards. 110 NumShards() int 111 112 // ShardsForState returns the shards in a certain state. 113 ShardsForState(state State) []Shard 114 115 // NumShardsForState returns the number of shards in a certain state. 116 NumShardsForState(state State) int 117 118 // Add adds a shard. 119 Add(shard Shard) 120 121 // Remove removes a shard. 122 Remove(shard uint32) 123 124 // Contains checks if a shard exists. 125 Contains(shard uint32) bool 126 127 // Shard returns the shard for the id. 128 Shard(id uint32) (Shard, bool) 129 130 // Equals returns whether the shards equals to another shards. 131 Equals(s Shards) bool 132 133 // String returns the string representation of the shards. 134 String() string 135 136 // Proto returns the proto representation for the shards. 137 Proto() ([]*placementpb.Shard, error) 138 139 // Clone returns a clone of the Shards. 140 Clone() Shards 141 }