Skip to content

Commit 3364ab5

Browse files
committed
writecache: drop BoltDB
Previously, the write-cache has 2 components: bolt database and fstree. BoltDB is absolutely useless for write caching given that the cache uses SSD, so it was decided to drop this database. Drop all code related to BoltDB. Migrate from this database to the main storage, by flushing objects. Remove config parameters for the write-cache: `small_object_size`, `workers_number`, `max_batch_delay`, `max_batch_size`. Update docs. Rewrite lens commands for the current version of the write-cache. Closes #3076. Signed-off-by: Andrey Butusov <[email protected]>
1 parent b4e5d1b commit 3364ab5

File tree

36 files changed

+174
-790
lines changed

36 files changed

+174
-790
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Changelog for NeoFS Node
2222

2323
### Removed
2424
- Drop creating new eacl tables with public keys (#3096)
25+
- BoltDB from write-cache (#3091)
2526

2627
### Updated
2728

@@ -31,6 +32,12 @@ since this realese it is not supported to create new eACL table with keys,
3132
use addresses instead.
3233
For more information call `neofs-cli acl extended create -h`.
3334

35+
`small_object_size`, `workers_number`, `max_batch_size` and `max_batch_delay`
36+
paramteters are removed from `writecache` config. These parameters are related
37+
to the BoltDB part of the write-cache, which is dropped from the code.
38+
Also, because of this, there will be automatic migration from BoltDB by flushing
39+
objects to the main storage and removing database file.
40+
3441
## [0.44.2] - 2024-12-20
3542

3643
### Fixed

cmd/neofs-lens/internal/printers.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ func PrintStorageObjectStatus(cmd *cobra.Command, status engine.ObjectStatus) {
9595
if shard.Shard.Metabase.Error != nil {
9696
cmd.Printf("\t\tMetabase object error:\t%v\n", shard.Shard.Metabase.Error)
9797
}
98-
if shard.Shard.Writecache.PathDB != "" || shard.Shard.Writecache.PathFSTree != "" {
98+
if shard.Shard.Writecache.PathFSTree != "" {
9999
cmd.Printf("\tWritecache\n")
100-
cmd.Printf("\t\tWritecache DB path:\t%s\n", shard.Shard.Writecache.PathDB)
101100
cmd.Printf("\t\tWritecache FSTree path:\t%s\n", shard.Shard.Writecache.PathFSTree)
102101
}
103102
cmd.Println()

cmd/neofs-lens/internal/storage/root.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ func openEngine() (*engine.StorageEngine, error) {
8282

8383
wc.Enabled = true
8484
wc.Path = writeCacheCfg.Path()
85-
wc.MaxBatchSize = writeCacheCfg.BoltDB().MaxBatchSize()
86-
wc.MaxBatchDelay = writeCacheCfg.BoltDB().MaxBatchDelay()
8785
wc.MaxObjSize = writeCacheCfg.MaxObjectSize()
88-
wc.SmallObjectSize = writeCacheCfg.SmallObjectSize()
89-
wc.FlushWorkerCount = writeCacheCfg.WorkersNumber()
9086
wc.SizeLimit = writeCacheCfg.SizeLimit()
9187
wc.NoSync = writeCacheCfg.NoSync()
9288
}
@@ -166,11 +162,7 @@ func openEngine() (*engine.StorageEngine, error) {
166162
if wcRead := shCfg.WritecacheCfg; wcRead.Enabled {
167163
writeCacheOpts = append(writeCacheOpts,
168164
writecache.WithPath(wcRead.Path),
169-
writecache.WithMaxBatchSize(wcRead.MaxBatchSize),
170-
writecache.WithMaxBatchDelay(wcRead.MaxBatchDelay),
171165
writecache.WithMaxObjectSize(wcRead.MaxObjSize),
172-
writecache.WithSmallObjectSize(wcRead.SmallObjectSize),
173-
writecache.WithFlushWorkersCount(wcRead.FlushWorkerCount),
174166
writecache.WithMaxCacheSize(wcRead.SizeLimit),
175167
writecache.WithNoSync(wcRead.NoSync),
176168
)

cmd/neofs-lens/internal/writecache/get.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import (
44
"fmt"
55

66
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
7-
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
8-
"github.com/nspcc-dev/neofs-sdk-go/object"
7+
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
98
"github.com/spf13/cobra"
109
)
1110

@@ -25,23 +24,23 @@ func init() {
2524
}
2625

2726
func getFunc(cmd *cobra.Command, _ []string) error {
28-
db, err := openWC()
27+
wc, err := openWC()
2928
if err != nil {
3029
return err
3130
}
32-
defer db.Close()
31+
defer wc.Close()
3332

34-
data, err := writecache.Get(db, []byte(vAddress))
33+
addr, err := oid.DecodeAddressString(vAddress)
3534
if err != nil {
36-
return fmt.Errorf("could not fetch object: %w", err)
35+
return fmt.Errorf("invalid address: %w", err)
3736
}
3837

39-
var o object.Object
40-
if err := o.Unmarshal(data); err != nil {
41-
return fmt.Errorf("could not unmarshal object: %w", err)
38+
obj, err := wc.Get(addr)
39+
if err != nil {
40+
return fmt.Errorf("could not fetch object: %w", err)
4241
}
4342

44-
common.PrintObjectHeader(cmd, o)
43+
common.PrintObjectHeader(cmd, *obj)
4544

46-
return common.WriteObjectToFile(cmd, vOut, data, vPayloadOnly)
45+
return common.WriteObjectToFile(cmd, vOut, obj.Marshal(), vPayloadOnly)
4746
}

cmd/neofs-lens/internal/writecache/list.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"io"
66

77
common "github.com/nspcc-dev/neofs-node/cmd/neofs-lens/internal"
8-
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
98
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
109
"github.com/spf13/cobra"
1110
)
@@ -26,18 +25,18 @@ func listFunc(cmd *cobra.Command, _ []string) error {
2625
// other targets can be supported
2726
w := cmd.OutOrStderr()
2827

29-
wAddr := func(addr oid.Address) error {
28+
wAddr := func(addr oid.Address, _ []byte) error {
3029
_, err := io.WriteString(w, fmt.Sprintf("%s\n", addr))
3130
return err
3231
}
3332

34-
db, err := openWC()
33+
wc, err := openWC()
3534
if err != nil {
3635
return err
3736
}
38-
defer db.Close()
37+
defer wc.Close()
3938

40-
err = writecache.IterateDB(db, wAddr)
39+
err = wc.Iterate(wAddr, true)
4140
if err != nil {
4241
return fmt.Errorf("write-cache iterator failure: %w", err)
4342
}

cmd/neofs-lens/internal/writecache/root.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/writecache"
77
"github.com/spf13/cobra"
8-
"go.etcd.io/bbolt"
98
)
109

1110
var (
@@ -26,11 +25,14 @@ func init() {
2625
Root.AddCommand(getCMD)
2726
}
2827

29-
func openWC() (*bbolt.DB, error) {
30-
db, err := writecache.OpenDB(vPath, true)
28+
// openWC opens and returns read-only writecache.Cache located in vPath.
29+
func openWC() (writecache.Cache, error) {
30+
wc := writecache.New(writecache.WithPath(vPath))
31+
32+
err := wc.Open(true)
3133
if err != nil {
32-
return nil, fmt.Errorf("could not open write-cache db: %w", err)
34+
return nil, fmt.Errorf("could not open write-cache: %w", err)
3335
}
3436

35-
return db, nil
37+
return wc, nil
3638
}

cmd/neofs-node/config.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,7 @@ func (a *applicationConfiguration) readConfig(c *config.Config) error {
195195

196196
wc.Enabled = true
197197
wc.Path = writeCacheCfg.Path()
198-
wc.MaxBatchSize = writeCacheCfg.BoltDB().MaxBatchSize()
199-
wc.MaxBatchDelay = writeCacheCfg.BoltDB().MaxBatchDelay()
200198
wc.MaxObjSize = writeCacheCfg.MaxObjectSize()
201-
wc.SmallObjectSize = writeCacheCfg.SmallObjectSize()
202-
wc.FlushWorkerCount = writeCacheCfg.WorkersNumber()
203199
wc.SizeLimit = writeCacheCfg.SizeLimit()
204200
wc.NoSync = writeCacheCfg.NoSync()
205201
}

cmd/neofs-node/config/engine/config_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ func TestEngineSection(t *testing.T) {
7474
require.Equal(t, true, wc.NoSync())
7575

7676
require.Equal(t, "tmp/0/cache", wc.Path())
77-
require.EqualValues(t, 16384, wc.SmallObjectSize())
7877
require.EqualValues(t, 134217728, wc.MaxObjectSize())
79-
require.EqualValues(t, 30, wc.WorkersNumber())
8078
require.EqualValues(t, 3221225472, wc.SizeLimit())
8179

8280
require.Equal(t, "tmp/0/meta", meta.Path())
@@ -117,9 +115,7 @@ func TestEngineSection(t *testing.T) {
117115
require.Equal(t, false, wc.NoSync())
118116

119117
require.Equal(t, "tmp/1/cache", wc.Path())
120-
require.EqualValues(t, 16384, wc.SmallObjectSize())
121118
require.EqualValues(t, 134217728, wc.MaxObjectSize())
122-
require.EqualValues(t, 30, wc.WorkersNumber())
123119
require.EqualValues(t, 4294967296, wc.SizeLimit())
124120

125121
require.Equal(t, "tmp/1/meta", meta.Path())

cmd/neofs-node/config/engine/shard/writecache/config.go

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@ package writecacheconfig
22

33
import (
44
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
5-
boltdbconfig "github.com/nspcc-dev/neofs-node/cmd/neofs-node/config/engine/shard/boltdb"
65
)
76

87
// Config is a wrapper over the config section
98
// which provides access to WriteCache configurations.
109
type Config config.Config
1110

1211
const (
13-
// SmallSizeDefault is a default size of small objects.
14-
SmallSizeDefault = 32 << 10
15-
1612
// MaxSizeDefault is a default value of the object payload size limit.
1713
MaxSizeDefault = 64 << 20
1814

19-
// WorkersNumberDefault is a default number of workers.
20-
WorkersNumberDefault = 20
21-
2215
// SizeLimitDefault is a default write-cache size limit.
2316
SizeLimitDefault = 1 << 30
2417
)
@@ -51,22 +44,6 @@ func (x *Config) Path() string {
5144
return p
5245
}
5346

54-
// SmallObjectSize returns the value of "small_object_size" config parameter.
55-
//
56-
// Returns SmallSizeDefault if the value is not a positive number.
57-
func (x *Config) SmallObjectSize() uint64 {
58-
s := config.SizeInBytesSafe(
59-
(*config.Config)(x),
60-
"small_object_size",
61-
)
62-
63-
if s > 0 {
64-
return s
65-
}
66-
67-
return SmallSizeDefault
68-
}
69-
7047
// MaxObjectSize returns the value of "max_object_size" config parameter.
7148
//
7249
// Returns MaxSizeDefault if the value is not a positive number.
@@ -83,22 +60,6 @@ func (x *Config) MaxObjectSize() uint64 {
8360
return MaxSizeDefault
8461
}
8562

86-
// WorkersNumber returns the value of "workers_number" config parameter.
87-
//
88-
// Returns WorkersNumberDefault if the value is not a positive number.
89-
func (x *Config) WorkersNumber() int {
90-
c := config.IntSafe(
91-
(*config.Config)(x),
92-
"workers_number",
93-
)
94-
95-
if c > 0 {
96-
return int(c)
97-
}
98-
99-
return WorkersNumberDefault
100-
}
101-
10263
// SizeLimit returns the value of "capacity" config parameter.
10364
//
10465
// Returns SizeLimitDefault if the value is not a positive number.
@@ -121,8 +82,3 @@ func (x *Config) SizeLimit() uint64 {
12182
func (x *Config) NoSync() bool {
12283
return config.BoolSafe((*config.Config)(x), "no_sync")
12384
}
124-
125-
// BoltDB returns config instance for querying bolt db specific parameters.
126-
func (x *Config) BoltDB() *boltdbconfig.Config {
127-
return (*boltdbconfig.Config)(x)
128-
}

cmd/neofs-node/config/internal/validate/config.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,11 @@ type shardDetails struct {
141141
ResyncMetabase bool `mapstructure:"resync_metabase"`
142142

143143
WriteCache struct {
144-
Enabled bool `mapstructure:"enabled"`
145-
Path string `mapstructure:"path"`
146-
Capacity string `mapstructure:"capacity"`
147-
NoSync bool `mapstructure:"no_sync"`
148-
SmallObjectSize string `mapstructure:"small_object_size"`
149-
MaxObjectSize string `mapstructure:"max_object_size"`
150-
WorkersNumber int `mapstructure:"workers_number"`
151-
MaxBatchDelay time.Duration `mapstructure:"max_batch_delay"`
152-
MaxBatchSize int `mapstructure:"max_batch_size"`
144+
Enabled bool `mapstructure:"enabled"`
145+
Path string `mapstructure:"path"`
146+
Capacity string `mapstructure:"capacity"`
147+
NoSync bool `mapstructure:"no_sync"`
148+
MaxObjectSize string `mapstructure:"max_object_size"`
153149
} `mapstructure:"writecache"`
154150

155151
Metabase struct {

0 commit comments

Comments
 (0)