github.com/m3db/m3@v1.5.0/src/cluster/placement/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 placement 22 23 import ( 24 "time" 25 26 "github.com/m3db/m3/src/cluster/shard" 27 "github.com/m3db/m3/src/x/clock" 28 "github.com/m3db/m3/src/x/instrument" 29 ) 30 31 const ( 32 defaultMaxStepSize = 3 33 defaultIsSharded = true 34 // By default partial replace should be allowed for better distribution. 35 defaultAllowPartialReplace = true 36 // By default the zone of the hosts within a placement should match the zone 37 // that the placement was created with. 38 defaultAllowAllZones = false 39 ) 40 41 type deploymentOptions struct { 42 maxStepSize int 43 } 44 45 // NewDeploymentOptions returns a default DeploymentOptions 46 func NewDeploymentOptions() DeploymentOptions { 47 return deploymentOptions{maxStepSize: defaultMaxStepSize} 48 } 49 50 func (o deploymentOptions) MaxStepSize() int { 51 return o.maxStepSize 52 } 53 54 func (o deploymentOptions) SetMaxStepSize(stepSize int) DeploymentOptions { 55 o.maxStepSize = stepSize 56 return o 57 } 58 59 func defaultTimeNanosFn() int64 { return shard.UnInitializedValue } 60 func defaultShardValidationFn(s shard.Shard) error { return nil } 61 62 type options struct { 63 shardStateMode ShardStateMode 64 iopts instrument.Options 65 validZone string 66 placementCutOverFn TimeNanosFn 67 shardCutOverFn TimeNanosFn 68 shardCutOffFn TimeNanosFn 69 isShardCutoverFn ShardValidateFn 70 isShardCutoffFn ShardValidateFn 71 validateFn ValidateFn 72 nowFn clock.NowFn 73 allowPartialReplace bool 74 allowAllZones bool 75 addAllCandidates bool 76 dryrun bool 77 isSharded bool 78 isMirrored bool 79 skipPortMirroring bool 80 isStaged bool 81 compress bool 82 instanceSelector InstanceSelector 83 } 84 85 // NewOptions returns a default Options. 86 func NewOptions() Options { 87 return options{ 88 allowPartialReplace: defaultAllowPartialReplace, 89 isSharded: defaultIsSharded, 90 shardStateMode: IncludeTransitionalShardStates, 91 iopts: instrument.NewOptions(), 92 placementCutOverFn: defaultTimeNanosFn, 93 shardCutOverFn: defaultTimeNanosFn, 94 shardCutOffFn: defaultTimeNanosFn, 95 isShardCutoverFn: defaultShardValidationFn, 96 isShardCutoffFn: defaultShardValidationFn, 97 validateFn: Validate, 98 nowFn: time.Now, 99 allowAllZones: defaultAllowAllZones, 100 } 101 } 102 103 func (o options) AllowPartialReplace() bool { 104 return o.allowPartialReplace 105 } 106 107 func (o options) SetAllowPartialReplace(allowPartialReplace bool) Options { 108 o.allowPartialReplace = allowPartialReplace 109 return o 110 } 111 112 func (o options) AllowAllZones() bool { 113 return o.allowAllZones 114 } 115 116 func (o options) SetAllowAllZones(allowAllZones bool) Options { 117 o.allowAllZones = allowAllZones 118 return o 119 } 120 121 func (o options) AddAllCandidates() bool { 122 return o.addAllCandidates 123 } 124 125 func (o options) SetAddAllCandidates(addAllCandidates bool) Options { 126 o.addAllCandidates = addAllCandidates 127 return o 128 } 129 130 func (o options) IsSharded() bool { 131 return o.isSharded 132 } 133 134 func (o options) SetIsSharded(sharded bool) Options { 135 o.isSharded = sharded 136 return o 137 } 138 139 func (o options) ShardStateMode() ShardStateMode { 140 return o.shardStateMode 141 } 142 143 func (o options) SetShardStateMode(value ShardStateMode) Options { 144 o.shardStateMode = value 145 return o 146 } 147 148 func (o options) IsMirrored() bool { 149 return o.isMirrored 150 } 151 152 func (o options) SetIsMirrored(v bool) Options { 153 o.isMirrored = v 154 return o 155 } 156 157 func (o options) SkipPortMirroring() bool { 158 return o.skipPortMirroring 159 } 160 161 func (o options) SetSkipPortMirroring(v bool) Options { 162 o.skipPortMirroring = v 163 return o 164 } 165 166 func (o options) IsStaged() bool { 167 return o.isStaged 168 } 169 170 func (o options) SetIsStaged(v bool) Options { 171 o.isStaged = v 172 return o 173 } 174 175 func (o options) Compress() bool { 176 return o.compress 177 } 178 179 func (o options) SetCompress(v bool) Options { 180 o.compress = v 181 return o 182 } 183 184 func (o options) Dryrun() bool { 185 return o.dryrun 186 } 187 188 func (o options) SetDryrun(d bool) Options { 189 o.dryrun = d 190 return o 191 } 192 193 func (o options) InstrumentOptions() instrument.Options { 194 return o.iopts 195 } 196 197 func (o options) SetInstrumentOptions(iopts instrument.Options) Options { 198 o.iopts = iopts 199 return o 200 } 201 202 func (o options) ValidZone() string { 203 return o.validZone 204 } 205 206 func (o options) SetValidZone(z string) Options { 207 o.validZone = z 208 return o 209 } 210 211 func (o options) PlacementCutoverNanosFn() TimeNanosFn { 212 return o.placementCutOverFn 213 } 214 215 func (o options) SetPlacementCutoverNanosFn(fn TimeNanosFn) Options { 216 o.placementCutOverFn = fn 217 return o 218 } 219 220 func (o options) ShardCutoverNanosFn() TimeNanosFn { 221 return o.shardCutOverFn 222 } 223 224 func (o options) SetShardCutoverNanosFn(fn TimeNanosFn) Options { 225 o.shardCutOverFn = fn 226 return o 227 } 228 229 func (o options) ShardCutoffNanosFn() TimeNanosFn { 230 return o.shardCutOffFn 231 } 232 233 func (o options) SetShardCutoffNanosFn(fn TimeNanosFn) Options { 234 o.shardCutOffFn = fn 235 return o 236 } 237 238 func (o options) IsShardCutoverFn() ShardValidateFn { 239 return o.isShardCutoverFn 240 } 241 242 func (o options) SetIsShardCutoverFn(fn ShardValidateFn) Options { 243 o.isShardCutoverFn = fn 244 return o 245 } 246 247 func (o options) IsShardCutoffFn() ShardValidateFn { 248 return o.isShardCutoffFn 249 } 250 251 func (o options) SetIsShardCutoffFn(fn ShardValidateFn) Options { 252 o.isShardCutoffFn = fn 253 return o 254 } 255 256 func (o options) NowFn() clock.NowFn { 257 return o.nowFn 258 } 259 260 func (o options) SetNowFn(fn clock.NowFn) Options { 261 o.nowFn = fn 262 return o 263 } 264 265 func (o options) ValidateFnBeforeUpdate() ValidateFn { 266 return o.validateFn 267 } 268 269 func (o options) SetValidateFnBeforeUpdate(fn ValidateFn) Options { 270 o.validateFn = fn 271 return o 272 } 273 274 func (o options) InstanceSelector() InstanceSelector { 275 return o.instanceSelector 276 } 277 278 func (o options) SetInstanceSelector(s InstanceSelector) Options { 279 o.instanceSelector = s 280 return o 281 }