Registry Mirror
Skip to content

Conversation

@MisterRaindrop

@MisterRaindrop MisterRaindrop commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Stack, part 3 of 7 (draft). Depends on #2471. This PR also carries the
commits of #2470 and #2471; its own change is the last commit,
"datalake_agent: serve Iceberg tables by metadata location". Parts after
it: #2473 → #2474 → #2475 → #2476.

Closes #2013. Part of #2008.

What does this PR do?

Fills in the agent's Iceberg operations for tables reached by metadata
location
: the path of one immutable Iceberg metadata.json, which names one
version of a table. The caller sends that location, the volume's storage
settings and credentials with every request, and the agent keeps no catalog
of its own. Which version is current is the caller's to record; #2473 keeps
it in PostgreSQL.

RPC What it does
CreateTable writes a table's first metadata file, exclusively, at a table location
LoadTable, TableExists, GetStatistics read one version
DropTable checks the table UUID, optionally purges its files
GetFragment streams the version's data files as fragments, with their delete files and the residual filter
PlanFileGroups bin-packs files per partition, for a later compaction
Append, Update stage a new version on a given one and return its metadata location, without committing

Requests without a location, and the catalog-level commits, still answer
UNIMPLEMENTED.

Decisions worth a look:

  • Writes stage, they do not commit. Append and Update write a new
    metadata file on top of the version named and return its location as
    staging_id. Nothing points at it until the caller moves its own pointer,
    so a transaction that rolls back leaves an unreferenced file, not a
    changed table.
  • Retries are safe by operation_id. A staged write's path is derived
    from the operation id, so a retried request finds its own earlier result;
    concurrent copies of one request wait for the first; the same id with a
    different payload is refused.
  • One create at a time per table location, in one agent. Concurrent
    creates at one location with different operation ids are serialized, so
    exactly one succeeds and the others get ALREADY_EXISTS. The cost: two
    agent processes on one volume are not serialized against each other.
  • GetFragment streams with back-pressure. Fragments come in batches;
    each batch carries a pool of delete files that its fragments refer to by
    index, so a delete file shared by many data files is sent once per batch.
  • Filters bind by field id through the full column path, so a filter on a
    nested field cannot bind to a top-level column of the same name.
  • 64-bit counts travel as decimal strings in GetStatistics, as the
    contract requires for integers that a double cannot hold exactly.
  • Storage: one leased S3FileIO per storage configuration, and a
    LocalFileIO without Hadoop. LocalFileIO publishes files atomically but
    does not fsync, so it survives a process crash, not a power loss; the
    extension does not put tables on file:// volumes (datalake_fdw: add Builtin catalog version tracking #2473), and this class
    serves the agent's own tests and hand-made requests.
  • Iceberg Java 1.12.0, which is why the agent needs Java 17.

Type of Change

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

Test Plan

  • Unit tests added/updated: mvn -B verify, 123 tests, 0 failures, 1
    skipped (PlanMemoryTest, which runs only when
    DATALAKE_TEST_PLAN_CALLS is set). They include the operations on a
    local directory, the whole gRPC chain in process, concurrent creates
    and replays, and an S3 end-to-end test against SeaweedFS that CI runs
    too.
  • Apache RAT: 80 files approved, 0 unknown.
  • Integration tests added/updated: agent_location in datalake_fdw
    runs the table lifecycle by location against a real agent.
  • Passed make installcheck of contrib/datalake_fdw: 16 tests, 0
    failures.

Impact

User-facing changes: none yet.

Dependencies: Iceberg 1.12.0 (iceberg-core, iceberg-aws, ...) and the
AWS SDK for Java 2.54.17, in the agent only.

Checklist

Additional Context

Draft until #2470 and #2471 are merged. Next: #2473, the Builtin catalog.

Add contrib/datalake_agent, the Java gRPC service that datalake_fdw talks
to over the contract in contrib/datalake_agent/proto. This establishes the
process, transport, error and version handling, configuration, and logging
scaffolding before Iceberg operations and catalog providers fill in RPC
bodies.

Startup runs in this order: Main builds the Guice graph; the server
registers every service and binds the endpoint with
grpc.health.v1.Health answering NOT_SERVING, then becomes ready: it
starts the parent-process watchdog (--parent.pid) and flips health to
SERVING. Until then a business call is answered UNAVAILABLE "dlagent is
not ready", which a client may retry since the call did not run.
Handlers run on a bounded pool. Any startup failure exits 1. Default
transport is a Unix domain socket with configured file mode, guarded by
a lock on <socket>.lock that the agent holds for its lifetime, so a
second agent on the same path refuses to start rather than take the
socket over; TCP requires TLS and a mode-0600 bearer token file
supporting live rotation.

Every failure returns an ErrorDetail with BusinessErrorCode, retryable
flag, and correlation id; unexpected exceptions return a generic INTERNAL
without leaking stack traces. Every response carries contract version
headers, and incompatible clients are refused with FAILED_PRECONDITION.
All IcebergCatalogService RPCs (and opt-in CatalogManagementService RPCs)
currently answer UNIMPLEMENTED naming the RPC.

Settings come from the packaged application.properties, overridden by the
environment and by --key=value arguments, with relaxed binding and
placeholders as Spring Boot defines them; they hold process settings
only. The agent logs to dlagent-YYYY-MM-DD.log under --logging.file.path
(default $COORDINATOR_DATA_DIRECTORY/log; with neither it refuses to
start), with java.util.logging bridged in. RequestOptionMapper maps
datalake_fdw server and user mapping options to Iceberg catalog/FileIO
properties while keeping credentials in StorageConfig.credentials. A Log4j
rewrite policy scrubs request credentials and bearer tokens across agent,
Netty, and gRPC logs.

Add unit, in-process, UDS, TCP/TLS, process-level (cold start, logging,
watchdog), and credential-scrubbing tests under mvn -B verify along with
the datalake-agent CI workflow.

Closes apache#2011.
Replace the default stub metadata engine with the gRPC-backed agent engine
(src/meta/engine_agent) and add DL_ERR_CONFLICT (reported as serialization
failure) to distinguish optimistic concurrency conflicts from I/O or
internal errors.

Split the client cleanly across a plain C boundary: agent_engine.c runs in
PostgreSQL (settings, MetaCtx conversion, wait events, per-backend RPC
accounting for EXPLAIN ANALYZE), while agent_rpc.cpp drives gRPC
completion-queue polls with signal masking and query cancellation checks
without including server headers or letting C++ exceptions/longjmps cross.

Carry the table lifecycle family (CreateTable, LoadTable, DropTable,
TableExists) with an initial health/version handshake, ErrorDetail-based
error mapping, credentials routed via StorageConfig.credentials, and
build-time stub generation from contrib/datalake_agent/proto and
fragment.proto, with LLVM bitcode rules for the generated sources.
Builds without gRPC still succeed and report clear errors on agent
calls. Add datalake_fdw.meta_engine_for_testing for stub-only regression
clusters.

An agent that is still starting is waited for: a handshake answered
NOT_SERVING, and a call the agent's readiness gate refused with
UNAVAILABLE "dlagent is not ready", are tried again every 200 ms within
the RPC's one deadline, with the cancel check between tries. No other
UNAVAILABLE is replayed, since such a call may have run.

Add meta_conformance, fake_agent, and real-agent plumbing tests, and update
CI to build datalake_fdw with gRPC on Rocky 9/10 (and verify the no-gRPC
fallback on Rocky 8) and run agent tests against a live datalake_agent,
started with its socket and log directory as arguments.

Closes apache#2012.
Implement the catalog-free Iceberg kernel in datalake_agent where every
operation targets an explicit, immutable metadata_location (or table
location for CreateTable) supplied by the caller alongside volume storage
options and credentials.

Support CreateTable (exclusive initial metadata file, one create at a
time per table location), LoadTable, TableExists, GetStatistics,
DropTable (UUID check and optional purge), GetFragment (back-pressured
streaming splits with pooled delete files and residual filters),
PlanFileGroups (per-partition bin-packing), and staged Append/Update
writes returning a new metadata file as staging_id. Filters on nested
fields bind by full column path, and 64-bit counts travel as decimal
strings. Add idempotent operation_id handling with deterministic staged
paths, claim coalescing, and payload-mismatch rejection. Requests
without a location and catalog-level commits stay UNIMPLEMENTED.

Wire per-configuration leased S3FileIO and Hadoop-free LocalFileIO on
iceberg-java 1.12.0, speaking the settled 1.0.0 contract (optional
snapshots/sequence numbers, Iceberg JSON schemas/specs, file format and
content enums, column metrics, and credentials restricted to
StorageConfig.credentials).

Add local kernel, in-process gRPC, S3 end-to-end (SeaweedFS in CI), and
datalake_fdw agent_location lifecycle regression tests.

Closes apache#2013.
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.

datalake_agent: Iceberg operations by metadata location

1 participant