Skip to content

Fix S3 listObjects dropping objects on an empty page with a continuation token - #118615

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix-s3-list-objects-empty-page
Sep 8, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix-s3-list-objects-empty-page

Conversation

@CheSema

@CheSema CheSema commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

Related: #109761
Related: #109751

S3ObjectStorage::listObjects stopped paginating as soon as a response carried no keys, ignoring IsTruncated. A listing may legitimately return an empty page while more keys remain, and every object after that page was then silently lost.

The most exposed caller is IObjectStorage::existsOrHasAnyChild, which lists with max-keys=1, so one such response makes it report that a path does not exist. That is how MetadataStorageFromPlainRewritableObjectStorage::load decides whether the disk holds anything, so the disk comes up with no directories at all and a MergeTree table on it loses every part. The same listing also backs directory lookups on plain disks and data lake metadata discovery for Iceberg, Delta Lake, Hudi and Paimon, where dropping the tail can mean reading an older snapshot.

IObjectStorageIteratorAsync::nextBatch had the same defect and was fixed in #109761. That fix does not cover this path: on a plain_rewritable disk the existsOrHasAnyChild probes run before the iterator is used and can short-circuit the whole load.

Added tests/integration/test_s3_list_objects_empty_page, which proxies MinIO and answers the first listing of each prefix with no keys plus IsTruncated=true and a continuation token.

test_empty_listing_page_does_not_hide_parts covers the immediate effect: without the fix the table reports 0 of 100 rows after a restart.

test_empty_listing_page_does_not_create_intersecting_parts carries it through to the lasting damage. With the parts hidden the block counter restarts from 1, so the next generation of parts reuses block numbers already on the disk. Each generation merges into a level 1 part with the same left edge, and once both are listed the table cannot be attached at all:

Code: 49. DB::Exception: Part all_1_2_1 intersects next part all_1_3_1.
It is a bug or a result of manual intervention:
Cannot attach table `default`.`test_intersecting`

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed object storage listing silently skipping objects when S3 returns an empty page together with a continuation token. This could make a plain_rewritable disk appear empty and hide table parts, and could make data lake tables read a stale snapshot.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.9.1.940 (included in 26.9 and later)
  • Backported to: 26.8.3.60, 26.7.7.48, 26.6.5.74, 26.3.33.19

…ion token

S3ObjectStorage::listObjects stopped paginating as soon as a response carried no
keys, ignoring IsTruncated. A listing may legitimately return an empty page while
more keys remain, in which case every object after that page was silently lost.

The most exposed caller is IObjectStorage::existsOrHasAnyChild, which lists with
max-keys=1, so a single such response makes it report that a path does not exist.
That is how MetadataStorageFromPlainRewritableObjectStorage::load decides whether
the disk holds anything: the disk then comes up with no directories at all and a
MergeTree table on it loses every part it has. The same listing also backs
directory lookups on plain disks and data lake metadata discovery for Iceberg,
Delta Lake, Hudi and Paimon.

IObjectStorageIteratorAsync::nextBatch had the same defect and was fixed
separately; this is the remaining copy.
@clickhouse-gh

clickhouse-gh Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [22698c7]

Summary: ❌

job_name test_name status info comment
Build profile diff ERROR

AI Review

Summary

This PR fixes the synchronous S3ObjectStorage::listObjects pagination loop so it continues on IsTruncated even when a page has no Contents, which closes the same empty-page gap that had already been fixed in the async iterator path. The new integration coverage exercises the startup path that still depended on the synchronous helper and carries the bug through to the later part-intersection failure mode; combined with the all-green CI report, that is enough evidence for the promised Bug Fix.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 22698c7.

Metric Baseline Current Δ
Lines 88.80% 88.80% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 81.20% 81.20% +0.00%

Changed lines: Changed C/C++ lines covered: 5/5 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Sep 7, 2026
@kssenii kssenii self-assigned this Sep 7, 2026
… part set

The existing test stops at the disk coming up empty. This one carries it through to
the damage that follows: with the parts hidden, the block counter restarts from 1,
so parts written afterwards reuse block numbers already present on the disk. Each
generation merges into a level 1 part with the same left edge, all_1_2_1 and
all_1_3_1, and MergeTreePartInfo::contains rejects that pair because a containing
part may only have an equal level when the block range is identical. Once both
generations are listed the table cannot be attached at all.

Without the fix the second startup fails with

  Part all_1_2_1 intersects next part all_1_3_1. It is a bug or a result of manual
  intervention: Cannot attach table `default`.`test_intersecting`

The merges are what make this an intersection rather than a name collision: two
generations of level 0 parts would simply reuse the same directory names.
@CheSema CheSema added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 7, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. label Sep 7, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 8, 2026
Merged via the queue into master with commit dd937c7 Sep 8, 2026
174 of 175 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-s3-list-objects-empty-page branch September 8, 2026 01:38
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 8, 2026
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 8, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 8, 2026
clickhouse-gh Bot pushed a commit that referenced this pull request Sep 8, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 8, 2026
Backport #118615 to 26.8: Fix S3 listObjects dropping objects on an empty page with a continuation token
CheSema added a commit that referenced this pull request Sep 8, 2026
Backport #118615 to 26.7: Fix S3 listObjects dropping objects on an empty page with a continuation token
CheSema added a commit that referenced this pull request Sep 8, 2026
Backport #118615 to 26.6: Fix S3 listObjects dropping objects on an empty page with a continuation token
CheSema added a commit that referenced this pull request Sep 8, 2026
Backport #118615 to 26.3: Fix S3 listObjects dropping objects on an empty page with a continuation token
CheSema added a commit that referenced this pull request Sep 9, 2026
Reuses the mock #118615 left behind, which injects a listing answering with no
keys, IsTruncated and a continuation token, so the case needs no new fixture.

3 passed in 48.65s.
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
…ts on an empty page with a continuation token
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
…ts on an empty page with a continuation token
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
…ts on an empty page with a continuation token
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-object-storage Object storage connectivity (S3/GCS/Azure) including credentials, retries, multipart, etc. pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants