Repository navigation
fix(iceberg): S3 Direct tables without version-hint.text, and shallow table locations - #2379
Conversation
…accept shallow locations S3 storage now lists the files and directories under a prefix, so a Direct table whose writer never produced version-hint.text resolves from its metadata/ listing, as local and GCS tables already do. A bare bucket lists its top level, so a warehouse root may be the bucket itself. The Direct table identifier no longer needs three path segments: the last two segments (bucket included) give namespace and table, and a single segment falls back to the default namespace.
aaj3f
left a comment
There was a problem hiding this comment.
@bplatz nice finds from the real-bucket run. The S3 listing in the same (dirs, files) shape GCS already has is exactly where I'd have put it, and counting the bucket as a segment is the smallest fix for shallow locations. Two musts below, both small: the test job is red because two of my surface tests still expect s3://bucket/t to be refused (the invariant they pin still holds, only the example is stale), and the docs say an empty hint falls back when the code errors. One design note: for a hint-less S3 table, metadata/ gets listed on every query (2s TTL), and that listing grows with the table's history, since manifests live there too. A probe-forward refresh in the shared fallback helper would bound it, and would fix GCS's identical path along the way. Also, this is the fourth time a storage capability has landed one backend at a time behind an "unsupported" trait default (6fcf7fc64 S3 list_dir, 15ca56807 local list_files, 86308f44c GCS, and here S3 list_files plus the LazyStorage forward). A required list_children on the traits would turn the next one into a compile error, but not in this PR. This and #2378 merge cleanly in either order:
Full review below:
✅ Approving to unblock: please get the two stale surface tests and the empty-hint line in before merging.
Really nice work turning this around from a live bucket test. The S3 listing is right: it paginates with continuation tokens, skips placeholders, and handles the bare bucket the way GCS handles gs://bucket. The current-file choice was already one shared rule, so local, GCS and S3 now pick identically. Claude mutation-checked the core of it: with list_children dropping its files, s3_lists_the_child_files_and_directories_of_a_prefix goes red, and with the identifier back on the three-segment rule, direct_identifier_derives_from_a_shallow_location goes red. The two musts are a few lines each. First, test is red on the head, because two of my older surface tests assert the old refusal. Second, iceberg.md:431 promises a fallback for an empty hint that the code doesn't take. The rest is optional: a pagination test, the per-query listing cost, and the display-copy drift.
Adherence to repo commitments:
- Patterns/abstractions: ✔ S3 now matches GCS's
list_implshape, and the choice rule is shared.⚠️ table_identifier_displaystill duplicates the identifier derivation on the old rule (inline). - Performance (speed first, memory second):
⚠️ no regression for tables with a hint. Hint-less S3 tables, newly readable, cost a hint GET plusceil(objects/1000)LISTs per query once the 2s cache expires, and that grows with history (inline, with a probe-forward fix). - Deployment targets: ✔ host-neutral: no background work or process-lifetime state is added, and the listing runs inside the request. Evidence is CI's mocked S3 plus the body's manual real-bucket run.
- Testing: ✖ the
testjob is red on the head (two stale surface tests). The new S3 test runs in CI and fails when the listing drops files, but pagination is unpinned (inline). - Conventions: ✔ multi-line commit, docs updated. ✖
iceberg.md:431overclaims the empty-hint case.
Verified at branch HEAD 4d38227b4: Claude ran the fluree-db-iceberg lib suite (485 passed) and the registration_* surface tests (2 of 4 fail, as in CI) with --all-features on a clean box. Two mutation checks went red as they should. A two-page mocked listing resolves v10 with 1 GET + 2 LISTs. The empty-hint gap was reproduced. Both suggested fixes above were run on the head and pass. The merge with #2378 passes both suites.
Approving so you can merge once the two musts are in. The pagination test would be cheap insurance while you're there.
| // bucket that is the bucket. A lone segment (a bucket, or a | ||
| // top-level directory) has no parent to name one. | ||
| match segments.as_slice() { | ||
| [.., ns, table] => { |
There was a problem hiding this comment.
Blocking: two existing tests still assert that shallow locations are refused, so the test job is red on this head. graph_source::surface::tests::registration_runs_the_engines_own_validation_in_every_mode and registration_refuses_what_every_query_would (fluree-db-api/src/graph_source/surface/tests.rs:1039-1061) build Direct configs at s3://bucket/t and s3://bucket/dw and expect a "table identifier" error. This derivation now accepts both, so both unwrap_err() calls panic on Ok(()). CI run 43435423829 shows 15858 tests with 2 failed, and these are the two. Claude reproduced both failures on a box at 4d38227b4.
Those tests are mine (64b9a0b91, be5e4b61e). What they pin is that registration refuses exactly what a query's validation refuses, and that still holds after this PR; only the example went stale. One wrinkle: no s3:// location reaches the identifier refusal any more. Even a bare s3:// is refused earlier, as not an S3 URI (Claude tried it). So I think both tests should flip: assert that the shallow locations now register, and pin the engine's location rule with a location only the engine refuses. Claude ran this version on the head and all 4 registration_* tests pass:
// registration_runs_the_engines_own_validation_in_every_mode
let e = IcebergCreateConfig::new_direct("gs", "ftp://bucket/t")
.validate()
.unwrap_err();
assert!(e.to_string().contains("table_location must be"), "{e}");
IcebergCreateConfig::new_direct("gs", "s3://bucket/t")
.validate()
.unwrap();
// registration_refuses_what_every_query_would
let mapping = "@prefix rr: <http://www.w3.org/ns/r2rml#> .";
let e = crate::R2rmlCreateConfig::new_direct("gs", "ftp://bucket/dw", mapping)
.validate()
.unwrap_err();
assert!(e.to_string().contains("table_location must be"), "{e}");
crate::R2rmlCreateConfig::new_direct("gs", "s3://bucket/dw", mapping)
.validate()
.unwrap();The comments above the two tests also still say a Direct location must name ns/table, so those want the same update. I'm commenting here because fluree-db-api/src/graph_source/surface/tests.rs is not in this diff.
| - `"{table_location}/metadata/{filename}"` as the table’s current metadata | ||
| - `version-hint.text` may contain a bare filename (e.g., `00001-abc.metadata.json`), a full absolute path (`s3://...` / `gs://...`), or a bare integer version `N` — the Iceberg Hadoop file-based catalog convention — which resolves to `vN.metadata.json`. | ||
| - **Local tables don't need `version-hint.text`** (pyiceberg and most non-Hadoop writers never produce it): when the hint is absent, the `metadata/` directory is listed and the highest-versioned `*.metadata.json` is used. On S3, where listing is not performed, a missing or empty `version-hint.text` fails with an error mentioning `version-hint.text`. | ||
| - **`version-hint.text` is optional** (pyiceberg and most non-Hadoop writers never produce it): when the hint is absent or empty, the `metadata/` directory is listed and the highest-versioned `*.metadata.json` is used. On S3 this needs `s3:ListBucket` on the bucket; if the listing is denied or finds no metadata file, the error mentions `version-hint.text`. |
There was a problem hiding this comment.
Blocking: the docs say an empty hint falls back to the listing, and the code doesn't. This line now says "when the hint is absent or empty, the metadata/ directory is listed". Both clients still return version-hint.text is empty without listing (fluree-db-iceberg/src/catalog/direct.rs:88-92 and :193-197). Claude checked it against a mocked bucket with an empty hint and a valid v1.metadata.json, and got Err("Metadata error: version-hint.text is empty").
Either drop "or empty" here, or make an empty hint take the same fallback as a missing one. I'd lean toward the second, since an empty hint names nothing:
if hint.is_empty() {
return fallback_metadata_location(
self.storage
.list_files(&format!("{}/metadata", self.table_location)),
&self.table_location,
&hint_path,
&IcebergError::Metadata("version-hint.text is empty".to_string()),
)
.await;
}That goes in both clients (per the SYNC comment). Claude applied it to both on the box: the empty-hint case then resolves v1.metadata.json, and all 39 catalog::direct and io::storage tests still pass.
| /// what resolves a table with no `version-hint.text`. | ||
| #[tokio::test] | ||
| #[cfg(feature = "aws")] | ||
| async fn s3_lists_the_child_files_and_directories_of_a_prefix() { |
There was a problem hiding this comment.
Optional: nothing pins pagination, which is exactly the case where a stale version would get picked. Every mocked response here has IsTruncated=false. Claude cut list_children down to its first page and this test still passes. A two-page mock catches it: page 1 holds v1…v9 with a NextContinuationToken, and page 2 holds v10, which sorts below v9 lexically. At this head, SendDirectCatalogClient::load_table resolves v10 with one hint GET and two LISTs. With the first-page-only mutation, it picks v9. The test Claude used is about 40 lines on top of the helpers this module already has (wiremock .with_priority(1) on the continuation-token matcher). Minor, but if you agree it's right, I'd rather see it folded in now than lost in the backlog.
| /// helper serves both the Send and non-Send clients. A storage backend without | ||
| /// listing support (S3) surfaces the ORIGINAL version-hint error, so S3 | ||
| /// Direct-mode behavior is unchanged. | ||
| /// helper serves both the Send and non-Send clients. A listing that fails (a |
There was a problem hiding this comment.
Optional (perf): for a hint-less S3 table, this runs on every query, and its cost grows with the table's history. Each miss on the Direct metadata-location cache resolves again, and that cache's TTL is 2s (fluree-db-api/src/graph_source/cache.rs:50). Each resolution is one hint GET (a 404, or a 403 without s3:ListBucket) plus one LIST page per 1,000 objects under metadata/. Manifests and manifest lists live there too: a pyiceberg append writes three objects (our silver/people_window fixture has 16 after 5 appends). So roughly every 333 commits add another sequential LIST to every query. It's not a regression, since these tables couldn't be read before, and GCS has had the same shape since 86308f44c. But I don't think we want per-query S3 work that grows with a table's age on a path we're just opening.
Since this helper is shared by every backend, the cheap fix seems to live right here. Remember the last version the listing found for a location (beyond the 2s TTL), and on refresh, probe forward: list prefix metadata/{N+1:05}- for NNNNN-uuid names, or HEAD v{N+1}.metadata.json for Hadoop names. Advance while the probe finds one, and fall back to the full listing only when it can't decide. That's how Iceberg's own HadoopTableOperations.refresh advances. This is more of a suggestion than a must, but if you agree it's right, folding it in here keeps the S3 path from starting life with the cliff.
| /// `table_location` (e.g., `s3://bucket/warehouse/ns/table` → `ns.table`), | ||
| /// the bucket counting as one (`s3://bucket/lake` → `bucket.lake`). A | ||
| /// single-segment location (`s3://bucket`) takes the namespace `default`. | ||
| pub fn table_identifier(&self) -> Result<TableIdentifier> { |
There was a problem hiding this comment.
Optional: table_identifier_display keeps a second copy of this derivation, still on the old rule. IcebergCreateConfig::table_identifier_display (fluree-db-api/src/graph_source/config.rs:1323-1344) re-derives ns.table with segments.len() >= 3 and only strips s3:///s3a://. So for s3://bucket/lake, iceberg map will print Table: s3://bucket/lake while the engine uses bucket.lake. Minimally, the display could call the engine's derivation instead of keeping a copy:
CatalogMode::Direct { table_location } => self
.to_iceberg_gs_config()
.table_identifier()
.map(|t| t.to_canonical())
.unwrap_or_else(|_| table_location.clone()),I'm commenting here because fluree-db-api/src/graph_source/config.rs is not in this diff. It's small and non-blocking, but I'd rather see it in this PR than have the two copies drift again.
… location A Direct location one level under its bucket now derives a table identifier, so no scheme-valid location is left without one. The two registration tests that refused such a location now refuse an unsupported scheme, which only the stored config's validation checks, and assert the shallow location registers.
…ssing one does The docs said an empty hint falls back to the metadata/ listing; both Direct clients returned 'version-hint.text is empty' instead. An empty hint names no file, so it takes the same fallback. A mocked two-page S3 listing pins pagination: v10 arrives on the second page and sorts below v9, so a listing that stopped at the first page would pick a stale file.
table_identifier_display kept its own copy of the Direct identifier derivation, still on the three-segment rule and stripping only s3://, so s3://bucket/lake displayed as the location while a query used bucket.lake. It now asks the engine's derivation.
Brings #2296, #2309, #2313, #2315, #2316, #2317, #2367, #2368, #2369, #2373, #2374, #2378 and #2379. Ports onto next: - #2374 (bound-object probe reads POST): main's POST walk and per-type flush replace next's OPST walk. The lane keys (o_type, o_key), so next's triple-term handles are one more covered type (object_probe_covers takes TripleTermDict) rather than a flush per type; a term's matches are read whole, as a ref's are. The wildcard cursor still keys refs only. Pooled graphs decline through dedicated_branch(Post); o_i is 64-bit. Next's pair join keys its subject through the shared LaneKey. - #2373 (leaflet type constant under replay): replays_history and o_type_const_for beside next's may_hold_keys; the row-labelling lanes take main's const-unless-replaying form over next's always-read-column. - #2368: the cyclic join decodes for eager callers with next's list index sentinel; both reasoning tests kept (cyclic operator and pair lane). - #2317 (GRAPH streams): main's work queue and InnerStream with next's pooled-graph pruning before each enumerated graph. - #2315: list predicates are an ordered set in next's multi-ledger view; the annotation edge probe stays deleted (no bundle lane on next). - #2296 (rebase reads its new line): ported onto next's fenced resets, erasure checks and peer sync (follow_record keeps next's unchanged-head arm); a non-fast-forward rebase moves head and index in one fenced reset. - Main's new tests: async genesis_ledger, graph_source_store for mapping writes, leaf_rows for leaflets-per-leaf, storage lock off for two file instances. New pattern/function matches cover TermComponents and the triple-term functions; AnnotationTarget arms dropped.
Two limits on catalog-less (Direct) Iceberg sources on S3, both found while testing #2378 against a real bucket.
S3 tables needed
version-hint.textDirect mode reads
metadata/version-hint.textto find the current metadata file and, when the hint is absent, listsmetadata/and takes the highest-versioned*.metadata.json. That fallback worked for local and GCS tables but not S3: the S3 storage had no file listing, so a table written by pyiceberg (which never writes the hint) failed with aversion-hint.texterror.S3 storage now lists both the files and the child directories of a prefix from one delimited
ListObjectsV2walk. The fallback needss3:ListBucket; if the listing is denied or finds nothing, the original hint error is still what surfaces.Shallow locations could not be registered
The table identifier for a Direct source was derived from the last two path segments after the bucket, so
s3://bucket/lakefailed with "Cannot determine table identifier from config". That ruled out a warehouse root, or a single table, sitting one level under the bucket.The bucket now counts as a segment: the last two segments give namespace and table, and a single segment gets the
defaultnamespace. Locations three or more segments deep derive the same identifier as before. A bares3://bucketalso lists its top level now, so the bucket itself can be a warehouse root.Testing
v10arrives on the second page and sorts belowv9, so a listing that stopped at the first page would pick a stale file.version-hint.textresolves by listing, as a missing one does (it used to error, contrary to the docs).iceberg mapdisplays the identifier a query uses: its display kept a copy of the old three-segment rule.version-hint.text: warehouse root one level under the bucket, warehouse root at the bucket, and a single table at one and two levels deep all resolved and returned the expected row counts.GCS already had the listing and is unchanged.