forked from TrueCloudLab/frostfs-node
[#1523] local_object_storage: Unify parameters for the Exists
operation
Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
d75d030a90
commit
ca15083a50
6 changed files with 51 additions and 59 deletions
|
@ -4,23 +4,23 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobovnicza"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (b *Blobovniczas) Exists(addr oid.Address) (bool, error) {
|
func (b *Blobovniczas) Exists(prm common.ExistsPrm) (common.ExistsRes, error) {
|
||||||
activeCache := make(map[string]struct{})
|
activeCache := make(map[string]struct{})
|
||||||
|
|
||||||
var prm blobovnicza.GetPrm
|
var gPrm blobovnicza.GetPrm
|
||||||
prm.SetAddress(addr)
|
gPrm.SetAddress(prm.Address)
|
||||||
|
|
||||||
var found bool
|
var found bool
|
||||||
err := b.iterateSortedLeaves(&addr, func(p string) (bool, error) {
|
err := b.iterateSortedLeaves(&prm.Address, func(p string) (bool, error) {
|
||||||
dirPath := filepath.Dir(p)
|
dirPath := filepath.Dir(p)
|
||||||
|
|
||||||
_, ok := activeCache[dirPath]
|
_, ok := activeCache[dirPath]
|
||||||
|
|
||||||
_, err := b.getObjectFromLevel(prm, p, !ok)
|
_, err := b.getObjectFromLevel(gPrm, p, !ok)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !blobovnicza.IsErrNotFound(err) {
|
if !blobovnicza.IsErrNotFound(err) {
|
||||||
b.log.Debug("could not get object from level",
|
b.log.Debug("could not get object from level",
|
||||||
|
@ -34,5 +34,5 @@ func (b *Blobovniczas) Exists(addr oid.Address) (bool, error) {
|
||||||
return found, nil
|
return found, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
return found, err
|
return common.ExistsRes{Exists: found}, err
|
||||||
}
|
}
|
||||||
|
|
13
pkg/local_object_storage/blobstor/common/exists.go
Normal file
13
pkg/local_object_storage/blobstor/common/exists.go
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
package common
|
||||||
|
|
||||||
|
import oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
|
|
||||||
|
// ExistsPrm groups the parameters of Exists operation.
|
||||||
|
type ExistsPrm struct {
|
||||||
|
Address oid.Address
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExistsRes groups the resulting values of Exists operation.
|
||||||
|
type ExistsRes struct {
|
||||||
|
Exists bool
|
||||||
|
}
|
|
@ -3,33 +3,18 @@ package blobstor
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExistsPrm groups the parameters of Exists operation.
|
|
||||||
type ExistsPrm struct {
|
|
||||||
address
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExistsRes groups the resulting values of Exists operation.
|
|
||||||
type ExistsRes struct {
|
|
||||||
exists bool
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exists returns the fact that the object is in BLOB storage.
|
|
||||||
func (r ExistsRes) Exists() bool {
|
|
||||||
return r.exists
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exists checks if the object is presented in BLOB storage.
|
// Exists checks if the object is presented in BLOB storage.
|
||||||
//
|
//
|
||||||
// Returns any error encountered that did not allow
|
// Returns any error encountered that did not allow
|
||||||
// to completely check object existence.
|
// to completely check object existence.
|
||||||
func (b *BlobStor) Exists(prm ExistsPrm) (ExistsRes, error) {
|
func (b *BlobStor) Exists(prm common.ExistsPrm) (common.ExistsRes, error) {
|
||||||
// check presence in shallow dir first (cheaper)
|
// check presence in shallow dir first (cheaper)
|
||||||
exists, err := b.existsBig(prm.addr)
|
res, err := b.existsBig(prm)
|
||||||
|
|
||||||
// If there was an error during existence check below,
|
// If there was an error during existence check below,
|
||||||
// it will be returned unless object was found in blobovnicza.
|
// it will be returned unless object was found in blobovnicza.
|
||||||
|
@ -40,13 +25,13 @@ func (b *BlobStor) Exists(prm ExistsPrm) (ExistsRes, error) {
|
||||||
// error | found | log the error, return true, nil
|
// error | found | log the error, return true, nil
|
||||||
// error | not found | return the error
|
// error | not found | return the error
|
||||||
// error | error | log the first error, return the second
|
// error | error | log the first error, return the second
|
||||||
if !exists {
|
if !res.Exists {
|
||||||
var smallErr error
|
var smallErr error
|
||||||
|
|
||||||
exists, smallErr = b.existsSmall(prm.addr)
|
res, smallErr = b.existsSmall(prm)
|
||||||
if err != nil && (smallErr != nil || exists) {
|
if err != nil && (smallErr != nil || res.Exists) {
|
||||||
b.log.Warn("error occured during object existence checking",
|
b.log.Warn("error occured during object existence checking",
|
||||||
zap.Stringer("address", prm.addr),
|
zap.Stringer("address", prm.Address),
|
||||||
zap.String("error", err.Error()))
|
zap.String("error", err.Error()))
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
|
@ -55,24 +40,20 @@ func (b *BlobStor) Exists(prm ExistsPrm) (ExistsRes, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
return res, err
|
||||||
return ExistsRes{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ExistsRes{exists: exists}, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// checks if object is presented in shallow dir.
|
// checks if object is presented in shallow dir.
|
||||||
func (b *BlobStor) existsBig(addr oid.Address) (bool, error) {
|
func (b *BlobStor) existsBig(prm common.ExistsPrm) (common.ExistsRes, error) {
|
||||||
_, err := b.fsTree.Exists(addr)
|
_, err := b.fsTree.Exists(prm.Address)
|
||||||
if errors.Is(err, fstree.ErrFileNotFound) {
|
if errors.Is(err, fstree.ErrFileNotFound) {
|
||||||
return false, nil
|
return common.ExistsRes{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return err == nil, err
|
return common.ExistsRes{Exists: err == nil}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// existsSmall checks if object is presented in blobovnicza.
|
// existsSmall checks if object is presented in blobovnicza.
|
||||||
func (b *BlobStor) existsSmall(addr oid.Address) (bool, error) {
|
func (b *BlobStor) existsSmall(prm common.ExistsPrm) (common.ExistsRes, error) {
|
||||||
return b.blobovniczas.Exists(addr)
|
return b.blobovniczas.Exists(prm)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
objectCore "github.com/nspcc-dev/neofs-node/pkg/core/object"
|
objectCore "github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
||||||
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
cidtest "github.com/nspcc-dev/neofs-sdk-go/container/id/test"
|
||||||
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
|
||||||
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
oidtest "github.com/nspcc-dev/neofs-sdk-go/object/id/test"
|
||||||
|
@ -37,19 +38,19 @@ func TestExists(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var prm ExistsPrm
|
var prm common.ExistsPrm
|
||||||
for i := range objects {
|
for i := range objects {
|
||||||
prm.SetAddress(objectCore.AddressOf(objects[i]))
|
prm.Address = objectCore.AddressOf(objects[i])
|
||||||
|
|
||||||
res, err := b.Exists(prm)
|
res, err := b.Exists(prm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, res.Exists())
|
require.True(t, res.Exists)
|
||||||
}
|
}
|
||||||
|
|
||||||
prm.SetAddress(oidtest.Address())
|
prm.Address = oidtest.Address()
|
||||||
res, err := b.Exists(prm)
|
res, err := b.Exists(prm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.False(t, res.Exists())
|
require.False(t, res.Exists)
|
||||||
|
|
||||||
t.Run("corrupt direcrory", func(t *testing.T) {
|
t.Run("corrupt direcrory", func(t *testing.T) {
|
||||||
var bigDir string
|
var bigDir string
|
||||||
|
@ -67,13 +68,13 @@ func TestExists(t *testing.T) {
|
||||||
t.Cleanup(func() { require.NoError(t, os.Chmod(dir, b.fsTree.Permissions)) })
|
t.Cleanup(func() { require.NoError(t, os.Chmod(dir, b.fsTree.Permissions)) })
|
||||||
|
|
||||||
// Object exists, first error is logged.
|
// Object exists, first error is logged.
|
||||||
prm.SetAddress(objectCore.AddressOf(objects[0]))
|
prm.Address = objectCore.AddressOf(objects[0])
|
||||||
res, err := b.Exists(prm)
|
res, err := b.Exists(prm)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.True(t, res.Exists())
|
require.True(t, res.Exists)
|
||||||
|
|
||||||
// Object doesn't exist, first error is returned.
|
// Object doesn't exist, first error is returned.
|
||||||
prm.SetAddress(objectCore.AddressOf(objects[1]))
|
prm.Address = objectCore.AddressOf(objects[1])
|
||||||
_, err = b.Exists(prm)
|
_, err = b.Exists(prm)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package shard
|
package shard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
oid "github.com/nspcc-dev/neofs-sdk-go/object/id"
|
||||||
)
|
)
|
||||||
|
@ -38,12 +38,12 @@ func (s *Shard) Exists(prm ExistsPrm) (ExistsRes, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if s.GetMode().NoMetabase() {
|
if s.GetMode().NoMetabase() {
|
||||||
var p blobstor.ExistsPrm
|
var p common.ExistsPrm
|
||||||
p.SetAddress(prm.addr)
|
p.Address = prm.addr
|
||||||
|
|
||||||
var res blobstor.ExistsRes
|
var res common.ExistsRes
|
||||||
res, err = s.blobStor.Exists(p)
|
res, err = s.blobStor.Exists(p)
|
||||||
exists = res.Exists()
|
exists = res.Exists
|
||||||
} else {
|
} else {
|
||||||
var existsPrm meta.ExistsPrm
|
var existsPrm meta.ExistsPrm
|
||||||
existsPrm.SetAddress(prm.addr)
|
existsPrm.SetAddress(prm.addr)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/common"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/blobstor/fstree"
|
||||||
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
meta "github.com/nspcc-dev/neofs-node/pkg/local_object_storage/metabase"
|
||||||
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
apistatus "github.com/nspcc-dev/neofs-sdk-go/client/status"
|
||||||
|
@ -75,9 +75,6 @@ func (c *cache) isFlushed(addr oid.Address) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
var prm blobstor.ExistsPrm
|
res, err := c.blobstor.Exists(common.ExistsPrm{Address: addr})
|
||||||
prm.SetAddress(addr)
|
return err == nil && res.Exists
|
||||||
|
|
||||||
res, err := c.blobstor.Exists(prm)
|
|
||||||
return err == nil && res.Exists()
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue