Skip to content

fix: return full commit log when a commit tail is shorter than the fetch page#5040

Open
anxkhn wants to merge 1 commit into
apache:mainfrom
anxkhn:fix/commitlog-null-padding-truncation
Open

fix: return full commit log when a commit tail is shorter than the fetch page#5040
anxkhn wants to merge 1 commit into
apache:mainfrom
anxkhn:fix/commitlog-null-padding-truncation

Conversation

@anxkhn

@anxkhn anxkhn commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Commits.commitLog allocated a fixed-size fetch array and populated only tail.length entries. When polaris.persistence.reference-previous-head-count was below the internal page size, null padding reached fetchMany, and the iterator interpreted the first null as end-of-history. This silently truncated the natural-order commit log and could affect maintenance retention decisions.

This change sizes the fetch array to min(REVERSE_COMMIT_FETCH_SIZE, tail.length), so no null padding reaches the iterator. It mirrors the bounded growing-list approach used by commitLogReversed.

A parameterized test in BaseTestCommitLogImpl covers previous-head counts 2, 3, and 5 across the NoSQL persistence backends and verifies that both commit-log directions return the complete 50-commit history.

No public interface or configuration changes.

Checklist

  • Don't disclose security issues! (contact security@apache.org)
  • Clearly explained why the changes are needed, or linked related issues
  • Added/updated tests with good coverage, or manually tested (and explained how)
  • Added comments for complex logic (test Javadoc documents the regression)
  • Updated CHANGELOG.md (if needed)
  • Updated documentation in site/content/in-dev/unreleased (not needed, no API or configuration change)

Copilot AI review requested due to automatic review settings July 11, 2026 12:34
@github-project-automation github-project-automation Bot moved this to PRs In Progress in Basic Kanban Board Jul 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a paging bug in the NoSQL Commits.commitLog (most-recent-first) iterator where null-padded fetch pages could cause an early stop when a commit’s tail is shorter than the internal fetch page size. This prevents silent truncation of commit history (and downstream maintenance retention decisions) when polaris.persistence.reference-previous-head-count is configured below the fetch page size.

Changes:

  • Size the fetchMany ID page array to min(REVERSE_COMMIT_FETCH_SIZE, tail.length) to avoid null padding reaching fetchMany/iteration.
  • Add a parameterized regression test covering multiple referencePreviousHeadCount values below the page size across all NoSQL backends.
  • Add required test-fixture dependency and document the fix in CHANGELOG.md.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
persistence/nosql/persistence/impl/src/main/java/org/apache/polaris/persistence/nosql/impl/commits/CommitsImpl.java Eliminates null padding in reverse-page fetches to prevent premature end-of-history in commitLog.
persistence/nosql/persistence/impl/src/testFixtures/java/org/apache/polaris/persistence/nosql/impl/commits/BaseTestCommitLogImpl.java Adds a cross-backend regression test verifying commitLog returns full history with short tails.
persistence/nosql/persistence/impl/build.gradle.kts Adds polaris-idgen-api to test fixtures to support constructing custom-config persistence instances in the new test.
CHANGELOG.md Notes the commit log truncation fix under Unreleased Fixes.

@dimas-b
dimas-b requested a review from snazy July 16, 2026 03:02
…tch page

Commits.commitLog paged through history by building a fixed-size ObjRef array of REVERSE_COMMIT_FETCH_SIZE and filling only tail.length entries. fetchMany returns null at the positions of the trailing null ids, and the iterator treats the first null as end-of-history, so a commit whose recent-ancestor tail is shorter than the fetch page size truncated the natural-order commit log at that point.

With the default reference-previous-head-count of 20 (equal to the fetch size) the trailing null always coincided with genuine end-of-history, so the bug was not observable. With a smaller reference-previous-head-count the log stopped early, and because maintenance walks this log to decide retained objects, still-referenced objects could be dropped.

Size the fetch array to min(REVERSE_COMMIT_FETCH_SIZE, tail.length) so no null padding reaches the iterator, mirroring the growing-list approach already used by commitLogReversed. Add a parameterized regression test that commits deeper than the tail with reference-previous-head-count below the fetch size and asserts the full log is returned.

Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>
@anxkhn
anxkhn force-pushed the fix/commitlog-null-padding-truncation branch from 9363f85 to b90b049 Compare July 16, 2026 08:23
@anxkhn

anxkhn commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Pushed a revision addressing the latest review/CI feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants