config: replace use_write_cache with writecache.enabled

This is the way things are done with `grpc.tls` and in neo-go.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-01-27 14:30:19 +03:00 committed by Alex Vanin
parent 20b3ff84b3
commit e976a55358
9 changed files with 22 additions and 27 deletions

View file

@ -373,10 +373,8 @@ func initShardOptions(c *cfg) {
engineconfig.IterateShards(c.appCfg, require, func(sc *shardconfig.Config) { engineconfig.IterateShards(c.appCfg, require, func(sc *shardconfig.Config) {
var writeCacheOpts []writecache.Option var writeCacheOpts []writecache.Option
useWriteCache := sc.UseWriteCache() writeCacheCfg := sc.WriteCache()
if useWriteCache { if writeCacheCfg.Enabled() {
writeCacheCfg := sc.WriteCache()
writeCacheOpts = []writecache.Option{ writeCacheOpts = []writecache.Option{
writecache.WithPath(writeCacheCfg.Path()), writecache.WithPath(writeCacheCfg.Path()),
writecache.WithLogger(c.log), writecache.WithLogger(c.log),
@ -421,7 +419,7 @@ func initShardOptions(c *cfg) {
Timeout: 100 * time.Millisecond, Timeout: 100 * time.Millisecond,
}), }),
), ),
shard.WithWriteCache(useWriteCache), shard.WithWriteCache(writeCacheCfg.Enabled()),
shard.WithWriteCacheOptions(writeCacheOpts...), shard.WithWriteCacheOptions(writeCacheOpts...),
shard.WithRemoverBatchSize(gcCfg.RemoverBatchSize()), shard.WithRemoverBatchSize(gcCfg.RemoverBatchSize()),
shard.WithGCRemoverSleepInterval(gcCfg.RemoverSleepInterval()), shard.WithGCRemoverSleepInterval(gcCfg.RemoverSleepInterval()),

View file

@ -55,7 +55,7 @@ func TestEngineSection(t *testing.T) {
switch num { switch num {
case 0: case 0:
require.Equal(t, false, sc.UseWriteCache()) require.Equal(t, false, wc.Enabled())
require.Equal(t, "tmp/0/cache", wc.Path()) require.Equal(t, "tmp/0/cache", wc.Path())
require.EqualValues(t, 2147483648, wc.MemSize()) require.EqualValues(t, 2147483648, wc.MemSize())
@ -85,7 +85,7 @@ func TestEngineSection(t *testing.T) {
require.Equal(t, false, sc.RefillMetabase()) require.Equal(t, false, sc.RefillMetabase())
require.Equal(t, shard.ModeReadOnly, sc.Mode()) require.Equal(t, shard.ModeReadOnly, sc.Mode())
case 1: case 1:
require.Equal(t, true, sc.UseWriteCache()) require.Equal(t, true, wc.Enabled())
require.Equal(t, "tmp/1/cache", wc.Path()) require.Equal(t, "tmp/1/cache", wc.Path())
require.EqualValues(t, 2147483648, wc.MemSize()) require.EqualValues(t, 2147483648, wc.MemSize())

View file

@ -20,16 +20,6 @@ func From(c *config.Config) *Config {
return (*Config)(c) return (*Config)(c)
} }
// UseWriteCache returns value of "use_write_cache" config parameter.
//
// Panics if value is not a valid bool.
func (x *Config) UseWriteCache() bool {
return config.Bool(
(*config.Config)(x),
"use_write_cache",
)
}
// BlobStor returns "blobstor" subsection as a blobstorconfig.Config. // BlobStor returns "blobstor" subsection as a blobstorconfig.Config.
func (x *Config) BlobStor() *blobstorconfig.Config { func (x *Config) BlobStor() *blobstorconfig.Config {
return blobstorconfig.From( return blobstorconfig.From(

View file

@ -31,6 +31,13 @@ func From(c *config.Config) *Config {
return (*Config)(c) return (*Config)(c)
} }
// Enabled returns true if write-cache is enabled and false otherwise.
//
// Panics if value is not a boolean.
func (x *Config) Enabled() bool {
return config.Bool((*config.Config)(x), "enabled")
}
// Path returns value of "path" config parameter. // Path returns value of "path" config parameter.
// //
// Panics if value is not a non-empty string. // Panics if value is not a non-empty string.

View file

@ -76,7 +76,7 @@ NEOFS_STORAGE_SHARD_0_RESYNC_METABASE=false
### Flag to set shard mode ### Flag to set shard mode
NEOFS_STORAGE_SHARD_0_MODE=read-only NEOFS_STORAGE_SHARD_0_MODE=read-only
### Write cache config ### Write cache config
NEOFS_STORAGE_SHARD_0_USE_WRITE_CACHE=false NEOFS_STORAGE_SHARD_0_WRITECACHE_ENABLED=false
NEOFS_STORAGE_SHARD_0_WRITECACHE_PATH=tmp/0/cache NEOFS_STORAGE_SHARD_0_WRITECACHE_PATH=tmp/0/cache
NEOFS_STORAGE_SHARD_0_WRITECACHE_MEMCACHE_CAPACITY=2147483648 NEOFS_STORAGE_SHARD_0_WRITECACHE_MEMCACHE_CAPACITY=2147483648
NEOFS_STORAGE_SHARD_0_WRITECACHE_SMALL_OBJECT_SIZE=16384 NEOFS_STORAGE_SHARD_0_WRITECACHE_SMALL_OBJECT_SIZE=16384
@ -110,7 +110,7 @@ NEOFS_STORAGE_SHARD_1_RESYNC_METABASE=true
### Flag to set shard mode ### Flag to set shard mode
NEOFS_STORAGE_SHARD_1_MODE=read-write NEOFS_STORAGE_SHARD_1_MODE=read-write
### Write cache config ### Write cache config
NEOFS_STORAGE_SHARD_1_USE_WRITE_CACHE=true NEOFS_STORAGE_SHARD_1_WRITECACHE_ENABLED=true
NEOFS_STORAGE_SHARD_1_WRITECACHE_PATH=tmp/1/cache NEOFS_STORAGE_SHARD_1_WRITECACHE_PATH=tmp/1/cache
NEOFS_STORAGE_SHARD_1_WRITECACHE_MEMCACHE_CAPACITY=2147483648 NEOFS_STORAGE_SHARD_1_WRITECACHE_MEMCACHE_CAPACITY=2147483648
NEOFS_STORAGE_SHARD_1_WRITECACHE_SMALL_OBJECT_SIZE=16384 NEOFS_STORAGE_SHARD_1_WRITECACHE_SMALL_OBJECT_SIZE=16384

View file

@ -119,8 +119,8 @@
"0": { "0": {
"mode": "read-only", "mode": "read-only",
"resync_metabase": false, "resync_metabase": false,
"use_write_cache": false,
"writecache": { "writecache": {
"enabled": false,
"path": "tmp/0/cache", "path": "tmp/0/cache",
"memcache_capacity": 2147483648, "memcache_capacity": 2147483648,
"small_object_size": 16384, "small_object_size": 16384,
@ -156,8 +156,8 @@
"1": { "1": {
"mode": "read-write", "mode": "read-write",
"resync_metabase": true, "resync_metabase": true,
"use_write_cache": true,
"writecache": { "writecache": {
"enabled": true,
"path": "tmp/1/cache", "path": "tmp/1/cache",
"memcache_capacity": 2147483648, "memcache_capacity": 2147483648,
"small_object_size": 16384, "small_object_size": 16384,

View file

@ -102,9 +102,8 @@ storage:
default: # section with the default shard parameters default: # section with the default shard parameters
resync_metabase: true # sync metabase with blobstor on start, expensive, leave false until complete understanding resync_metabase: true # sync metabase with blobstor on start, expensive, leave false until complete understanding
use_write_cache: true # use write-cache
writecache: writecache:
enabled: true
memcache_capacity: 2147483648 # approximate RAM usage limit for "small" objects, bytes memcache_capacity: 2147483648 # approximate RAM usage limit for "small" objects, bytes
small_object_size: 16384 # size threshold for "small" objects which are cached in key-value DB, not in FS, bytes small_object_size: 16384 # size threshold for "small" objects which are cached in key-value DB, not in FS, bytes
max_object_size: 134217728 # size threshold for "big" objects which bypass write-cache and go to the storage directly, bytes max_object_size: 134217728 # size threshold for "big" objects which bypass write-cache and go to the storage directly, bytes
@ -134,9 +133,8 @@ storage:
mode: "read-only" # mode of the shard, must be one of the: "read-write" (default), "read-only" mode: "read-only" # mode of the shard, must be one of the: "read-write" (default), "read-only"
resync_metabase: false # sync metabase with blobstor on start, expensive, leave false until complete understanding resync_metabase: false # sync metabase with blobstor on start, expensive, leave false until complete understanding
use_write_cache: false # use write-cache
writecache: writecache:
enabled: false
path: tmp/0/cache # write-cache root directory path: tmp/0/cache # write-cache root directory
capacity: 3221225472 # approximate write-cache total size, bytes capacity: 3221225472 # approximate write-cache total size, bytes

View file

@ -20,7 +20,6 @@ storage:
shard_num: 1 shard_num: 1
shard: shard:
0: 0:
use_write_cache: false
metabase: metabase:
path: <storage-path>/metabase path: <storage-path>/metabase
perm: 0600 perm: 0600
@ -31,6 +30,8 @@ storage:
opened_cache_capacity: 32 opened_cache_capacity: 32
depth: 1 depth: 1
width: 1 width: 1
writecache:
enabled: false
gc: gc:
remover_batch_size: 100 remover_batch_size: 100
remover_sleep_interval: 1m remover_sleep_interval: 1m

View file

@ -39,7 +39,6 @@ storage:
shard_num: 1 shard_num: 1
shard: shard:
0: 0:
use_write_cache: false
metabase: metabase:
path: /storage/metabase path: /storage/metabase
perm: 0777 perm: 0777
@ -50,6 +49,8 @@ storage:
opened_cache_capacity: 32 opened_cache_capacity: 32
depth: 1 depth: 1
width: 1 width: 1
writecache:
enabled: false
gc: gc:
remover_batch_size: 100 remover_batch_size: 100
remover_sleep_interval: 1m remover_sleep_interval: 1m