Conversation
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.
This was referenced Dec 2, 2026
MisterRaindrop
marked this pull request as draft
December 3, 2026 02:30
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2012. Part of #2008.
What does this PR do?
Adds the metadata engine that talks to
datalake_agentover gRPC(
src/meta/engine_agent) and makes it the default in place of the stubengine. This PR carries the table lifecycle calls:
CreateTable,LoadTable,DropTableandTableExists, after a health and versionhandshake. An agent's
ErrorDetailbecomes a PostgreSQL error with theagent's message and correlation id; a new
DL_ERR_CONFLICTis reported as aserialization failure (SQLSTATE 40001). A build without gRPC still succeeds,
and then every agent call reports that the extension was built without it.
Decisions worth a look:
agent_engine.cruns inPostgreSQL: settings, conversion of the engine's call context, wait events,
and the per-backend RPC counts
EXPLAIN ANALYZEshows.agent_rpc.cppdrives gRPC's completion queue with signals masked, checks for query
cancellation between polls, includes no server header, and lets neither a
C++ exception nor a
longjmpcross the boundary.NOT_SERVING, and a call the agent's readiness gate refused withUNAVAILABLE "dlagent is not ready", are tried again every 200 ms withinthe RPC's one deadline, checking for cancellation in between. No other
UNAVAILABLEis replayed, since that call may have run.datalake_fdw.meta_engine_for_testing = stub, a hidden setting thattakes effect at server start, registers it in place of the agent.
contrib/datalake_agent/protoand
src/meta/fragment.proto; nothing generated is committed. The Makefilealso gives the generated sources LLVM bitcode rules, so a build configured
--with-llvmworks.datalake_fdwwith gRPC on Rocky 9 and 10, checks theno-gRPC build on Rocky 8 (which has no gRPC packages), and runs the agent
tests against a live
datalake_agentstarted with its socket and logdirectory as arguments.
test/fake_agent/health.proto(Apache-2.0, reduced to one RPC). It isrecorded in
LICENSE, andNOTICEcarries the attribution line of gRPC'sown NOTICE.
Type of Change
Test Plan
meta_conformance: the enginecontract run against the stub and against the agent engine;
agent_plumbing, against test agents that each misbehave one way(handshake, version refusal, error mapping, deadlines, cancellation, an
agent that is down, one still starting, TCP with a bearer token);
agent_real_plumbing, the same plumbing against a real agent; andagent_without_grpc, the build without gRPC.make installcheckofcontrib/datalake_fdwwith gRPC: 15tests, 0 failures. Extension built with 0 warnings.
mvn -B verifyof the agent: 87 tests, 0 failures.make -C src/test installcheck-cbdb-parallel(no core change)Impact
User-facing changes: none yet; the tables that use the agent arrive in
#2473.
Dependencies: gRPC C++ and protobuf, optional. Without them
(
DATALAKE_GRPC=no, or no packages found) the extension builds and theagent engine reports that it is unavailable.
Checklist
contrib/datalake_fdw/README.md, "The metadata agent")Additional Context
Next in the stack: #2472, the agent's Iceberg operations.