github.com/m3db/m3@v1.5.0/src/dbnode/storage/bootstrap/bootstrapper/fs/migrator/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 migrator 22 23 import ( 24 "errors" 25 26 "github.com/m3db/m3/src/dbnode/persist/fs" 27 "github.com/m3db/m3/src/dbnode/persist/fs/migration" 28 "github.com/m3db/m3/src/dbnode/storage" 29 "github.com/m3db/m3/src/dbnode/storage/bootstrap" 30 "github.com/m3db/m3/src/x/instrument" 31 ) 32 33 var ( 34 errMigrationTaskFnNotSet = errors.New("migrationTaskFn not set") 35 errInfoFilesByNamespaceNotSet = errors.New("infoFilesByNamespaces not set") 36 errMigrationOptsNotSet = errors.New("migrationOpts not set") 37 errInstrumentOptsNotSet = errors.New("instrumentOpts not set") 38 errStorageOptsNotSet = errors.New("storageOpts not set") 39 errFilesystemOptsNotSet = errors.New("filesystemOpts not set") 40 ) 41 42 type options struct { 43 migrationTaskFn MigrationTaskFn 44 infoFilesByNamespace bootstrap.InfoFilesByNamespace 45 migrationOpts migration.Options 46 fsOpts fs.Options 47 instrumentOpts instrument.Options 48 storageOpts storage.Options 49 } 50 51 // NewOptions return new migration opts 52 func NewOptions() Options { 53 return &options{ 54 migrationOpts: migration.NewOptions(), 55 instrumentOpts: instrument.NewOptions(), 56 } 57 } 58 59 func (o *options) Validate() error { 60 if o.storageOpts == nil { 61 return errStorageOptsNotSet 62 } 63 if err := o.storageOpts.Validate(); err != nil { 64 return err 65 } 66 if o.migrationTaskFn == nil { 67 return errMigrationTaskFnNotSet 68 } 69 if o.infoFilesByNamespace == nil { 70 return errInfoFilesByNamespaceNotSet 71 } 72 if o.migrationOpts == nil { 73 return errMigrationOptsNotSet 74 } 75 if o.instrumentOpts == nil { 76 return errInstrumentOptsNotSet 77 } 78 if o.fsOpts == nil { 79 return errFilesystemOptsNotSet 80 } 81 if err := o.fsOpts.Validate(); err != nil { 82 return err 83 } 84 return nil 85 } 86 87 func (o *options) SetMigrationTaskFn(value MigrationTaskFn) Options { 88 opts := *o 89 opts.migrationTaskFn = value 90 return &opts 91 } 92 93 func (o *options) MigrationTaskFn() MigrationTaskFn { 94 return o.migrationTaskFn 95 } 96 97 func (o *options) SetInfoFilesByNamespace(value bootstrap.InfoFilesByNamespace) Options { 98 opts := *o 99 opts.infoFilesByNamespace = value 100 return &opts 101 } 102 103 func (o *options) InfoFilesByNamespace() bootstrap.InfoFilesByNamespace { 104 return o.infoFilesByNamespace 105 } 106 107 func (o *options) SetMigrationOptions(value migration.Options) Options { 108 opts := *o 109 opts.migrationOpts = value 110 return &opts 111 } 112 113 func (o *options) MigrationOptions() migration.Options { 114 return o.migrationOpts 115 } 116 117 func (o *options) SetFilesystemOptions(value fs.Options) Options { 118 opts := *o 119 opts.fsOpts = value 120 return &opts 121 } 122 123 func (o *options) FilesystemOptions() fs.Options { 124 return o.fsOpts 125 } 126 127 func (o *options) SetInstrumentOptions(value instrument.Options) Options { 128 opts := *o 129 opts.instrumentOpts = value 130 return &opts 131 } 132 133 func (o *options) InstrumentOptions() instrument.Options { 134 return o.instrumentOpts 135 } 136 137 func (o *options) SetStorageOptions(value storage.Options) Options { 138 opts := *o 139 opts.storageOpts = value 140 return &opts 141 } 142 143 func (o *options) StorageOptions() storage.Options { 144 return o.storageOpts 145 }