Registry Mirror
Skip to content

Conversation

@MisterRaindrop

@MisterRaindrop MisterRaindrop commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Stack, part 2 of 7. Depends on #2470. A pull request from a fork can
only target main, so this one also carries #2470's commit; this PR's own
change is the last commit, "datalake_fdw: add the agent engine gRPC
client". Parts after it: #2472 → #2473 → #2474 → #2475 → #2476.

Closes #2012. Part of #2008.

What does this PR do?

Adds the metadata engine that talks to datalake_agent over gRPC
(src/meta/engine_agent) and makes it the default in place of the stub
engine. This PR carries the table lifecycle calls: CreateTable,
LoadTable, DropTable and TableExists, after a health and version
handshake. An agent's ErrorDetail becomes a PostgreSQL error with the
agent's message and correlation id; a new DL_ERR_CONFLICT is reported as a
serialization 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:

  • Two files, split at a plain C boundary. agent_engine.c runs in
    PostgreSQL: settings, conversion of the engine's call context, wait events,
    and the per-backend RPC counts EXPLAIN ANALYZE shows. agent_rpc.cpp
    drives 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 longjmp cross the boundary.
  • Only a call that never ran is retried. 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, checking for cancellation in between. No other
    UNAVAILABLE is replayed, since that call may have run.
  • The stub engine stays, for regression clusters only.
    datalake_fdw.meta_engine_for_testing = stub, a hidden setting that
    takes effect at server start, registers it in place of the agent.
  • Stubs are generated at build time from contrib/datalake_agent/proto
    and src/meta/fragment.proto; nothing generated is committed. The Makefile
    also gives the generated sources LLVM bitcode rules, so a build configured
    --with-llvm works.
  • CI builds datalake_fdw with gRPC on Rocky 9 and 10, checks the
    no-gRPC build on Rocky 8 (which has no gRPC packages), and runs the agent
    tests against a live datalake_agent started with its socket and log
    directory as arguments.
  • One third-party file. The test agent serves gRPC's health service,
    test/fake_agent/health.proto (Apache-2.0, reduced to one RPC). It is
    recorded in LICENSE, and NOTICE carries the attribution line of gRPC's
    own NOTICE.

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

  • Integration tests added/updated, in meta_conformance: the engine
    contract 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; and
    agent_without_grpc, the build without gRPC.
  • Passed make installcheck of contrib/datalake_fdw with gRPC: 15
    tests, 0 failures. Extension built with 0 warnings.
  • mvn -B verify of the agent: 87 tests, 0 failures.
  • Tested on Rocky Linux 9.8 (aarch64).
  • Passed 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 the
agent engine reports that it is unavailable.

Checklist

  • Followed contribution guide
  • Added/updated documentation (contrib/datalake_fdw/README.md, "The metadata agent")
  • Reviewed code for security implications
  • This PR contains AI-assisted code generation
  • Requested review from cloudberry committers

Additional Context

Next in the stack: #2472, the agent's Iceberg operations.

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.
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_fdw: the agent engine client (meta/engine_agent)

1 participant