[#74] service/tree: Add logger
Log error instead of failing when multiple unversioned nodes are found Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
ca8791a5fd
commit
ee8cce662b
4 changed files with 23 additions and 11 deletions
|
@ -121,7 +121,7 @@ func prepareHandlerContext(t *testing.T) *handlerContext {
|
||||||
func NewTreeServiceMock(t *testing.T) *tree.Tree {
|
func NewTreeServiceMock(t *testing.T) *tree.Tree {
|
||||||
memCli, err := tree.NewTreeServiceClientMemory()
|
memCli, err := tree.NewTreeServiceClientMemory()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
return tree.NewTree(memCli)
|
return tree.NewTree(memCli, zap.NewExample())
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTestBucket(hc *handlerContext, bktName string) *data.BucketInfo {
|
func createTestBucket(hc *handlerContext, bktName string) *data.BucketInfo {
|
||||||
|
|
|
@ -119,7 +119,7 @@ func (a *App) initLayer(ctx context.Context) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
a.log.Fatal("failed to create tree service", zap.Error(err))
|
a.log.Fatal("failed to create tree service", zap.Error(err))
|
||||||
}
|
}
|
||||||
treeService := tree.NewTree(treeGRPCClient)
|
treeService := tree.NewTree(treeGRPCClient, a.log)
|
||||||
a.log.Info("init tree service", zap.Strings("endpoints", treeGRPCClient.Endpoints()))
|
a.log.Info("init tree service", zap.Strings("endpoints", treeGRPCClient.Endpoints()))
|
||||||
|
|
||||||
// prepare random key for anonymous requests
|
// prepare random key for anonymous requests
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -12,11 +13,13 @@ import (
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer"
|
"git.frostfs.info/TrueCloudLab/frostfs-s3-gw/api/layer"
|
||||||
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id"
|
||||||
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/user"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Tree struct {
|
Tree struct {
|
||||||
service ServiceClient
|
service ServiceClient
|
||||||
|
log *zap.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServiceClient is a client to interact with tree service.
|
// ServiceClient is a client to interact with tree service.
|
||||||
|
@ -104,8 +107,11 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewTree creates instance of Tree using provided address and create grpc connection.
|
// NewTree creates instance of Tree using provided address and create grpc connection.
|
||||||
func NewTree(service ServiceClient) *Tree {
|
func NewTree(service ServiceClient, log *zap.Logger) *Tree {
|
||||||
return &Tree{service: service}
|
return &Tree{
|
||||||
|
service: service,
|
||||||
|
log: log,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type Meta interface {
|
type Meta interface {
|
||||||
|
@ -811,14 +817,19 @@ func (c *Tree) getUnversioned(ctx context.Context, bktInfo *data.BucketInfo, tre
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(nodes) > 1 {
|
if len(nodes) == 0 {
|
||||||
return nil, fmt.Errorf("found more than one unversioned node")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(nodes) != 1 {
|
|
||||||
return nil, layer.ErrNodeNotFound
|
return nil, layer.ErrNodeNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(nodes) > 1 {
|
||||||
|
c.log.Debug("found more than one unversioned node", zap.Stringer("cid", bktInfo.CID),
|
||||||
|
zap.String("treeID", treeID), zap.String("filepath", filepath))
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(nodes, func(i, j int) bool {
|
||||||
|
return nodes[i].Timestamp > nodes[j].Timestamp
|
||||||
|
})
|
||||||
|
|
||||||
return nodes[0], nil
|
return nodes[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
cidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/container/id/test"
|
||||||
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
oidtest "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id/test"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
"go.uber.org/zap/zaptest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLockConfigurationEncoding(t *testing.T) {
|
func TestLockConfigurationEncoding(t *testing.T) {
|
||||||
|
@ -102,7 +103,7 @@ func TestTreeServiceSettings(t *testing.T) {
|
||||||
|
|
||||||
memCli, err := NewTreeServiceClientMemory()
|
memCli, err := NewTreeServiceClientMemory()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
treeService := NewTree(memCli)
|
treeService := NewTree(memCli, zaptest.NewLogger(t))
|
||||||
|
|
||||||
bktInfo := &data.BucketInfo{
|
bktInfo := &data.BucketInfo{
|
||||||
CID: cidtest.ID(),
|
CID: cidtest.ID(),
|
||||||
|
@ -134,7 +135,7 @@ func TestTreeServiceAddVersion(t *testing.T) {
|
||||||
|
|
||||||
memCli, err := NewTreeServiceClientMemory()
|
memCli, err := NewTreeServiceClientMemory()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
treeService := NewTree(memCli)
|
treeService := NewTree(memCli, zaptest.NewLogger(t))
|
||||||
|
|
||||||
bktInfo := &data.BucketInfo{
|
bktInfo := &data.BucketInfo{
|
||||||
CID: cidtest.ID(),
|
CID: cidtest.ID(),
|
||||||
|
|
Loading…
Reference in a new issue