github.com/m3db/m3@v1.5.0/src/msg/producer/buffer/types.go (about) 1 // Copyright (c) 2018 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 buffer 22 23 import ( 24 "time" 25 26 "github.com/m3db/m3/src/x/instrument" 27 "github.com/m3db/m3/src/x/retry" 28 ) 29 30 // OnFullStrategy defines the buffer behavior when the buffer is full. 31 type OnFullStrategy string 32 33 const ( 34 // ReturnError means an error will be returned 35 // on new buffer requests when the buffer is full. 36 ReturnError OnFullStrategy = "returnError" 37 38 // DropOldest means the oldest message in the buffer 39 // will be dropped to make room for new buffer requests 40 // when the buffer is full. 41 DropOldest OnFullStrategy = "dropOldest" 42 ) 43 44 // Options configs the buffer. 45 type Options interface { 46 // OnFullStrategy returns the strategy when buffer is full. 47 OnFullStrategy() OnFullStrategy 48 49 // SetOnFullStrategy sets the strategy when buffer is full. 50 SetOnFullStrategy(value OnFullStrategy) Options 51 52 // MaxMessageSize returns the max message size. 53 MaxMessageSize() int 54 55 // SetMaxMessageSize sets the max message size. 56 SetMaxMessageSize(value int) Options 57 58 // MaxBufferSize returns the max buffer size. 59 MaxBufferSize() int 60 61 // SetMaxBufferSize sets the max buffer size. 62 SetMaxBufferSize(value int) Options 63 64 // CloseCheckInterval returns the close check interval. 65 CloseCheckInterval() time.Duration 66 67 // SetCloseCheckInterval sets the close check interval. 68 SetCloseCheckInterval(value time.Duration) Options 69 70 // DropOldestInterval returns the interval to drop oldest buffer. 71 // The max buffer size might be spilled over during the interval. 72 DropOldestInterval() time.Duration 73 74 // SetDropOldestInterval sets the interval to drop oldest buffer. 75 // The max buffer size might be spilled over during the interval. 76 SetDropOldestInterval(value time.Duration) Options 77 78 // ScanBatchSize returns the scan batch size. 79 ScanBatchSize() int 80 81 // SetScanBatchSize sets the scan batch size. 82 SetScanBatchSize(value int) Options 83 84 // AllowedSpilloverRatio returns the ratio for allowed buffer spill over, 85 // below which the buffer will drop oldest messages asynchronizely for 86 // better performance. When the limit for allowed spill over is reached, 87 // the buffer will start to drop oldest messages synchronizely. 88 AllowedSpilloverRatio() float64 89 90 // SetAllowedSpilloverRatio sets the ratio for allowed buffer spill over. 91 SetAllowedSpilloverRatio(value float64) Options 92 93 // CleanupRetryOptions returns the cleanup retry options. 94 CleanupRetryOptions() retry.Options 95 96 // SetCleanupRetryOptions sets the cleanup retry options. 97 SetCleanupRetryOptions(value retry.Options) Options 98 99 // InstrumentOptions returns the instrument options. 100 InstrumentOptions() instrument.Options 101 102 // SetInstrumentOptions sets the instrument options. 103 SetInstrumentOptions(value instrument.Options) Options 104 105 // Validate validates the options. 106 Validate() error 107 }