github.com/m3db/m3@v1.5.0/src/dbnode/integration/generate/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 generate 22 23 import ( 24 "os" 25 "time" 26 27 "github.com/m3db/m3/src/dbnode/encoding" 28 "github.com/m3db/m3/src/dbnode/encoding/m3tsz" 29 "github.com/m3db/m3/src/x/clock" 30 ) 31 32 const ( 33 // defaultRetentionPeriod is how long we keep data in memory by default. 34 defaultRetentionPeriod = 2 * 24 * time.Hour 35 36 // defaultBlockSize is the default block size 37 defaultBlockSize = 2 * time.Hour 38 39 // defaultWriterBufferSize is the default buffer size for writing TSDB files 40 defaultWriterBufferSize = 65536 41 42 // defaultNewFileMode is the file mode used for new files by default 43 defaultNewFileMode = os.FileMode(0666) 44 45 // defaultNewDirectoryMode is the file mode used for new directories by default 46 defaultNewDirectoryMode = os.ModeDir | os.FileMode(0755) 47 48 // defaultWriteEmptyShards is the writeEmptyShards value by default 49 defaultWriteEmptyShards = true 50 51 // defaultWriteSnapshot determines whether the writer writes snapshots instead 52 // of data files. 53 defaultWriteSnapshot = false 54 ) 55 56 var ( 57 defaultFilePathPrefix = os.TempDir() 58 ) 59 60 type options struct { 61 clockOpts clock.Options 62 retentionPeriod time.Duration 63 blockSize time.Duration 64 filePathPrefix string 65 newFileMode os.FileMode 66 newDirectoryMode os.FileMode 67 writerBufferSize int 68 writeEmptyShards bool 69 writeSnapshot bool 70 encoderPool encoding.EncoderPool 71 } 72 73 // NewOptions creates a new set of fs options 74 func NewOptions() Options { 75 encoderPool := encoding.NewEncoderPool(nil) 76 encodingOpts := encoding.NewOptions().SetEncoderPool(encoderPool) 77 encoderPool.Init(func() encoding.Encoder { 78 return m3tsz.NewEncoder(0, nil, m3tsz.DefaultIntOptimizationEnabled, encodingOpts) 79 }) 80 81 return &options{ 82 clockOpts: clock.NewOptions(), 83 retentionPeriod: defaultRetentionPeriod, 84 blockSize: defaultBlockSize, 85 filePathPrefix: defaultFilePathPrefix, 86 newFileMode: defaultNewFileMode, 87 newDirectoryMode: defaultNewDirectoryMode, 88 writerBufferSize: defaultWriterBufferSize, 89 writeEmptyShards: defaultWriteEmptyShards, 90 writeSnapshot: defaultWriteSnapshot, 91 encoderPool: encoderPool, 92 } 93 } 94 95 func (o *options) SetClockOptions(value clock.Options) Options { 96 opts := *o 97 opts.clockOpts = value 98 return &opts 99 } 100 101 func (o *options) ClockOptions() clock.Options { 102 return o.clockOpts 103 } 104 105 func (o *options) SetRetentionPeriod(value time.Duration) Options { 106 opts := *o 107 opts.retentionPeriod = value 108 return &opts 109 } 110 111 func (o *options) RetentionPeriod() time.Duration { 112 return o.retentionPeriod 113 } 114 115 func (o *options) SetBlockSize(value time.Duration) Options { 116 opts := *o 117 opts.blockSize = value 118 return &opts 119 } 120 121 func (o *options) BlockSize() time.Duration { 122 return o.blockSize 123 } 124 125 func (o *options) SetFilePathPrefix(value string) Options { 126 opts := *o 127 opts.filePathPrefix = value 128 return &opts 129 } 130 131 func (o *options) FilePathPrefix() string { 132 return o.filePathPrefix 133 } 134 135 func (o *options) SetNewFileMode(value os.FileMode) Options { 136 opts := *o 137 opts.newFileMode = value 138 return &opts 139 } 140 141 func (o *options) NewFileMode() os.FileMode { 142 return o.newFileMode 143 } 144 145 func (o *options) SetNewDirectoryMode(value os.FileMode) Options { 146 opts := *o 147 opts.newDirectoryMode = value 148 return &opts 149 } 150 151 func (o *options) NewDirectoryMode() os.FileMode { 152 return o.newDirectoryMode 153 } 154 155 func (o *options) SetWriterBufferSize(value int) Options { 156 opts := *o 157 opts.writerBufferSize = value 158 return &opts 159 } 160 161 func (o *options) WriterBufferSize() int { 162 return o.writerBufferSize 163 } 164 165 func (o *options) SetWriteEmptyShards(value bool) Options { 166 opts := *o 167 opts.writeEmptyShards = value 168 return &opts 169 } 170 171 func (o *options) WriteEmptyShards() bool { 172 return o.writeEmptyShards 173 } 174 175 func (o *options) SetWriteSnapshot(value bool) Options { 176 opts := *o 177 opts.writeSnapshot = value 178 return &opts 179 } 180 181 func (o *options) WriteSnapshot() bool { 182 return o.writeSnapshot 183 } 184 185 func (o *options) SetEncoderPool(value encoding.EncoderPool) Options { 186 opts := *o 187 opts.encoderPool = value 188 return &opts 189 } 190 191 func (o *options) EncoderPool() encoding.EncoderPool { 192 return o.encoderPool 193 }