manuzhang commented on code in PR #19027:
URL: https://github.com/apache/iceberg/pull/19027#discussion_r4653388758
##########
core/src/test/java/org/apache/iceberg/TestRewriteManifests.java:
##########
@@ -726,6 +726,82 @@ public void testManifestReplacementConcurrentAppend()
throws IOException {
statuses(ManifestEntry.Status.ADDED, ManifestEntry.Status.ADDED));
}
+ @TestTemplate
+ public void testReplaceStagedManifestAfterTransactionRetry() throws
IOException {
+ assumeThat(formatVersion).isGreaterThanOrEqualTo(2);
+
+ Transaction txn = table.newTransaction();
+ txn.newFastAppend().appendFile(FILE_A).commit();
+
+ Snapshot stagedAppend = txn.table().currentSnapshot();
+ List<ManifestFile> stagedManifests = stagedAppend.allManifests(table.io());
+ assertThat(stagedManifests).hasSize(1);
+ ManifestFile stagedManifest = stagedManifests.get(0);
+
+ // copy the staged manifest's entries with the metadata they inherit in
this attempt
+ File replacementFile =
temp.resolve(manifestFormat().addExtension("replacement")).toFile();
+ ManifestWriter<DataFile> writer =
+ ManifestFiles.write(
+ formatVersion,
+ table.spec(),
+ table.io().newOutputFile(replacementFile.getCanonicalPath()),
+ null);
+ try (ManifestReader<DataFile> reader =
+ ManifestFiles.read(stagedManifest, table.io(), table.specs())) {
+ for (ManifestEntry<DataFile> entry : reader.entries()) {
+ writer.existing(
+ entry.file(),
+ entry.snapshotId(),
+ entry.dataSequenceNumber(),
+ entry.fileSequenceNumber());
+ }
+ } finally {
+ writer.close();
+ }
+
+ txn.rewriteManifests()
+ .deleteManifest(stagedManifest)
+ .addManifest(writer.toManifestFile())
+ .commit();
+
+ // a concurrent commit forces the transaction to retry, which reuses the
staged manifest
+ // but assigns it a new sequence number and first row ID
+ table.newFastAppend().appendFile(FILE_B).commit();
+ Snapshot concurrentAppend = table.currentSnapshot();
+
+ // committing the replacement would keep the sequence number and row IDs
of the first attempt
+ assertThatThrownBy(txn::commitTransaction)
+ .isInstanceOf(ValidationException.class)
+ .hasMessageStartingWith(
+ String.format(
+ "Deleted manifest %s changed in the latest snapshot",
stagedManifest.path()));
+
+
assertThat(table.currentSnapshot().snapshotId()).isEqualTo(concurrentAppend.snapshotId());
+ }
+
+ @TestTemplate
+ public void testReplaceCommittedManifestAfterTransactionRetry() throws
IOException {
Review Comment:
This should already be covered by existing tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]