From 9d19acadcdba28db591f55b0f9a34246b20cfa3d Mon Sep 17 00:00:00 2001 From: Denis Kirillov Date: Thu, 17 Mar 2022 17:03:06 +0300 Subject: [PATCH] [#195] Use exp epoch attribute instead of tick Signed-off-by: Denis Kirillov --- api/layer/layer.go | 18 +----------------- api/layer/locking_test.go | 11 ++++------- api/layer/system_object.go | 13 ++++++------- internal/neofstest/neofs_mock.go | 8 ++++---- 4 files changed, 15 insertions(+), 35 deletions(-) diff --git a/api/layer/layer.go b/api/layer/layer.go index 00347654..f38f324e 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -21,7 +21,6 @@ import ( cid "github.com/nspcc-dev/neofs-sdk-go/container/id" "github.com/nspcc-dev/neofs-sdk-go/eacl" "github.com/nspcc-dev/neofs-sdk-go/netmap" - "github.com/nspcc-dev/neofs-sdk-go/object/address" oid "github.com/nspcc-dev/neofs-sdk-go/object/id" "github.com/nspcc-dev/neofs-sdk-go/owner" "github.com/nspcc-dev/neofs-sdk-go/pool" @@ -290,9 +289,7 @@ func (n *layer) Initialize(ctx context.Context, c Notificator) error { return fmt.Errorf("already initialized") } - if err := c.Subscribe(ctx, LockTopic, MsgHandlerFunc(n.handleLockTick)); err != nil { - return fmt.Errorf("couldn't initialize layer: %w", err) - } + // todo add notification handlers (e.g. for lifecycles) c.Listen(ctx) @@ -304,19 +301,6 @@ func (n *layer) IsNotificationEnabled() bool { return n.ncontroller != nil } -func (n *layer) handleLockTick(ctx context.Context, msg *nats.Msg) error { - addr := address.NewAddress() - if err := addr.Parse(string(msg.Data)); err != nil { - return fmt.Errorf("invalid msg, address expected: %w", err) - } - - n.log.Debug("handling lock tick", zap.String("address", string(msg.Data))) - - // todo clear cache - // and make sure having right access - return n.objectDelete(ctx, addr.ContainerID(), addr.ObjectID()) -} - // IsAuthenticatedRequest check if access box exists in current request. func IsAuthenticatedRequest(ctx context.Context) bool { _, ok := ctx.Value(api.BoxData).(*accessbox.Box) diff --git a/api/layer/locking_test.go b/api/layer/locking_test.go index 57cdad22..961bfb60 100644 --- a/api/layer/locking_test.go +++ b/api/layer/locking_test.go @@ -33,15 +33,12 @@ func TestObjectLockAttributes(t *testing.T) { lockObj := tc.getSystemObject(obj.RetentionObject()) require.NotNil(t, lockObj) - tickTopic, tickEpoch := false, false + expEpoch := false for _, attr := range lockObj.Attributes() { - if attr.Key() == AttributeSysTickEpoch { - tickEpoch = true - } else if attr.Key() == AttributeSysTickTopic { - tickTopic = true + if attr.Key() == AttributeExpirationEpoch { + expEpoch = true } } - require.Truef(t, tickTopic, "system header __NEOFS__TICK_TOPIC presence") - require.Truef(t, tickEpoch, "system header __NEOFS__TICK_EPOCH presence") + require.Truef(t, expEpoch, "system header __NEOFS__EXPIRATION_EPOCH presence") } diff --git a/api/layer/system_object.go b/api/layer/system_object.go index 64b9e3f3..a57fb30d 100644 --- a/api/layer/system_object.go +++ b/api/layer/system_object.go @@ -18,11 +18,11 @@ import ( ) const ( - AttributeComplianceMode = ".s3-compliance-mode" - AttributeRetainUntil = ".s3-retain-until" - AttributeSysTickEpoch = "__NEOFS__TICK_EPOCH" - AttributeSysTickTopic = "__NEOFS__TICK_TOPIC" - LockTopic = "lock" + AttributeComplianceMode = ".s3-compliance-mode" + AttributeRetainUntil = ".s3-retain-until" + AttributeExpirationEpoch = "__NEOFS__EXPIRATION_EPOCH" + AttributeSysTickEpoch = "__NEOFS__TICK_EPOCH" + AttributeSysTickTopic = "__NEOFS__TICK_TOPIC" ) func (n *layer) PutSystemObject(ctx context.Context, p *PutSystemObjectParams) (*data.ObjectInfo, error) { @@ -296,8 +296,7 @@ func (n *layer) attributesFromLock(ctx context.Context, lock *data.ObjectLock) ( } attrs := [][2]string{ - {AttributeSysTickEpoch, strconv.FormatUint(exp, 10)}, - {AttributeSysTickTopic, LockTopic}, + {AttributeExpirationEpoch, strconv.FormatUint(exp, 10)}, {AttributeRetainUntil, lock.Until.Format(time.RFC3339)}, } diff --git a/internal/neofstest/neofs_mock.go b/internal/neofstest/neofs_mock.go index 7e0431bb..fb8a8e7d 100644 --- a/internal/neofstest/neofs_mock.go +++ b/internal/neofstest/neofs_mock.go @@ -187,20 +187,20 @@ func (t *TestNeoFS) ReadObject(_ context.Context, prm neofs.PrmObjectRead) (*neo func (t *TestNeoFS) CreateObject(_ context.Context, prm neofs.PrmObjectCreate) (*oid.ID, error) { id := test.ID() - attrs := make([]*object.Attribute, 0) + attrs := make([]object.Attribute, 0) if prm.Filename != "" { a := object.NewAttribute() a.SetKey(object.AttributeFileName) a.SetValue(prm.Filename) - attrs = append(attrs, a) + attrs = append(attrs, *a) } for i := range prm.Attributes { a := object.NewAttribute() a.SetKey(prm.Attributes[i][0]) a.SetValue(prm.Attributes[i][1]) - attrs = append(attrs, a) + attrs = append(attrs, *a) } obj := object.New() @@ -245,7 +245,7 @@ func (t *TestNeoFS) TimeToEpoch(ctx context.Context, futureTime time.Time) (uint return t.currentEpoch, t.currentEpoch + uint64(futureTime.Second()), nil } -func isMatched(attributes []*object.Attribute, filter object.SearchFilter) bool { +func isMatched(attributes []object.Attribute, filter object.SearchFilter) bool { for _, attr := range attributes { if attr.Key() == filter.Header() && attr.Value() == filter.Value() { return true