diff --git a/api/handler/delete_test.go b/api/handler/delete_test.go index 45ae8f707..1e3ae2b63 100644 --- a/api/handler/delete_test.go +++ b/api/handler/delete_test.go @@ -134,6 +134,26 @@ func TestDeleteMarkers(t *testing.T) { require.Len(t, listOIDsFromMockedNeoFS(t, tc, bktName, objName), 0, "shouldn't be any object in neofs") } +func TestDeleteObjectFromListCache(t *testing.T) { + tc := prepareHandlerContext(t) + + bktName, objName := "bucket-for-removal", "object-to-delete" + bktInfo, objInfo := createVersionedBucketAndObject(t, tc, bktName, objName) + + versions := listObjectsV1(t, tc, bktName) + require.Len(t, versions.Contents, 1) + + checkFound(t, tc, bktName, objName, objInfo.Version()) + deleteObject(t, tc, bktName, objName, objInfo.Version()) + checkNotFound(t, tc, bktName, objName, objInfo.Version()) + + // check cache is clean after object removal + versions = listObjectsV1(t, tc, bktName) + require.Len(t, versions.Contents, 0) + + require.False(t, existInMockedNeoFS(tc, bktInfo, objInfo)) +} + func createBucketAndObject(t *testing.T, tc *handlerContext, bktName, objName string) (*data.BucketInfo, *data.ObjectInfo) { createTestBucket(tc.Context(), t, tc, bktName) bktInfo, err := tc.Layer().GetBucketInfo(tc.Context(), bktName) @@ -202,3 +222,12 @@ func listVersions(t *testing.T, tc *handlerContext, bktName string) *ListObjects parseTestResponse(t, w, res) return res } + +func listObjectsV1(t *testing.T, tc *handlerContext, bktName string) *ListObjectsV1Response { + w, r := prepareTestRequest(t, bktName, "", nil) + tc.Handler().ListObjectsV1Handler(w, r) + assertStatus(t, w, http.StatusOK) + res := &ListObjectsV1Response{} + parseTestResponse(t, w, res) + return res +} diff --git a/api/layer/layer.go b/api/layer/layer.go index 8c6dab499..bf73c8431 100644 --- a/api/layer/layer.go +++ b/api/layer/layer.go @@ -486,6 +486,7 @@ func (n *layer) deleteObject(ctx context.Context, bkt *data.BucketInfo, settings } obj.Error = n.treeService.RemoveVersion(ctx, bkt.CID, nodeVersion.ID) + n.listsCache.CleanCacheEntriesContainingObject(obj.Name, bkt.CID) return obj } @@ -528,7 +529,9 @@ func (n *layer) deleteObject(ctx context.Context, bkt *data.BucketInfo, settings if obj.Error = n.treeService.AddVersion(ctx, bkt.CID, newVersion); obj.Error != nil { return obj } + n.namesCache.Delete(bkt.Name + "/" + obj.Name) + n.listsCache.CleanCacheEntriesContainingObject(obj.Name, bkt.CID) return obj }