-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
118 lines (103 loc) · 4.65 KB
/
config.go
File metadata and controls
118 lines (103 loc) · 4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright observIQ, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package badgerextension
import (
"errors"
"time"
)
// Config configures the badger storage extension
type Config struct {
Directory *DirectoryConfig `mapstructure:"directory,omitempty"`
SyncWrites bool `mapstructure:"sync_writes"`
Memory *MemoryConfig `mapstructure:"memory,omitempty"`
Compaction *CompactionConfig `mapstructure:"compaction,omitempty"`
BlobGarbageCollection *BlobGarbageCollectionConfig `mapstructure:"blob_garbage_collection,omitempty"`
Telemetry *TelemetryConfig `mapstructure:"telemetry,omitempty"`
_ struct{} // prevent unkeyed literal initialization
}
// DirectoryConfig configures the file storage parameters for the badger storage extension
type DirectoryConfig struct {
Path string `mapstructure:"path"`
PathPrefix string `mapstructure:"path_prefix"`
_ struct{} // prevent unkeyed literal initialization
}
// BlobGarbageCollectionConfig configures the blob garbage collection
type BlobGarbageCollectionConfig struct {
Interval time.Duration `mapstructure:"interval"`
DiscardRatio float64 `mapstructure:"discard_ratio"`
_ struct{} // prevent unkeyed literal initialization
}
// MemoryConfig configures the memory parameters for the badger storage extension; this is intended to be used
// for fine tuning if desired and should be considered an advanced configuration option.
type MemoryConfig struct {
TableSize int64 `mapstructure:"table_size"`
BlockCacheSize int64 `mapstructure:"block_cache_size"`
ValueLogFileSize int64 `mapstructure:"value_log_file_size"`
_ struct{} // prevent unkeyed literal initialization
}
// CompactionConfig configures LSM tree compaction behavior for more aggressive cleanup of deleted data.
type CompactionConfig struct {
// NumCompactors is the number of background compaction workers. Higher values = more aggressive compaction.
NumCompactors int `mapstructure:"num_compactors"`
// NumLevelZeroTables is the number of L0 tables that triggers compaction. Lower values = earlier compaction.
NumLevelZeroTables int `mapstructure:"num_level_zero_tables"`
// NumLevelZeroTablesStall is the number of L0 tables that stalls writes until compaction catches up.
NumLevelZeroTablesStall int `mapstructure:"num_level_zero_tables_stall"`
_ struct{} // prevent unkeyed literal initialization
}
// TelemetryConfig configures the telemetry parameters for the badger storage extension
type TelemetryConfig struct {
// whether or not to enable telemetry
Enabled bool `mapstructure:"enabled"`
// the interval at which to update the telemetry
UpdateInterval time.Duration `mapstructure:"update_interval"`
_ struct{} // prevent unkeyed literal initialization
}
// Validate validate the config
func (c *Config) Validate() error {
if c.Directory == nil || c.Directory.Path == "" {
return errors.New("a file path for the directory is required")
}
if c.BlobGarbageCollection != nil {
if c.BlobGarbageCollection.Interval < 0 {
return errors.New("blob garbage collection interval cannot be negative")
}
if c.BlobGarbageCollection.DiscardRatio <= 0 || c.BlobGarbageCollection.DiscardRatio >= 1 {
return errors.New("blob garbage collection discard ratio must be between 0 and 1")
}
}
if c.Memory != nil {
if c.Memory.TableSize < 0 {
return errors.New("memory table size must not be negative")
}
if c.Memory.BlockCacheSize < 0 {
return errors.New("memory block cache size must not be negative")
}
if c.Memory.ValueLogFileSize < 0 {
return errors.New("value log file size must not be negative")
}
}
if c.Compaction != nil {
if c.Compaction.NumCompactors < 0 {
return errors.New("number of compactors must not be negative")
}
if c.Compaction.NumLevelZeroTables < 0 {
return errors.New("number of level zero tables must not be negative")
}
if c.Compaction.NumLevelZeroTablesStall < 0 {
return errors.New("number of level zero tables stall must not be negative")
}
}
return nil
}