mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(s3): make the replaced version noncurrent on a write to a suspended bucket (#7143)
A write in a versioning-suspended bucket makes the version or delete marker it replaces noncurrent, and deleting versionId=null makes the newest of them current again, as on S3.
This commit is contained in:
1 parent
45b85405f7
commit
04558d9c1a
4 files changed
+79
-18
No files matched your search
+4
-1
@@ -105,7 +105,10 @@ noncurrent version. Deleting newer versions can make that null version current a
|
||||
`DeleteObject` without a version id in a versioning-suspended bucket makes a `null` delete marker
|
||||
the current version, as on S3. It replaces the null version or an earlier `null` delete marker, and
|
||||
the other versions stay as noncurrent versions. Deleting `versionId=null` removes that marker and
|
||||
makes the newest remaining version current again.
|
||||
makes the newest remaining version current again. A write in such a bucket, by PutObject, CopyObject
|
||||
or CompleteMultipartUpload, makes its `null` version current in the same way. The other versions and
|
||||
delete markers stay as noncurrent versions, and deleting `versionId=null` makes the newest of them
|
||||
current again.
|
||||
|
||||
Object Lock works only with versioning enabled. `PutBucketVersioning` with `Suspended` on a bucket
|
||||
with Object Lock answers `409 InvalidBucketState`, "An Object Lock configuration is present on this
|
||||
|
||||
@@ -1089,6 +1089,11 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
// In a suspended bucket the version or delete marker this write replaces stays as noncurrent.
|
||||
if (prev != null && prev.getVersionId() != null) {
|
||||
prev.setLatest(false);
|
||||
putObjectForAccount(bucketOwnerAccount, versionedKey(bucketName, key, prev.getVersionId()), prev);
|
||||
}
|
||||
// Retain archived null history and annotations until publication succeeds.
|
||||
// Annotation readers share this bucket monitor, so they cannot observe the
|
||||
// replacement with the old annotations while cleanup is pending.
|
||||
@@ -2476,29 +2481,14 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
.filter(existing -> isNamedVersion(existing, versionId))
|
||||
.orElse(null);
|
||||
if (toDelete == null && "null".equals(versionId)) {
|
||||
// A current null delete marker exists only at the plain latest key.
|
||||
// A current null version or null delete marker exists only at the plain latest key.
|
||||
toDelete = objectStore.get(objectKey(bucketName, key))
|
||||
.filter(candidate -> key.equals(candidate.getKey()))
|
||||
.filter(candidate -> candidate.isDeleteMarker() && candidate.getVersionId() == null)
|
||||
.orElse(null);
|
||||
}
|
||||
if (toDelete == null && "null".equals(versionId)) {
|
||||
// Before the null version is archived it exists only at the plain latest key.
|
||||
S3Object existing = objectStore.get(objectKey(bucketName, key))
|
||||
.filter(candidate -> key.equals(candidate.getKey()))
|
||||
.filter(candidate -> !candidate.isDeleteMarker())
|
||||
.filter(candidate -> candidate.getVersionId() == null)
|
||||
.orElse(null);
|
||||
if (existing == null) {
|
||||
if (toDelete == null) {
|
||||
return null;
|
||||
}
|
||||
checkLockProtection(existing, bypassGovernance);
|
||||
objectStore.delete(objectKey(bucketName, key));
|
||||
deleteFile(bucketName, key);
|
||||
deleteAllAnnotationsFor(annotationParentKey(bucketName, key, null));
|
||||
LOG.debugv("Permanently deleted null version: {0}/{1}", bucketName, key);
|
||||
fireNotifications(bucketName, key, removalEvent + ":Delete", existing);
|
||||
return existing;
|
||||
}
|
||||
if (toDelete != null && !toDelete.isDeleteMarker()) {
|
||||
checkLockProtection(toDelete, bypassGovernance);
|
||||
|
||||
@@ -832,4 +832,47 @@ class S3VersioningIntegrationTest {
|
||||
.body(equalTo("older"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(30)
|
||||
void aSuspendedWriteMakesTheVersionItReplacesNoncurrent() {
|
||||
String bucket = "suspended-null-write";
|
||||
given().when().put("/" + bucket).then().statusCode(200);
|
||||
given().body("<VersioningConfiguration><Status>Enabled</Status></VersioningConfiguration>")
|
||||
.when().put("/" + bucket + "?versioning").then().statusCode(200);
|
||||
List<String> keys = List.of("put", "copy", "upload");
|
||||
List<String> older = keys.stream()
|
||||
.map(key -> given().body("older").when().put("/" + bucket + "/" + key)
|
||||
.then().statusCode(200).extract().header("x-amz-version-id"))
|
||||
.toList();
|
||||
given().body("<VersioningConfiguration><Status>Suspended</Status></VersioningConfiguration>")
|
||||
.when().put("/" + bucket + "?versioning").then().statusCode(200);
|
||||
|
||||
given().body("null").when().put("/" + bucket + "/put").then().statusCode(200);
|
||||
given().header("x-amz-copy-source", "/" + bucket + "/put")
|
||||
.when().put("/" + bucket + "/copy").then().statusCode(200);
|
||||
String uploadId = given().when().post("/" + bucket + "/upload?uploads").then().statusCode(200)
|
||||
.extract().xmlPath().getString("InitiateMultipartUploadResult.UploadId");
|
||||
String partETag = given().body("null").when().put("/" + bucket + "/upload?uploadId=" + uploadId
|
||||
+ "&partNumber=1").then().statusCode(200).extract().header("ETag");
|
||||
given().contentType("application/xml")
|
||||
.body("""
|
||||
<CompleteMultipartUpload>
|
||||
<Part><PartNumber>1</PartNumber><ETag>%s</ETag></Part>
|
||||
</CompleteMultipartUpload>""".formatted(partETag))
|
||||
.when().post("/" + bucket + "/upload?uploadId=" + uploadId).then().statusCode(200);
|
||||
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
given().queryParam("versions", "").queryParam("prefix", keys.get(i)).when().get("/" + bucket)
|
||||
.then().statusCode(200)
|
||||
.body("ListVersionsResult.Version.VersionId", contains("null", older.get(i)))
|
||||
.body("ListVersionsResult.Version.IsLatest", contains("true", "false"));
|
||||
}
|
||||
|
||||
given().queryParam("versionId", "null").when().delete("/" + bucket + "/put").then().statusCode(204)
|
||||
.header("x-amz-version-id", "null");
|
||||
given().when().get("/" + bucket + "/put").then().statusCode(200)
|
||||
.header("x-amz-version-id", older.get(0))
|
||||
.body(equalTo("older"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -154,6 +154,31 @@ class S3VersioningServiceTest {
|
||||
assertEquals(List.of(current.getVersionId() + " latest"), versionLines("put"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aSuspendedPutMakesTheVersionOrDeleteMarkerItReplacesNoncurrent() {
|
||||
s3Service.putBucketVersioning("versioned-bucket", "Enabled");
|
||||
S3Object first = s3Service.putObject("versioned-bucket", "put",
|
||||
"v1".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
S3Object second = s3Service.putObject("versioned-bucket", "put",
|
||||
"v2".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
S3Object hidden = s3Service.putObject("versioned-bucket", "marker",
|
||||
"v1".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
S3Object marker = s3Service.deleteObject("versioned-bucket", "marker");
|
||||
s3Service.putBucketVersioning("versioned-bucket", "Suspended");
|
||||
s3Service.putObject("versioned-bucket", "put", "null".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
s3Service.putObject("versioned-bucket", "marker", "null".getBytes(StandardCharsets.UTF_8), "text/plain", null);
|
||||
|
||||
assertEquals(List.of("null latest", second.getVersionId(), first.getVersionId()), versionLines("put"));
|
||||
assertEquals(List.of("null latest", marker.getVersionId() + " marker", hidden.getVersionId()),
|
||||
versionLines("marker"));
|
||||
|
||||
s3Service.deleteObject("versioned-bucket", "put", "null");
|
||||
s3Service.deleteObject("versioned-bucket", "marker", "null");
|
||||
assertEquals(List.of(second.getVersionId() + " latest", first.getVersionId()), versionLines("put"));
|
||||
assertEquals(List.of(marker.getVersionId() + " marker latest", hidden.getVersionId()),
|
||||
versionLines("marker"));
|
||||
}
|
||||
|
||||
private List<String> versionLines(String key) {
|
||||
return s3Service.listObjectVersions("versioned-bucket", key, 100, null).versions().stream()
|
||||
.map(version -> (version.getVersionId() != null ? version.getVersionId() : "null")
|
||||
|
||||
Reference in new issue
Block a user