github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/dbnode/namespace/types.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 namespace 22 23 import ( 24 "time" 25 26 "github.com/m3db/m3/src/cluster/client" 27 "github.com/m3db/m3/src/dbnode/retention" 28 "github.com/m3db/m3/src/x/ident" 29 "github.com/m3db/m3/src/x/instrument" 30 xresource "github.com/m3db/m3/src/x/resource" 31 32 protobuftypes "github.com/gogo/protobuf/types" 33 ) 34 35 // Options controls namespace behavior. 36 type Options interface { 37 // Validate validates the options. 38 Validate() error 39 40 // Equal returns true if the provide value is equal to this one. 41 Equal(value Options) bool 42 43 // SetBootstrapEnabled sets whether this namespace requires bootstrapping. 44 SetBootstrapEnabled(value bool) Options 45 46 // BootstrapEnabled returns whether this namespace requires bootstrapping. 47 BootstrapEnabled() bool 48 49 // SetFlushEnabled sets whether the in-memory data for this namespace needs to be flushed. 50 SetFlushEnabled(value bool) Options 51 52 // FlushEnabled returns whether the in-memory data for this namespace needs to be flushed. 53 FlushEnabled() bool 54 55 // SetSnapshotEnabled sets whether the in-memory data for this namespace should be snapshotted regularly. 56 SetSnapshotEnabled(value bool) Options 57 58 // SnapshotEnabled returns whether the in-memory data for this namespace should be snapshotted regularly. 59 SnapshotEnabled() bool 60 61 // SetWritesToCommitLog sets whether writes for series in this namespace need to go to commit log. 62 SetWritesToCommitLog(value bool) Options 63 64 // WritesToCommitLog returns whether writes for series in this namespace need to go to commit log. 65 WritesToCommitLog() bool 66 67 // SetCleanupEnabled sets whether this namespace requires cleaning up fileset/snapshot files. 68 SetCleanupEnabled(value bool) Options 69 70 // CleanupEnabled returns whether this namespace requires cleaning up fileset/snapshot files. 71 CleanupEnabled() bool 72 73 // SetRepairEnabled sets whether the data for this namespace needs to be repaired. 74 SetRepairEnabled(value bool) Options 75 76 // RepairEnabled returns whether the data for this namespace needs to be repaired. 77 RepairEnabled() bool 78 79 // SetColdWritesEnabled sets whether cold writes are enabled for this namespace. 80 SetColdWritesEnabled(value bool) Options 81 82 // ColdWritesEnabled returns whether cold writes are enabled for this namespace. 83 ColdWritesEnabled() bool 84 85 // SetCacheBlocksOnRetrieve sets whether to cache blocks from this namespace when retrieved. 86 // If global CacheBlocksOnRetrieve option in config.BlockRetrievePolicy is set to false, 87 // then that will override any namespace-specific CacheBlocksOnRetrieve options set to true. 88 SetCacheBlocksOnRetrieve(value bool) Options 89 90 // CacheBlocksOnRetrieve returns whether to cache blocks from this namespace when retrieved. 91 CacheBlocksOnRetrieve() bool 92 93 // SetRetentionOptions sets the retention options for this namespace. 94 SetRetentionOptions(value retention.Options) Options 95 96 // RetentionOptions returns the retention options for this namespace. 97 RetentionOptions() retention.Options 98 99 // SetIndexOptions sets the IndexOptions. 100 SetIndexOptions(value IndexOptions) Options 101 102 // IndexOptions returns the IndexOptions. 103 IndexOptions() IndexOptions 104 105 // SetSchemaHistory sets the schema registry for this namespace. 106 SetSchemaHistory(value SchemaHistory) Options 107 108 // SchemaHistory returns the schema registry for this namespace. 109 SchemaHistory() SchemaHistory 110 111 // SetRuntimeOptions sets the RuntimeOptions. 112 SetRuntimeOptions(value RuntimeOptions) Options 113 114 // RuntimeOptions returns the RuntimeOptions. 115 RuntimeOptions() RuntimeOptions 116 117 // SetExtendedOptions sets the ExtendedOptions. 118 SetExtendedOptions(value ExtendedOptions) Options 119 120 // ExtendedOptions returns the dynamically typed ExtendedOptions (requires type check on access). 121 ExtendedOptions() ExtendedOptions 122 123 // SetAggregationOptions sets the aggregation-related options for this namespace. 124 SetAggregationOptions(value AggregationOptions) Options 125 126 // AggregationOptions returns the aggregation-related options for this namespace. 127 AggregationOptions() AggregationOptions 128 129 // SetStagingState sets the state related to a namespace's availability for use. 130 SetStagingState(value StagingState) Options 131 132 // StagingState returns the state related to a namespace's availability for use. 133 StagingState() StagingState 134 } 135 136 // IndexOptions controls the indexing options for a namespace. 137 type IndexOptions interface { 138 // Equal returns true if the provide value is equal to this one. 139 Equal(value IndexOptions) bool 140 141 // SetEnabled sets whether indexing is enabled. 142 SetEnabled(value bool) IndexOptions 143 144 // Enabled returns whether indexing is enabled. 145 Enabled() bool 146 147 // SetBlockSize returns the block size. 148 SetBlockSize(value time.Duration) IndexOptions 149 150 // BlockSize returns the block size. 151 BlockSize() time.Duration 152 } 153 154 // SchemaDescr describes the schema for a complex type value. 155 type SchemaDescr interface { 156 // DeployId returns the deploy id of the schema. 157 DeployId() string 158 // PrevDeployId returns the previous deploy id of the schema. 159 PrevDeployId() string 160 // Get returns the message descriptor for the schema. 161 Get() MessageDescriptor 162 // String returns the compact text of the message descriptor. 163 String() string 164 // Equal returns true if the provided value is equal to this one. 165 Equal(SchemaDescr) bool 166 } 167 168 // SchemaHistory represents schema history for a namespace. 169 type SchemaHistory interface { 170 // Equal returns true if the provided value is equal to this one. 171 Equal(SchemaHistory) bool 172 173 // Extends returns true iif the provided value has a lineage to this one. 174 Extends(SchemaHistory) bool 175 176 // Get gets the schema descriptor for the specified deploy id. 177 Get(id string) (SchemaDescr, bool) 178 179 // GetLatest gets the latest version of schema descriptor. 180 GetLatest() (SchemaDescr, bool) 181 } 182 183 // SchemaListener listens for updates to schema registry for a namespace. 184 type SchemaListener interface { 185 // SetSchemaHistory is called when the listener is registered 186 // and when any updates occurred passing the new schema history. 187 SetSchemaHistory(value SchemaHistory) 188 } 189 190 // SchemaRegistry represents the schema registry for a database. 191 // It is where dynamic schema updates are delivered into, 192 // and where schema is retrieved from at series read and write path. 193 type SchemaRegistry interface { 194 // GetLatestSchema gets the latest schema for the namespace. 195 // If proto is not enabled, nil, nil is returned. 196 GetLatestSchema(id ident.ID) (SchemaDescr, error) 197 198 // GetSchema gets the latest schema for the namespace. 199 // If proto is not enabled, nil, nil is returned. 200 GetSchema(id ident.ID, schemaID string) (SchemaDescr, error) 201 202 // SetSchemaHistory sets the schema history for the namespace. 203 // If proto is not enabled, nil is returned. 204 SetSchemaHistory(id ident.ID, history SchemaHistory) error 205 206 // RegisterListener registers a schema listener for the namespace. 207 // If proto is not enabled, nil, nil is returned 208 RegisterListener(id ident.ID, listener SchemaListener) (xresource.SimpleCloser, error) 209 210 // Close closes all the listeners. 211 Close() 212 } 213 214 // Metadata represents namespace metadata information. 215 type Metadata interface { 216 // Equal returns true if the provided value is equal to this one. 217 Equal(value Metadata) bool 218 219 // ID is the ID of the namespace. 220 ID() ident.ID 221 222 // Options is the namespace options. 223 Options() Options 224 } 225 226 // Map is mapping from known namespaces' ID to their Metadata. 227 type Map interface { 228 // Equal returns true if the provide value is equal to this one. 229 Equal(value Map) bool 230 231 // Get gets the metadata for the provided namespace. 232 Get(ident.ID) (Metadata, error) 233 234 // IDs returns the ID of known namespaces. 235 IDs() []ident.ID 236 237 // Metadatas returns the metadata of known namespaces. 238 Metadatas() []Metadata 239 } 240 241 // Watch is a watch on a namespace Map. 242 type Watch interface { 243 // C is the notification channel for when a value becomes available. 244 C() <-chan struct{} 245 246 // Get the current namespace map. 247 Get() Map 248 249 // Close closes the watch. 250 Close() error 251 } 252 253 // Registry is an un-changing container for a Map. 254 type Registry interface { 255 // Watch for the Registry changes. 256 Watch() (Watch, error) 257 258 // Close closes the registry. 259 Close() error 260 } 261 262 // Initializer can init new instances of namespace registries. 263 type Initializer interface { 264 // Init will return a new Registry. 265 Init() (Registry, error) 266 } 267 268 // DynamicOptions is a set of options for dynamic namespace registry. 269 type DynamicOptions interface { 270 // Validate validates the options. 271 Validate() error 272 273 // SetInstrumentOptions sets the instrumentation options. 274 SetInstrumentOptions(value instrument.Options) DynamicOptions 275 276 // InstrumentOptions returns the instrumentation options. 277 InstrumentOptions() instrument.Options 278 279 // SetConfigServiceClient sets the client of ConfigService. 280 SetConfigServiceClient(c client.Client) DynamicOptions 281 282 // ConfigServiceClient returns the client of ConfigService. 283 ConfigServiceClient() client.Client 284 285 // SetNamespaceRegistryKey sets the kv-store key used for the NamespaceRegistry. 286 SetNamespaceRegistryKey(k string) DynamicOptions 287 288 // NamespaceRegistryKey returns the kv-store key used for the NamespaceRegistry. 289 NamespaceRegistryKey() string 290 291 // SetForceColdWritesEnabled sets whether or not to force enable cold writes 292 // for all ns. 293 SetForceColdWritesEnabled(enabled bool) DynamicOptions 294 295 // ForceColdWritesEnabled returns whether or not to force enable cold writes 296 // for all ns. 297 ForceColdWritesEnabled() bool 298 299 // SetAllowEmptyInitialNamespaceRegistry sets whether to allow the initial 300 // namespace update to be empty or to wait indefinitely until namespaces are received. 301 SetAllowEmptyInitialNamespaceRegistry(value bool) DynamicOptions 302 303 // AllowEmptyInitialNamespaceRegistry returns whether to allow the initial 304 // namespace update to be empty or to wait indefinitely until namespaces are received. 305 AllowEmptyInitialNamespaceRegistry() bool 306 } 307 308 // NamespaceWatch watches for namespace updates. 309 type NamespaceWatch interface { 310 // Start starts the namespace watch. 311 Start() error 312 313 // Stop stops the namespace watch. 314 Stop() error 315 316 // close stops the watch, and releases any held resources. 317 Close() error 318 } 319 320 // NamespaceUpdater is a namespace updater function. 321 type NamespaceUpdater func(Map) error 322 323 // ExtendedOptions is the type for dynamically typed options. 324 type ExtendedOptions interface { 325 // ToProto converts ExtendedOptions to the corresponding protobuf message. 326 ToProto() (string, *protobuftypes.Struct) 327 328 // Validate validates the ExtendedOptions. 329 Validate() error 330 } 331 332 // AggregationOptions is a set of options for aggregating data 333 // within the namespace. 334 type AggregationOptions interface { 335 // Equal returns true if the provided value is equal to this one. 336 Equal(value AggregationOptions) bool 337 338 // SetAggregations sets the aggregations for this namespace. 339 SetAggregations(value []Aggregation) AggregationOptions 340 341 // Aggregations returns the aggregations for this namespace. 342 Aggregations() []Aggregation 343 } 344 345 // Aggregation describes data points within the namespace. 346 type Aggregation struct { 347 // Aggregated is true if data points are aggregated, false otherwise. 348 Aggregated bool 349 350 // Attributes specifies how to aggregate data when aggregated is set to true. 351 // This field is ignored when aggregated is false. 352 Attributes AggregatedAttributes 353 } 354 355 // AggregationAttributes are attributes specifying how data points should be aggregated. 356 type AggregatedAttributes struct { 357 // Resolution is the time range to aggregate data across. 358 Resolution time.Duration 359 360 // DownsampleOptions stores options around how data points are downsampled. 361 DownsampleOptions DownsampleOptions 362 } 363 364 // DownsampleOptions is a set of options related to downsampling data. 365 type DownsampleOptions struct { 366 // All indicates whether to send data points to this namespace. 367 // If set to false, this namespace will not receive data points. In this 368 // case, data will need to be sent to the namespace via another mechanism 369 // (e.g. rollup/recording rules). 370 All bool 371 } 372 373 // StagingStatus is the status of the namespace. 374 type StagingStatus uint8 375 376 const ( 377 // UnknownStagingStatus represents an unknown staging status. 378 // Namespaces created before StagingState was added to the namespace API 379 // will return UnknownStagingStatus. Callers should be prepared to handle this case. 380 UnknownStagingStatus StagingStatus = iota 381 // InitializingStagingStatus means the namespace is in the process of coming online for use. 382 InitializingStagingStatus 383 // ReadyStagingStatus means the namespace is ready for use. 384 ReadyStagingStatus 385 ) 386 387 var validStagingStatuses = []StagingStatus{ 388 UnknownStagingStatus, 389 InitializingStagingStatus, 390 ReadyStagingStatus, 391 }