github.com/m3db/m3@v1.5.0/src/dbnode/runtime/types.go (about) 1 // Copyright (c) 2017 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 runtime 22 23 import ( 24 "time" 25 26 "github.com/m3db/m3/src/dbnode/ratelimit" 27 "github.com/m3db/m3/src/dbnode/topology" 28 xresource "github.com/m3db/m3/src/x/resource" 29 ) 30 31 // Options is a set of runtime options. 32 type Options interface { 33 // Validate will validate the runtime options are valid. 34 Validate() error 35 36 // SetPersistRateLimitOptions sets the persist rate limit options 37 SetPersistRateLimitOptions(value ratelimit.Options) Options 38 39 // PersistRateLimitOptions returns the persist rate limit options 40 PersistRateLimitOptions() ratelimit.Options 41 42 // SetWriteNewSeriesAsync sets whether to write new series asynchronously or not, 43 // when true this essentially makes writes for new series eventually consistent 44 // as after a write is finished you are not guaranteed to read it back immediately 45 // due to inserts into the shard map being buffered. The write is however written 46 // to the commit log before completing so it is considered durable. 47 SetWriteNewSeriesAsync(value bool) Options 48 49 // WriteNewSeriesAsync returns whether to write new series asynchronously or not, 50 // when true this essentially makes writes for new series eventually consistent 51 // as after a write is finished you are not guaranteed to read it back immediately 52 // due to inserts into the shard map being buffered. The write is however written 53 // to the commit log before completing so it is considered durable. 54 WriteNewSeriesAsync() bool 55 56 // SetWriteNewSeriesBackoffDuration sets the insert backoff duration during 57 // periods of heavy insertions, this backoff helps gather larger batches 58 // to insert into a shard in a single batch requiring far less write lock 59 // acquisitions. 60 SetWriteNewSeriesBackoffDuration(value time.Duration) Options 61 62 // WriteNewSeriesBackoffDuration returns the insert backoff duration during 63 // periods of heavy insertions, this backoff helps gather larger batches 64 // to insert into a shard in a single batch requiring far less write lock 65 // acquisitions. 66 WriteNewSeriesBackoffDuration() time.Duration 67 68 // SetWriteNewSeriesLimitPerShardPerSecond sets the insert rate limit per second, 69 // setting to zero disables any rate limit for new series insertions. This rate 70 // limit is primarily offered to defend against unintentional bursts of new 71 // time series being inserted. 72 SetWriteNewSeriesLimitPerShardPerSecond(value int) Options 73 74 // WriteNewSeriesLimitPerShardPerSecond returns the insert rate limit per second, 75 // setting to zero disables any rate limit for new series insertions. This rate 76 // limit is primarily offered to defend against unintentional bursts of new 77 // time series being inserted. 78 WriteNewSeriesLimitPerShardPerSecond() int 79 80 // SetEncodersPerBlockLimit sets the maximum number of encoders per block 81 // allowed. Setting to zero means an unlimited number of encoders are 82 // permitted. This rate limit is primarily offered to defend against 83 // bursts of out of order writes, which creates many encoders, subsequently 84 // causing a large burst in CPU load when trying to merge them. 85 SetEncodersPerBlockLimit(value int) Options 86 87 // EncodersPerBlockLimit sets the maximum number of encoders per block 88 // allowed. Setting to zero means an unlimited number of encoders are 89 // permitted. This rate limit is primarily offered to defend against 90 // bursts of out of order writes, which creates many encoders, subsequently 91 // causing a large burst in CPU load when trying to merge them. 92 EncodersPerBlockLimit() int 93 94 // SetTickSeriesBatchSize sets the batch size to process series together 95 // during a tick before yielding and sleeping the per series duration 96 // multiplied by the batch size. 97 // The higher this value is the more variable CPU utilization will be 98 // but the shorter ticks will ultimately be. 99 SetTickSeriesBatchSize(value int) Options 100 101 // TickSeriesBatchSize returns the batch size to process series together 102 // during a tick before yielding and sleeping the per series duration 103 // multiplied by the batch size. 104 // The higher this value is the more variable CPU utilization will be 105 // but the shorter ticks will ultimately be. 106 TickSeriesBatchSize() int 107 108 // SetTickPerSeriesSleepDuration sets the tick sleep per series value that 109 // provides a constant duration to sleep per series at the end of processing 110 // a batch of series during a background tick, this can directly effect how 111 // fast a block is persisted after is rotated from the mutable series buffer 112 // to a series block (since all series need to be merged/processed before a 113 // persist can occur). 114 SetTickPerSeriesSleepDuration(value time.Duration) Options 115 116 // TickPerSeriesSleepDuration returns the tick sleep per series value that 117 // provides a constant duration to sleep per series at the end of processing 118 // a batch of series during a background tick, this can directly effect how 119 // fast a block is persisted after is rotated from the mutable series buffer 120 // to a series block (since all series need to be merged/processed before a 121 // persist can occur). 122 TickPerSeriesSleepDuration() time.Duration 123 124 // SetTickMinimumInterval sets the minimum tick interval to run ticks, this 125 // helps throttle the tick when the amount of series is low and the sleeps 126 // on a per series basis is short. 127 SetTickMinimumInterval(value time.Duration) Options 128 129 // TickMinimumInterval returns the minimum tick interval to run ticks, this 130 // helps throttle the tick when the amount of series is low and the sleeps 131 // on a per series basis is short. 132 TickMinimumInterval() time.Duration 133 134 // SetMaxWiredBlocks sets the max blocks to keep wired; zero is used 135 // to specify no limit. Wired blocks that are in the buffer, I.E are 136 // being written to, cannot be unwired. Similarly, blocks which have 137 // just been rotated out of the buffer but have not been flushed yet 138 // can also not be unwired. This means that the limit is best effort. 139 SetMaxWiredBlocks(value uint) Options 140 141 // MaxWiredBlocks returns the max blocks to keep wired, zero is used 142 // to specify no limit. Wired blocks that are in the buffer, I.E are 143 // being written to, cannot be unwired. Similarly, blocks which have 144 // just been rotated out of the buffer but have not been flushed yet 145 // can also not be unwired. This means that the limit is best effort. 146 MaxWiredBlocks() uint 147 148 // SetClientBootstrapConsistencyLevel sets the client bootstrap 149 // consistency level used when bootstrapping from peers. Setting this 150 // will take effect immediately, and as such can be used to finish a 151 // bootstrap in an unhealthy cluster to recover read capability by setting 152 // this value to ReadConsistencyLevelNone. 153 SetClientBootstrapConsistencyLevel(value topology.ReadConsistencyLevel) Options 154 155 // ClientBootstrapConsistencyLevel returns the client bootstrap 156 // consistency level used when bootstrapping from peers. Setting this 157 // will take effect immediately, and as such can be used to finish a 158 // bootstrap in an unhealthy cluster to recover read capability by setting 159 // this value to ReadConsistencyLevelNone. 160 ClientBootstrapConsistencyLevel() topology.ReadConsistencyLevel 161 162 // SetClientReadConsistencyLevel sets the client read consistency level 163 // used when fetching data from peers for coordinated reads 164 SetClientReadConsistencyLevel(value topology.ReadConsistencyLevel) Options 165 166 // ClientReadConsistencyLevel returns the client read consistency level 167 // used when fetching data from peers for coordinated reads 168 ClientReadConsistencyLevel() topology.ReadConsistencyLevel 169 170 // SetClientWriteConsistencyLevel sets the client write consistency level 171 // used when fetching data from peers for coordinated writes 172 SetClientWriteConsistencyLevel(value topology.ConsistencyLevel) Options 173 174 // ClientWriteConsistencyLevel returns the client write consistency level 175 // used when fetching data from peers for coordinated writes 176 ClientWriteConsistencyLevel() topology.ConsistencyLevel 177 178 // SetTickCancellationCheckInterval sets the interval to check whether the tick 179 // has been canceled. This duration also affects the minimum tick duration. 180 SetTickCancellationCheckInterval(value time.Duration) Options 181 182 // TickCancellationCheckInterval is the interval to check whether the tick 183 // has been canceled. This duration also affects the minimum tick duration. 184 TickCancellationCheckInterval() time.Duration 185 } 186 187 // OptionsManager updates and supplies runtime options. 188 type OptionsManager interface { 189 // Update updates the current runtime options. 190 Update(value Options) error 191 192 // Get returns the current values. 193 Get() Options 194 195 // RegisterListener registers a listener for updates to runtime options, 196 // it will synchronously call back the listener when this method is called 197 // to deliver the current set of runtime options. 198 RegisterListener(l OptionsListener) xresource.SimpleCloser 199 200 // Close closes the watcher and all descendent watches. 201 Close() 202 } 203 204 // OptionsListener listens for updates to runtime options. 205 type OptionsListener interface { 206 // SetRuntimeOptions is called when the listener is registered 207 // and when any updates occurred passing the new runtime options. 208 SetRuntimeOptions(value Options) 209 }