github.com/m3db/m3@v1.5.0/src/dbnode/namespace/dynamic_options.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 namespace 22 23 import ( 24 "errors" 25 "time" 26 27 "github.com/m3db/m3/src/cluster/client" 28 "github.com/m3db/m3/src/x/instrument" 29 ) 30 31 const ( 32 defaultInitTimeout = 30 * time.Second 33 defaultNsRegistryKey = "m3db.node.namespace_registry" 34 ) 35 36 var ( 37 errInitTimeoutPositive = errors.New("init timeout must be positive") 38 errNsRegistryKeyEmpty = errors.New("namespace registry key must not be empty") 39 errCsClientNotSet = errors.New("config service client not set") 40 ) 41 42 type dynamicOpts struct { 43 iopts instrument.Options 44 csClient client.Client 45 nsRegistryKey string 46 initTimeout time.Duration 47 forceColdWritesEnabled bool 48 allowEmptyInitialNamespaceRegistry bool 49 } 50 51 // NewDynamicOptions creates a new DynamicOptions 52 func NewDynamicOptions() DynamicOptions { 53 return &dynamicOpts{ 54 iopts: instrument.NewOptions(), 55 nsRegistryKey: defaultNsRegistryKey, 56 initTimeout: defaultInitTimeout, 57 } 58 } 59 60 func (o *dynamicOpts) Validate() error { 61 if o.initTimeout <= 0 { 62 return errInitTimeoutPositive 63 } 64 if o.nsRegistryKey == "" { 65 return errNsRegistryKeyEmpty 66 } 67 if o.csClient == nil { 68 return errCsClientNotSet 69 } 70 return nil 71 } 72 73 func (o *dynamicOpts) SetInstrumentOptions(value instrument.Options) DynamicOptions { 74 opts := *o 75 opts.iopts = value 76 return &opts 77 } 78 79 func (o *dynamicOpts) InstrumentOptions() instrument.Options { 80 return o.iopts 81 } 82 83 func (o *dynamicOpts) SetConfigServiceClient(c client.Client) DynamicOptions { 84 opts := *o 85 opts.csClient = c 86 return &opts 87 } 88 89 func (o *dynamicOpts) ConfigServiceClient() client.Client { 90 return o.csClient 91 } 92 93 func (o *dynamicOpts) SetNamespaceRegistryKey(k string) DynamicOptions { 94 opts := *o 95 opts.nsRegistryKey = k 96 return &opts 97 } 98 99 func (o *dynamicOpts) NamespaceRegistryKey() string { 100 return o.nsRegistryKey 101 } 102 103 func (o *dynamicOpts) SetForceColdWritesEnabled(enabled bool) DynamicOptions { 104 opts := *o 105 opts.forceColdWritesEnabled = enabled 106 return &opts 107 } 108 109 func (o *dynamicOpts) ForceColdWritesEnabled() bool { 110 return o.forceColdWritesEnabled 111 } 112 113 func (o *dynamicOpts) SetAllowEmptyInitialNamespaceRegistry(value bool) DynamicOptions { 114 opts := *o 115 opts.allowEmptyInitialNamespaceRegistry = value 116 return &opts 117 } 118 119 func (o *dynamicOpts) AllowEmptyInitialNamespaceRegistry() bool { 120 return o.allowEmptyInitialNamespaceRegistry 121 }