github.com/m3db/m3@v1.5.0/src/dbnode/namespace/config.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 "fmt" 25 "time" 26 27 "github.com/m3db/m3/src/dbnode/retention" 28 "github.com/m3db/m3/src/x/ident" 29 ) 30 31 // MapConfiguration is the configuration for a registry of namespaces 32 type MapConfiguration struct { 33 Metadatas []MetadataConfiguration `yaml:"metadatas" validate:"nonzero"` 34 } 35 36 // Map returns a Map corresponding to the receiver struct 37 func (m *MapConfiguration) Map() (Map, error) { 38 metadatas := make([]Metadata, 0, len(m.Metadatas)) 39 for _, m := range m.Metadatas { 40 md, err := m.Metadata() 41 if err != nil { 42 return nil, fmt.Errorf("unable to construct metadata for [%+v], err: %v", m, err) 43 } 44 metadatas = append(metadatas, md) 45 } 46 return NewMap(metadatas) 47 } 48 49 // MetadataConfiguration is the configuration for a single namespace 50 type MetadataConfiguration struct { 51 ID string `yaml:"id" validate:"nonzero"` 52 BootstrapEnabled *bool `yaml:"bootstrapEnabled"` 53 FlushEnabled *bool `yaml:"flushEnabled"` 54 WritesToCommitLog *bool `yaml:"writesToCommitLog"` 55 CleanupEnabled *bool `yaml:"cleanupEnabled"` 56 RepairEnabled *bool `yaml:"repairEnabled"` 57 ColdWritesEnabled *bool `yaml:"coldWritesEnabled"` 58 CacheBlocksOnRetrieve *bool `yaml:"cacheBlocksOnRetrieve"` 59 Retention retention.Configuration `yaml:"retention" validate:"nonzero"` 60 Index IndexConfiguration `yaml:"index"` 61 } 62 63 // Metadata returns a Metadata corresponding to the receiver struct 64 func (mc *MetadataConfiguration) Metadata() (Metadata, error) { 65 iopts := mc.Index.Options() 66 ropts := mc.Retention.Options() 67 opts := NewOptions(). 68 SetRetentionOptions(ropts). 69 SetIndexOptions(iopts) 70 if v := mc.BootstrapEnabled; v != nil { 71 opts = opts.SetBootstrapEnabled(*v) 72 } 73 if v := mc.FlushEnabled; v != nil { 74 opts = opts.SetFlushEnabled(*v) 75 } 76 if v := mc.WritesToCommitLog; v != nil { 77 opts = opts.SetWritesToCommitLog(*v) 78 } 79 if v := mc.CleanupEnabled; v != nil { 80 opts = opts.SetCleanupEnabled(*v) 81 } 82 if v := mc.RepairEnabled; v != nil { 83 opts = opts.SetRepairEnabled(*v) 84 } 85 if v := mc.ColdWritesEnabled; v != nil { 86 opts = opts.SetColdWritesEnabled(*v) 87 } 88 if v := mc.CacheBlocksOnRetrieve; v != nil { 89 opts = opts.SetCacheBlocksOnRetrieve(*v) 90 } 91 return NewMetadata(ident.StringID(mc.ID), opts) 92 } 93 94 // IndexConfiguration controls the knobs to tweak indexing configuration. 95 type IndexConfiguration struct { 96 Enabled bool `yaml:"enabled" validate:"nonzero"` 97 BlockSize time.Duration `yaml:"blockSize" validate:"nonzero"` 98 } 99 100 // Options returns the IndexOptions corresponding to the receiver struct. 101 func (ic *IndexConfiguration) Options() IndexOptions { 102 return NewIndexOptions(). 103 SetEnabled(ic.Enabled). 104 SetBlockSize(ic.BlockSize) 105 }