forked from nspcc-dev/neofs-node
-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.go
138 lines (119 loc) · 3.56 KB
/
config.go
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package shardconfig
import (
"fmt"
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
blobstorconfig "github.com/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/blobstor"
gcconfig "github.com/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/gc"
metabaseconfig "github.com/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/metabase"
piloramaconfig "github.com/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/pilorama"
writecacheconfig "github.com/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/engine/shard/writecache"
"github.com/TrueCloudLab/frostfs-node/pkg/local_object_storage/shard/mode"
)
// Config is a wrapper over the config section
// which provides access to Shard configurations.
type Config config.Config
// SmallSizeLimitDefault is a default limit of small objects payload in bytes.
const SmallSizeLimitDefault = 1 << 20
// From wraps config section into Config.
func From(c *config.Config) *Config {
return (*Config)(c)
}
// Compress returns the value of "compress" config parameter.
//
// Returns false if the value is not a valid bool.
func (x *Config) Compress() bool {
return config.BoolSafe(
(*config.Config)(x),
"compress",
)
}
// UncompressableContentTypes returns the value of "compress_skip_content_types" config parameter.
//
// Returns nil if a the value is missing or is invalid.
func (x *Config) UncompressableContentTypes() []string {
return config.StringSliceSafe(
(*config.Config)(x),
"compression_exclude_content_types")
}
// SmallSizeLimit returns the value of "small_object_size" config parameter.
//
// Returns SmallSizeLimitDefault if the value is not a positive number.
func (x *Config) SmallSizeLimit() uint64 {
l := config.SizeInBytesSafe(
(*config.Config)(x),
"small_object_size",
)
if l > 0 {
return l
}
return SmallSizeLimitDefault
}
// BlobStor returns "blobstor" subsection as a blobstorconfig.Config.
func (x *Config) BlobStor() *blobstorconfig.Config {
return blobstorconfig.From(
(*config.Config)(x).
Sub("blobstor"),
)
}
// Metabase returns "metabase" subsection as a metabaseconfig.Config.
func (x *Config) Metabase() *metabaseconfig.Config {
return metabaseconfig.From(
(*config.Config)(x).
Sub("metabase"),
)
}
// WriteCache returns "writecache" subsection as a writecacheconfig.Config.
func (x *Config) WriteCache() *writecacheconfig.Config {
return writecacheconfig.From(
(*config.Config)(x).
Sub("writecache"),
)
}
// Pilorama returns "pilorama" subsection as a piloramaconfig.Config.
func (x *Config) Pilorama() *piloramaconfig.Config {
return piloramaconfig.From(
(*config.Config)(x).
Sub("pilorama"),
)
}
// GC returns "gc" subsection as a gcconfig.Config.
func (x *Config) GC() *gcconfig.Config {
return gcconfig.From(
(*config.Config)(x).
Sub("gc"),
)
}
// RefillMetabase returns the value of "resync_metabase" config parameter.
//
// Returns false if the value is not a valid bool.
func (x *Config) RefillMetabase() bool {
return config.BoolSafe(
(*config.Config)(x),
"resync_metabase",
)
}
// Mode return the value of "mode" config parameter.
//
// Panics if read the value is not one of predefined
// shard modes.
func (x *Config) Mode() (m mode.Mode) {
s := config.StringSafe(
(*config.Config)(x),
"mode",
)
switch s {
case "read-write", "":
m = mode.ReadWrite
case "read-only":
m = mode.ReadOnly
case "degraded":
m = mode.Degraded
case "degraded-read-only":
m = mode.DegradedReadOnly
case "disabled":
m = mode.Disabled
default:
panic(fmt.Sprintf("unknown shard mode: %s", s))
}
return
}