Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read delta lake table history when initial transaction logs are deleted #18845

Merged
merged 1 commit into from
Sep 14, 2023

Conversation

krvikash
Copy link
Contributor

@krvikash krvikash commented Aug 29, 2023

Description

This PR handles the case when transaction logs are deleted because the retention time of the transaction log is over.

This issue will occur when initial transaction logs get deleted because of log retention interval is exceeded while writing a new checkpoint file.

Release notes

( ) This is not user-visible or is docs only, and no release notes are required.
(X) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

# Deltalake
* Fix reading delta lake table history when initial transaction logs are removed. ({issue}`18845`)

@cla-bot cla-bot bot added the cla-signed label Aug 29, 2023
@krvikash krvikash self-assigned this Aug 29, 2023
@krvikash krvikash added the delta-lake Delta Lake connector label Aug 29, 2023
@krvikash krvikash force-pushed the krvikash/delta-history-table branch 2 times, most recently from 7f6e106 to 8f8bcb2 Compare September 4, 2023 06:42
@@ -94,6 +94,45 @@ public static TransactionLogTail loadNewTail(
return new TransactionLogTail(entriesBuilder.build(), version);
}

// Load a section of the Transaction Log JSON entries. Optionally from a given end version (inclusive) through an start version (inclusive)
public static TransactionLogTail loadNewTailBackward(
Copy link
Member

Choose a reason for hiding this comment

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

Any specific reason for reading backward, because we try to reverse them later in getPageSource

Copy link
Contributor Author

@krvikash krvikash Sep 4, 2023

Choose a reason for hiding this comment

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

Yes, the transaction log we intend to access through loadNewTailBackward will start from the final checkpoint file version and continue all the way back to version 0. This will remain true even if the log retention period is exceeded, leading to the removal of some of the initial transaction logs (0, 1, etc.). In this way, we can still retrieve the complete history of the table till the last checkpoint version.

@krvikash
Copy link
Contributor Author

krvikash commented Sep 8, 2023

Thanks @findinpath for the review. I have addressed comments.

if (lastCheckpointVersion.isPresent() && endVersionInclusive.isPresent()) {
middleVersion = Optional.of(Math.min(lastCheckpointVersion.get(), endVersionInclusive.get()));
}
commitInfoEntries.addAll(TransactionLogTail.loadNewTailBackward(fileSystem, tableLocation, startVersionExclusive, middleVersion, true).getFileEntries().stream()
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need to do this from the middle backwards and then from the middle forward separately? Rather than from endVersion backwards in one pass.

It's not obvious to me this way that you're not potentially going to have duplicates.

@krvikash
Copy link
Contributor Author

krvikash commented Sep 8, 2023

Thanks @alexjo2144 for the review. AC.

@krvikash
Copy link
Contributor Author

krvikash commented Sep 8, 2023

(resolved conflicts)

@krvikash
Copy link
Contributor Author

(resolved conflicts)

@krvikash
Copy link
Contributor Author

(fixed CI failure)

@krvikash
Copy link
Contributor Author

Thanks @alexjo2144 for the review. Addressed comments.

@findepi findepi merged commit 5548599 into trinodb:master Sep 14, 2023
23 checks passed
@github-actions github-actions bot added this to the 427 milestone Sep 14, 2023
@krvikash krvikash deleted the krvikash/delta-history-table branch September 14, 2023 08:16
@krvikash
Copy link
Contributor Author

krvikash commented Sep 14, 2023

ci / test (plugin/trino-delta-lake, cloud-tests) is failing in master. I am working on fixing it.

Failing for ADLS and GCS. S3 is passing.

@krvikash
Copy link
Contributor Author

minio.removeObject is not removing files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed delta-lake Delta Lake connector
Development

Successfully merging this pull request may close these issues.

5 participants