forked from TrueCloudLab/frostfs-node
[#791] blobovnicza: Support read-only mode
There is a need to open Blobovnicza instances in read-only mode in some cases. Add `ReadOnly` option. Do not create dir path in RO. Open underlying BoltDB instance with ReadOnly flag. Document thal all writing operations should not be called in ro (otherwise BoltDB txs fail). Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
cc5d3288a1
commit
f73c5c2259
4 changed files with 27 additions and 7 deletions
|
@ -106,3 +106,10 @@ func WithLogger(l *logger.Logger) Option {
|
|||
c.log = l.With(zap.String("component", "Blobovnicza"))
|
||||
}
|
||||
}
|
||||
|
||||
// ReadOnly returns option to open Blobovnicza in read-only mode.
|
||||
func ReadOnly() Option {
|
||||
return func(c *cfg) {
|
||||
c.boltOptions.ReadOnly = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,17 +16,24 @@ import (
|
|||
func (b *Blobovnicza) Open() error {
|
||||
b.log.Debug("creating directory for BoltDB",
|
||||
zap.String("path", b.path),
|
||||
zap.Bool("ro", b.boltOptions.ReadOnly),
|
||||
)
|
||||
|
||||
err := util.MkdirAllX(path.Dir(b.path), b.perm)
|
||||
if err == nil {
|
||||
var err error
|
||||
|
||||
if !b.boltOptions.ReadOnly {
|
||||
err = util.MkdirAllX(path.Dir(b.path), b.perm)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
b.log.Debug("opening BoltDB",
|
||||
zap.String("path", b.path),
|
||||
zap.Stringer("permissions", b.perm),
|
||||
)
|
||||
|
||||
b.boltDB, err = bbolt.Open(b.path, b.perm, b.boltOptions)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
@ -34,6 +41,8 @@ func (b *Blobovnicza) Open() error {
|
|||
// Init initializes internal database structure.
|
||||
//
|
||||
// If Blobovnicza is already initialized, then no action is taken.
|
||||
//
|
||||
// Should not be called in read-only configuration.
|
||||
func (b *Blobovnicza) Init() error {
|
||||
b.log.Debug("initializing...",
|
||||
zap.Uint64("object size limit", b.objSizeLimit),
|
||||
|
|
|
@ -27,6 +27,8 @@ func (p *DeletePrm) SetAddress(addr *objectSDK.Address) {
|
|||
// did not allow to completely delete the object.
|
||||
//
|
||||
// Returns ErrNotFound if the object to be deleted is not in blobovnicza.
|
||||
//
|
||||
// Should not be called in read-only configuration.
|
||||
func (b *Blobovnicza) Delete(prm *DeletePrm) (*DeleteRes, error) {
|
||||
addrKey := addressKey(prm.addr)
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@ func (p *PutPrm) SetMarshaledObject(data []byte) {
|
|||
// did not allow to completely save the object.
|
||||
//
|
||||
// Returns ErrFull if blobovnicza is filled.
|
||||
//
|
||||
// Should not be called in read-only configuration.
|
||||
func (b *Blobovnicza) Put(prm *PutPrm) (*PutRes, error) {
|
||||
addr := prm.addr
|
||||
if addr == nil {
|
||||
|
|
Loading…
Reference in a new issue