Skip to content

AO vacuum: CommandCounterIncrement before AppendOptimizedTruncateToEOF#1748

Open
yjhjstz wants to merge 1 commit into
apache:mainfrom
yjhjstz:fix/aocs-vacuum-eof-visibility
Open

AO vacuum: CommandCounterIncrement before AppendOptimizedTruncateToEOF#1748
yjhjstz wants to merge 1 commit into
apache:mainfrom
yjhjstz:fix/aocs-vacuum-eof-visibility

Conversation

@yjhjstz
Copy link
Copy Markdown
Member

@yjhjstz yjhjstz commented May 15, 2026

ClearAOCSFileSegInfo/ClearFileSegInfo (called from ao_vacuum_rel_recycle_dead_segments) updates pg_aoseg rows via simple_heap_update, which assigns the current CommandId to the new tuple. AppendOptimizedTruncateToEOF then opens a catalog snapshot via GetCatalogSnapshot, which also uses GetCurrentCommandId. Because both operations share the same CommandId, the just-zeroed rows are invisible to the snapshot (cid >= snapshot->curcid), while the old rows with their original non-zero EOF values remain visible. TruncateAOSegmentFile then sees a 0-byte physical file but a non-zero logical EOF and raises:

"file size smaller than logical eof"

Advancing the command counter before AppendOptimizedTruncateToEOF ensures the zeroed rows are visible to its catalog snapshot (their cid is now strictly less than the new curcid).

Fixes: #1746

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


ClearAOCSFileSegInfo/ClearFileSegInfo (called from
ao_vacuum_rel_recycle_dead_segments) updates pg_aoseg rows via
simple_heap_update, which assigns the current CommandId to the new tuple.
AppendOptimizedTruncateToEOF then opens a catalog snapshot via
GetCatalogSnapshot, which also uses GetCurrentCommandId.  Because both
operations share the same CommandId, the just-zeroed rows are invisible
to the snapshot (cid >= snapshot->curcid), while the old rows with their
original non-zero EOF values remain visible.  TruncateAOSegmentFile then
sees a 0-byte physical file but a non-zero logical EOF and raises:

  "file size smaller than logical eof"

Advancing the command counter before AppendOptimizedTruncateToEOF
ensures the zeroed rows are visible to its catalog snapshot (their cid
is now strictly less than the new curcid).

Fixes: apache#1746
Copy link
Copy Markdown
Contributor

@zhangwenchao-123 zhangwenchao-123 left a comment

Choose a reason for hiding this comment

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

LGTM

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.

[Bug] Vacuum on AOCS table issues the "file size smaller than logical eof" error

2 participants