forked from TrueCloudLab/frostfs-s3-gw
[#542] Clear list cache on object removal
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
parent
f1a0288e3a
commit
b380d4ab53
2 changed files with 32 additions and 0 deletions
|
@ -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")
|
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) {
|
func createBucketAndObject(t *testing.T, tc *handlerContext, bktName, objName string) (*data.BucketInfo, *data.ObjectInfo) {
|
||||||
createTestBucket(tc.Context(), t, tc, bktName)
|
createTestBucket(tc.Context(), t, tc, bktName)
|
||||||
bktInfo, err := tc.Layer().GetBucketInfo(tc.Context(), 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)
|
parseTestResponse(t, w, res)
|
||||||
return 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
|
||||||
|
}
|
||||||
|
|
|
@ -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)
|
obj.Error = n.treeService.RemoveVersion(ctx, bkt.CID, nodeVersion.ID)
|
||||||
|
n.listsCache.CleanCacheEntriesContainingObject(obj.Name, bkt.CID)
|
||||||
return obj
|
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 {
|
if obj.Error = n.treeService.AddVersion(ctx, bkt.CID, newVersion); obj.Error != nil {
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
||||||
n.namesCache.Delete(bkt.Name + "/" + obj.Name)
|
n.namesCache.Delete(bkt.Name + "/" + obj.Name)
|
||||||
|
n.listsCache.CleanCacheEntriesContainingObject(obj.Name, bkt.CID)
|
||||||
|
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue