Skip to content

Conversation

@bartash
Copy link
Member

@bartash bartash commented Nov 29, 2023

When a snapshot is expired as part of a transaction, the snapshot file(s) should be deleted when the transaction commits. A recent change (#6634) ensured that files are not deleted when they have also been committed as part of a transaction, but this breaks the simple case where no new files are committed. Fix this by not skipping deletion when the list of committed files is empty.

Closes #9182

TESTING:

Extended a unit test to ensure that snapshot files are deleted. Ran the test without the fix on a branch where #6634 was reverted to show that this is a regression.

@github-actions github-actions bot added the core label Nov 29, 2023
@bartash
Copy link
Member Author

bartash commented Nov 29, 2023

@amogh-jahagirdar can you please take a look when you have time as you implemented #6634

@amogh-jahagirdar
Copy link
Contributor

Thanks for the PR @bartash I'm taking a look.

Copy link
Contributor

@amogh-jahagirdar amogh-jahagirdar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix, this does seem like a legitimate bug. Could we add a test to TestRemoveSnapshots ? I think there's no harm with the test in TestSequenceNumberForV2Table but TestRemoveSnapshot would be a better place for tests around this. There's a deletedFiles that's visible for testing on the transaction and I think could be used for assertions on files we expect to be deleted.

.onFailure((file, exc) -> LOG.warn("Failed to delete uncommitted file: {}", file, exc))
.run(
path -> {
if (committedFiles == null || !committedFiles.contains(path)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, good catch. If there are no committed files (which would be expected for a transaction with just ExpireSnapshots) but there are files to cleanup (which would be expected for ExpireSnapshots again) then we should proceed with the file removal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized alternatively we could've just returned an empty set in committedFiles instead of null and then could've removed the (committedFiles == null) check (in addition to the current top level check). I'm not super opinionated on that though (it can be done in a follow on)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should actually change committedFiles to return ImmutableSet.of() if there are no new snapshot IDs. The logic is correct to warn if the other reason null is returned happens (a committed snapshot is missing). null signals that the output of the method is invalid, which we assumed was the case if there are no committed snapshots. But here we have a case where it's a valid case to have no committed snapshots and therefore no committed files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a PR #9221 for addressing this.

@bartash bartash force-pushed the asherman_issue_9182 branch from c0f8e00 to b196590 Compare November 30, 2023 23:40
@bartash
Copy link
Member Author

bartash commented Nov 30, 2023

@amogh-jahagirdar thanks for the helpful suggestions.
I pushed a new version.
Changes from version 1:

  • Used the term “manifest list file” instead of “snapshot file”.
  • Fixed the order of expected and actual parameters in my added assertions in TestSequenceNumberForV2Table.
  • Added a new test in TestRemoveSnapshots(). The existing mechanism for tracking deleted files in TestRemoveSnapshots does not work for deletes inside transactions as the function passed in deleteWith() is called before the files are actually deleted in BaseTransaction, which is where my fix is.

@jbonofre
Copy link
Member

jbonofre commented Dec 4, 2023

I'm reviewing this. Thanks for the contribution !

Copy link
Contributor

@amogh-jahagirdar amogh-jahagirdar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks good to me, just some naming nits. Thanks for the fix. cc @rdblue In case he has any comments.

When a snapshot is expired as part of a transaction, the manifest list
file(s) should be deleted when the transaction commits. A recent change
(apache#6634) ensured that these files are not deleted when they have also
been committed as part of a transaction, but this breaks the simple
case where no new files are committed. Fix this by not skipping
deletion when the list of committed files is empty.

TESTING:

Extended a unit test to ensure that manifest list files are deleted.
Ran the test without the fix on a branch where apache#6634 was reverted
to show that this is a regression.
@bartash bartash force-pushed the asherman_issue_9182 branch from b196590 to 2ebd21a Compare December 4, 2023 18:33
@bartash
Copy link
Member Author

bartash commented Dec 4, 2023

Thanks @amogh-jahagirdar I pushed changes for the nits.

Copy link
Contributor

@Fokko Fokko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once this gets in, can you create a PR against the 1.4.x branch?

@amogh-jahagirdar
Copy link
Contributor

Thanks @bartash for the fix! Merging, @rdblue @jbonofre let me know if you have any concerns

@amogh-jahagirdar amogh-jahagirdar merged commit 99843f0 into apache:main Dec 4, 2023
bartash added a commit to bartash/iceberg that referenced this pull request Dec 5, 2023
…che#9183)

When a snapshot is expired as part of a transaction, the manifest list
file(s) should be deleted when the transaction commits. A recent change
(apache#6634) ensured that these files are not deleted when they have also
been committed as part of a transaction, but this breaks the simple
case where no new files are committed. Fix this by not skipping
deletion when the list of committed files is empty.

TESTING:

Extended a unit test to ensure that manifest list files are deleted.
Ran the test without the fix on a branch where apache#6634 was reverted
to show that this is a regression.
@bartash
Copy link
Member Author

bartash commented Dec 5, 2023

Once this gets in, can you create a PR against the 1.4.x branch?

Clean cherry-pick to 1.4.x is in #9223

amogh-jahagirdar added a commit that referenced this pull request Dec 19, 2023
…ed (#9223)

* Core: Expired Snapshot files in a transaction should be deleted. (#9183)

When a snapshot is expired as part of a transaction, the manifest list
file(s) should be deleted when the transaction commits. A recent change
(#6634) ensured that these files are not deleted when they have also
been committed as part of a transaction, but this breaks the simple
case where no new files are committed. Fix this by not skipping
deletion when the list of committed files is empty.

* Core: Fix logic for determining set of committed files in BaseTransaction when there are no new snapshots (#9221)

---------

Co-authored-by: Amogh Jahagirdar <[email protected]>
lisirrx pushed a commit to lisirrx/iceberg that referenced this pull request Jan 4, 2024
…che#9183)

When a snapshot is expired as part of a transaction, the manifest list
file(s) should be deleted when the transaction commits. A recent change
(apache#6634) ensured that these files are not deleted when they have also
been committed as part of a transaction, but this breaks the simple
case where no new files are committed. Fix this by not skipping
deletion when the list of committed files is empty.

TESTING:

Extended a unit test to ensure that manifest list files are deleted.
Ran the test without the fix on a branch where apache#6634 was reverted
to show that this is a regression.
devangjhabakh pushed a commit to cdouglas/iceberg that referenced this pull request Apr 22, 2024
…che#9183)

When a snapshot is expired as part of a transaction, the manifest list
file(s) should be deleted when the transaction commits. A recent change
(apache#6634) ensured that these files are not deleted when they have also
been committed as part of a transaction, but this breaks the simple
case where no new files are committed. Fix this by not skipping
deletion when the list of committed files is empty.

TESTING:

Extended a unit test to ensure that manifest list files are deleted.
Ran the test without the fix on a branch where apache#6634 was reverted
to show that this is a regression.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Core: Snapshot file are not correctly deleted when a snapshot is expired as part of a transaction

5 participants