[#100] s3: Add a flag for permanent versioned object deletion
All checks were successful
DCO action / DCO (pull_request) Successful in 1m14s
Tests and linters / Tests (pull_request) Successful in 2m24s
Tests and linters / Tests with -race (pull_request) Successful in 2m44s
Tests and linters / Lint (pull_request) Successful in 3m6s

Signed-off-by: Nikita Zinkevich <n.zinkevich@yadro.com>
This commit is contained in:
Nikita Zinkevich 2024-11-06 12:34:48 +03:00
parent c6f7d51393
commit 2c58cbdd43
Signed by: nzinkevich
GPG key ID: 748EA1D0B2E6420A
4 changed files with 47 additions and 4 deletions

View file

@ -106,8 +106,51 @@ func (c *Client) Multipart(bucket, key string, objPartSize, concurrency int, pay
return PutResponse{Success: true}
}
func (c *Client) Delete(bucket, key string) DeleteResponse {
func (c *Client) Delete(bucket, key string, allVersions bool) DeleteResponse {
start := time.Now()
if allVersions {
versions, err := c.cli.ListObjectVersions(c.vu.Context(), &s3.ListObjectVersionsInput{
Bucket: aws.String(bucket),
Prefix: aws.String(key),
})
if err != nil {
stats.Report(c.vu, objPutFails, 1)
return DeleteResponse{Success: false, Error: err.Error()}
}
var toDelete []types.ObjectIdentifier
for _, v := range versions.Versions {
if *v.Key == key {
toDelete = append(toDelete, types.ObjectIdentifier{
Key: v.Key,
VersionId: v.VersionId,
})
}
}
for _, marker := range versions.DeleteMarkers {
if *marker.Key == key {
toDelete = append(toDelete, types.ObjectIdentifier{
Key: marker.Key,
VersionId: marker.VersionId,
})
}
}
if len(toDelete) != 0 {
_, err := c.cli.DeleteObjects(c.vu.Context(), &s3.DeleteObjectsInput{
Bucket: aws.String(bucket),
Delete: &types.Delete{
Objects: toDelete,
Quiet: true,
},
})
if err != nil {
stats.Report(c.vu, objPutFails, 1)
return DeleteResponse{Success: false, Error: err.Error()}
}
return DeleteResponse{Success: true}
}
}
_, err := c.cli.DeleteObject(c.vu.Context(), &s3.DeleteObjectInput{
Bucket: aws.String(bucket),

View file

@ -215,7 +215,7 @@ export function obj_delete() {
return;
}
const resp = s3_client.delete(obj.s3_bucket, obj.s3_key);
const resp = s3_client.delete(obj.s3_bucket, obj.s3_key, false);
if (!resp.success) {
log.withFields({bucket : obj.s3_bucket, key : obj.s3_key, op : 'DELETE'})
.error(resp.error);

View file

@ -228,7 +228,7 @@ export function obj_delete() {
return;
}
const resp = s3_client.delete(obj.s3_bucket, obj.s3_key);
const resp = s3_client.delete(obj.s3_bucket, obj.s3_key, false);
if (!resp.success) {
log.withFields({bucket: obj.s3_bucket, key: obj.s3_key, op: 'DELETE'})
.error(resp.error);

View file

@ -222,7 +222,7 @@ export function delete_object(obj) {
return;
}
const resp = s3_client.delete(obj.s3_bucket, obj.s3_key);
const resp = s3_client.delete(obj.s3_bucket, obj.s3_key, false);
if (!resp.success) {
log.withFields({bucket : obj.s3_bucket, key : obj.s3_key, op : 'DELETE'})
.error(resp.error);