From 7e0c5a55de8e14ee9bdf4484d186db87923383b8 Mon Sep 17 00:00:00 2001 From: Dmitrii Stepanov Date: Fri, 13 Oct 2023 13:50:25 +0300 Subject: [PATCH] [#734] writecache: Fix flush Now UpdateStorageID doesn't return error in case of logical error. If object is in graveyard or GC market, it is still required to update storage ID. Signed-off-by: Dmitrii Stepanov --- .../metabase/storage_id.go | 5 ++++- .../metabase/storage_id_test.go | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/pkg/local_object_storage/metabase/storage_id.go b/pkg/local_object_storage/metabase/storage_id.go index 6ba5a60cb..7e43e30eb 100644 --- a/pkg/local_object_storage/metabase/storage_id.go +++ b/pkg/local_object_storage/metabase/storage_id.go @@ -5,6 +5,7 @@ import ( "errors" "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/internal/metaerr" + "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/local_object_storage/util/logicerr" "git.frostfs.info/TrueCloudLab/frostfs-observability/tracing" oid "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/id" "github.com/nspcc-dev/neo-go/pkg/util/slice" @@ -107,7 +108,9 @@ func (db *DB) UpdateStorageID(prm UpdateStorageIDPrm) (res UpdateStorageIDRes, e err = db.boltDB.Batch(func(tx *bbolt.Tx) error { exists, err := db.exists(tx, prm.addr, currEpoch) - if err == nil && exists || errors.Is(err, ErrObjectIsExpired) { + if err == nil && exists { + err = updateStorageID(tx, prm.addr, prm.id) + } else if errors.As(err, new(logicerr.Logical)) { err = updateStorageID(tx, prm.addr, prm.id) } diff --git a/pkg/local_object_storage/metabase/storage_id_test.go b/pkg/local_object_storage/metabase/storage_id_test.go index b3652a680..7278eec57 100644 --- a/pkg/local_object_storage/metabase/storage_id_test.go +++ b/pkg/local_object_storage/metabase/storage_id_test.go @@ -18,6 +18,7 @@ func TestDB_StorageID(t *testing.T) { raw1 := testutil.GenerateObject() raw2 := testutil.GenerateObject() + deleted := testutil.GenerateObject() storageID := []byte{1, 2, 3, 4} @@ -34,6 +35,15 @@ func TestDB_StorageID(t *testing.T) { err = putBig(db, raw2) require.NoError(t, err) + // put object with storageID and delete it + err = metaPut(db, deleted, storageID) + require.NoError(t, err) + + cnrID, ok := deleted.ContainerID() + require.True(t, ok) + ts := testutil.GenerateObjectWithCID(cnrID) + require.NoError(t, metaInhume(db, object.AddressOf(deleted), object.AddressOf(ts))) + // check StorageID for object without storageID fetchedStorageID, err = metaStorageID(db, object.AddressOf(raw2)) require.NoError(t, err) @@ -44,12 +54,23 @@ func TestDB_StorageID(t *testing.T) { require.NoError(t, err) require.Equal(t, storageID, fetchedStorageID) + // check StorageID for deleted object with storageID + fetchedStorageID, err = metaStorageID(db, object.AddressOf(deleted)) + require.NoError(t, err) + require.Equal(t, storageID, fetchedStorageID) + t.Run("update", func(t *testing.T) { + storageID := []byte{1, 2, 3, 4, 5} require.NoError(t, metaUpdateStorageID(db, object.AddressOf(raw2), storageID)) + require.NoError(t, metaUpdateStorageID(db, object.AddressOf(deleted), storageID)) fetchedStorageID, err = metaStorageID(db, object.AddressOf(raw2)) require.NoError(t, err) require.Equal(t, storageID, fetchedStorageID) + + fetchedStorageID, err = metaStorageID(db, object.AddressOf(deleted)) + require.NoError(t, err) + require.Equal(t, storageID, fetchedStorageID) }) }