Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metabase: Open(readOnly) moves metabase in RO mode #3000

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ attribute, which is used for container domain name in NNS contracts (#2954)
- False negative connection to NeoFS chain in multi-endpoint setup with at least one live node (#2986)
- Overriding the default container and object attributes only with the appropriate flags (#2985)
- RPC client reconnection failures leading to complete SN failure (#2797)
- `meta.DB.Open(readOnly)` moves metabase in RO mode (#3000)

### Changed
- `ObjectService`'s `Put` RPC handler caches up to 10K lists of per-object sorted container nodes (#2901)
Expand Down
4 changes: 4 additions & 0 deletions pkg/local_object_storage/metabase/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (db *DB) Open(readOnly bool) error {
}
db.boltOptions.ReadOnly = readOnly

if readOnly {
db.mode = mode.ReadOnly
}

return db.openBolt()
}

Expand Down
38 changes: 38 additions & 0 deletions pkg/local_object_storage/metabase/control_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package meta_test

import (
"path/filepath"
"testing"

"github.com/nspcc-dev/neofs-node/pkg/core/object"
Expand Down Expand Up @@ -50,6 +51,43 @@ func TestReset(t *testing.T) {
assertExists(addr, false, nil)
}

func TestOpenRO(t *testing.T) {
path := filepath.Join(t.TempDir(), "meta")

db := meta.New(
meta.WithPath(path),
meta.WithPermissions(0o600),
meta.WithEpochState(epochState{}),
)

require.NoError(t, db.Open(false))
require.NoError(t, db.Init())

obj := generateObject(t)
addr := object.AddressOf(obj)

require.NoError(t, putBig(db, obj))
exists, err := metaExists(db, addr)
require.NoError(t, err)
require.True(t, exists)

require.NoError(t, db.Close())

// Open in RO mode
require.NoError(t, db.Open(true))

// we can't write
err = putBig(db, obj)
require.ErrorIs(t, err, meta.ErrReadOnlyMode)

// but can read
exists, err = metaExists(db, addr)
require.NoError(t, err)
require.True(t, exists)

require.NoError(t, db.Close())
}

func metaExists(db *meta.DB, addr oid.Address) (bool, error) {
var existsPrm meta.ExistsPrm
existsPrm.SetAddress(addr)
Expand Down
Loading