github.com/m3db/m3@v1.5.0/src/dbnode/persist/fs/migration/task_options.go (about) 1 // Copyright (c) 2020 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 migration 22 23 import ( 24 "errors" 25 26 "github.com/m3db/m3/src/dbnode/namespace" 27 "github.com/m3db/m3/src/dbnode/persist" 28 "github.com/m3db/m3/src/dbnode/persist/fs" 29 "github.com/m3db/m3/src/dbnode/storage" 30 ) 31 32 var ( 33 errNewMergerFnNotSet = errors.New("newMergerFn not set") 34 errNamespaceMetadataNotSet = errors.New("namespaceMetadata not set") 35 errPersistManagerNotSet = errors.New("persistManager not set") 36 errStorageOptionsNotSet = errors.New("storageOptions not set") 37 errFilesystemOptionsNotSet = errors.New("filesystemOptions not set") 38 ) 39 40 type taskOptions struct { 41 newMergerFn fs.NewMergerFn 42 infoFileResult fs.ReadInfoFileResult 43 shard uint32 44 namespaceMetadata namespace.Metadata 45 persistManager persist.Manager 46 storageOptions storage.Options 47 fsOpts fs.Options 48 } 49 50 // NewTaskOptions creates new taskOptions. 51 func NewTaskOptions() TaskOptions { 52 return &taskOptions{ 53 newMergerFn: fs.NewMerger, 54 } 55 } 56 57 func (t *taskOptions) Validate() error { 58 if t.storageOptions == nil { 59 return errStorageOptionsNotSet 60 } 61 if err := t.storageOptions.Validate(); err != nil { 62 return err 63 } 64 if t.newMergerFn == nil { 65 return errNewMergerFnNotSet 66 } 67 if t.infoFileResult.Err != nil && t.infoFileResult.Err.Error() != nil { 68 return t.infoFileResult.Err.Error() 69 } 70 if t.namespaceMetadata == nil { 71 return errNamespaceMetadataNotSet 72 } 73 if t.persistManager == nil { 74 return errPersistManagerNotSet 75 } 76 if t.fsOpts == nil { 77 return errFilesystemOptionsNotSet 78 } 79 if err := t.fsOpts.Validate(); err != nil { 80 return err 81 } 82 83 return nil 84 } 85 86 func (t *taskOptions) SetNewMergerFn(value fs.NewMergerFn) TaskOptions { 87 to := *t 88 to.newMergerFn = value 89 return &to 90 } 91 92 func (t *taskOptions) NewMergerFn() fs.NewMergerFn { 93 return t.newMergerFn 94 } 95 96 func (t *taskOptions) SetInfoFileResult(value fs.ReadInfoFileResult) TaskOptions { 97 to := *t 98 to.infoFileResult = value 99 return &to 100 } 101 102 func (t *taskOptions) InfoFileResult() fs.ReadInfoFileResult { 103 return t.infoFileResult 104 } 105 106 func (t *taskOptions) SetShard(value uint32) TaskOptions { 107 to := *t 108 to.shard = value 109 return &to 110 } 111 112 func (t *taskOptions) Shard() uint32 { 113 return t.shard 114 } 115 116 func (t *taskOptions) SetNamespaceMetadata(value namespace.Metadata) TaskOptions { 117 to := *t 118 to.namespaceMetadata = value 119 return &to 120 } 121 122 func (t *taskOptions) NamespaceMetadata() namespace.Metadata { 123 return t.namespaceMetadata 124 } 125 126 func (t *taskOptions) SetPersistManager(value persist.Manager) TaskOptions { 127 to := *t 128 to.persistManager = value 129 return &to 130 } 131 132 func (t *taskOptions) PersistManager() persist.Manager { 133 return t.persistManager 134 } 135 136 func (t *taskOptions) SetStorageOptions(value storage.Options) TaskOptions { 137 to := *t 138 to.storageOptions = value 139 return &to 140 } 141 142 func (t *taskOptions) StorageOptions() storage.Options { 143 return t.storageOptions 144 } 145 146 func (t *taskOptions) SetFilesystemOptions(value fs.Options) TaskOptions { 147 to := *t 148 to.fsOpts = value 149 return &to 150 } 151 152 func (t *taskOptions) FilesystemOptions() fs.Options { 153 return t.fsOpts 154 }