Skip to content

docs: add native grpc-proxy architecture design note (M0 of #8184) - #8218

Open
dmsolr wants to merge 3 commits into
masterfrom
docs/grpc-proxy-architecture
Open

dmsolr wants to merge 3 commits into
masterfrom
docs/grpc-proxy-architecture

Conversation

@dmsolr

@dmsolr dmsolr commented Oct 28, 2026

Copy link
Copy Markdown
Member

What this PR does

Delivers milestone M0 (architecture/design) of #8184: a design note for the dedicated native gRPC proxy plugin, at docs/grpc-proxy-architecture.md (17 sections).

Documentation only. No implementation and no runtime change — no new module, no PluginEnum entry, no database row, no starter, no behavior change.

Related Issue

Refs: #8184

Refs rather than Fixes deliberately: #8184 is an umbrella feature issue with seven separately implementable milestones and this PR delivers only the first. Merging it must not close the umbrella. The milestone plan (M0 to M6) with dependencies and rough sizes is in section 15.2.

Related complementary work, intentionally not linked with Fixes since none is a sub-task of this change: #8150 (bridge aggregation budgets and end-to-end cancellation), #8171 (Kubernetes GRPCRoute/BackendTLSPolicy), #8207 (selector client leases and bounded retired channel generations), and apache/shenyu-website#1172 (documentation-site side of the grpc-http naming clarification; nothing here closes it).

What the note decides

  • Grounding in current code, not assertion (§2): six concrete breakpoints making the existing HTTP/JSON bridge unsuitable as a base for native forwarding — doExecute bound to ServerWebExchange, errors emitted as JSON bodies, MessageWriter.onNext aggregating into a list until onCompleted, Mono.fromFuture(result.thenApply(...)) so cancellation never reaches ClientCall.cancel, identity/routing travelling through gRPC Context ThreadLocals, and the JSON-envelope contract with the JSON-suffixed service name. §2.7 lists what is reusable (config models, sync channels, PluginDataHandler, the BootstrapServer pattern, namespace/discovery, load-balancer SPI).
  • Naming and compatibility boundary (§4): new identifier grpcProxy; the existing grpc identifier, enum order, registration RPC type, starter coordinates, selector/rule/metadata bindings and JSON-envelope wire contract stay unchanged; grpc-http is a display name only. No canonical rename, no implicit database migration.
  • Listener lifecycle (§6): dedicated grpc-java listener following the MqttPluginDataHandler + BootstrapServer ownership pattern, extended with drain. Configuration is split into restart-class (port, TLS/ALPN, executor sizing, transport limits) and snapshot-class (selectors, rules, method registry, upstreams, policies, limits); snapshot-class changes never touch the listener, so an unrelated selector edit cannot sever long-lived streams.
  • Per-call context with exactly-once terminal accounting (§7): no ThreadLocal propagation, and no CompletableFuture dependent-stage cancellation as a release mechanism.
  • Immutable snapshot with reload-safe admission accounting (§8): compile then atomically publish, bind at admission, permit counters owned by a lifecycle object that outlives snapshots, removal/disable events reaching cleanup even with a null payload.
  • Channel pooling coordinated with [Task][gRPC] Lease selector clients and bound retired channel generations #8207 (§9.2) and marker-based circuit-breaker classification (§9.3) so local rejects and upstream failures are never confused.
  • Streaming governance, trust boundary, status/trailer mapping, per-RPC-stream routing granularity (§10–§13).
  • Verification strategy and acceptance mapping (§14, §15.1): all ten acceptance criteria of [Feature][gRPC] Add a dedicated native grpc-proxy plugin with streaming and interceptor governance #8184 mapped to design sections and milestones, with mandatory negative and boundary cases enumerated.

Notes on accuracy

Every code reference was verified against master at a87a3613f. Three findings the issue text does not cover are recorded in the note:

  1. MqttBootstrapServer.shutdown() is immediate (closes the bound channel, shutdownGracefully() on both event loop groups). Correct for MQTT, insufficient for long-lived gRPC streams — hence the restart-class/snapshot-class split and drain deadline in §6.3.
  2. There are six SQL dialects, not four: db/upgrade carries -h2, -mysql, -ob, -og, -oracle, -pg, and the H2 fresh-install schema lives in shenyu-admin/src/main/resources/sql-script/h2/schema.sql, not under db/init (which has no ob/og tree). §5.1/§5.4 list the exact files; §17 records the open question about the ob/og fresh-install path.
  3. Per db/upgrade/native-sql-matrix.md, the native-sql-matrix gate runs five native database jobs, each executing both the upgrade flow from the pinned v2.7.1 schema and the fresh-install flow, and skipped applicable jobs fail the gate. §5.4 flags this as M4 budget.

§9.3 is explicit that at a87a3613f UpstreamCircuitBreaker has no local-reject classification, and that the marker-type approach comes from #8189, which is pending rather than merged. Nothing here assumes that PR has landed.

Type of change

  • Documentation

How was this tested

Documentation-only; no code path, configuration default or schema is affected, so no module build or test run applies. Verification performed instead:

  • All code references checked against master a87a3613f (paths, method names, enum orders, SQL dialect layout, CI gate description)
  • Section numbering contiguous (1–17); all 29 internal cross-references resolve to an existing heading
  • License header follows the existing docs/*.md convention, plus the Status: line used by docs/plugin-graph-orchestration.md
  • No Fixes linkage that could close [Feature][gRPC] Add a dedicated native grpc-proxy plugin with streaming and interceptor governance #8184 or any related issue prematurely

Checklist

  • Apache 2.0 license header present (.licenserc.yaml excludes **/*.md and **/docs/** from RAT; header follows repository convention)
  • No breaking changes to public API / config / DB schema
  • No new source files, so no checkstyle surface added

Deliver milestone M0 of #8184: a design note for the dedicated native
gRPC proxy plugin, with no implementation and no runtime change.

Grounds the design in current code rather than assertion: records the six
concrete breakpoints that make the existing HTTP/JSON bridge unsuitable as a
base (ServerWebExchange binding, JSON error bodies, response aggregation in
MessageWriter, cancellation not crossing the CompletableFuture bridge,
ThreadLocal gRPC Context propagation, JSON-envelope service renamed with a
JSON suffix), and lists what is reusable instead.

Covers naming and compatibility boundary (grpc-proxy new, grpc identifier and
wire contract unchanged, grpc-http as display name only), module layout and
dependency direction, all six SQL dialects plus the native-sql-matrix CI gate,
listener lifecycle that discriminates restart-class from snapshot-class
configuration so unrelated edits cannot sever long-lived streams, per-call
context with exactly-once terminal accounting, immutable snapshot publication
with reload-safe admission accounting, upstream channel pooling coordinated
with #8207, marker-based circuit-breaker classification per #8189, streaming
governance boundaries, trust boundary, status/trailer mapping, per-RPC-stream
routing granularity, verification strategy, acceptance-criteria mapping,
milestone plan M0-M6, risks and open questions.

@Aias00 Aias00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2af0190.

The native/HTTP-JSON compatibility boundary and the per-call forwarding/resource model are grounded in the existing code. One concrete listener-lifecycle sequence needs correction before this becomes the implementation plan: a same-port replacement cannot be started while the old listener still owns the bind. Verified with a real grpc-java 1.65.1 listener bind probe; this is not a claim that the future native proxy implementation or four-RPC-type E2E has been tested.

Checkstyle (where Java was built), separately executed Apache RAT and git diff --check pass. No full repository/E2E pass is claimed.

Comment thread docs/grpc-proxy-architecture.md Outdated

| Configuration class | Examples | On change |
| --- | --- | --- |
| **restart-class** | port, TLS/ALPN material, cleartext policy, executor/thread sizing, transport-level message size limits | Start a new listener, stop accepting on the old one, drain established calls to a deadline, then release old resources. Never a bare `shutdown()`. |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Release the old socket before starting a same-port replacement

This restart sequence starts the new listener before stopping acceptance on the old listener, but restart-class changes include TLS, executors and transport limits without changing the address/port. Two ordinary grpc-java listeners cannot bind that same socket concurrently. With pinned grpc-java 1.65.1, a loopback probe starting the second NettyServerBuilder on the first server port fails with BindException: Address already in use. Distinguish a new-port replacement from a same-port restart: release the old listening socket through orderly shutdown before binding the replacement, while retaining active calls and their executors/channel leases until drain completes. Document the bind-failure/rollback behavior and any bounded acceptance gap. Server.shutdown() is graceful for existing RPCs; it need not mean terminating their streams.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cd7faca. You are right — the previous sequence started the replacement before releasing the old socket, which cannot work for the common restart-class changes (TLS, executors, transport limits) that keep the same address/port.

Section 6.3 now:

  • Distinguishes the two cases. Same-port restart: orderly Server.shutdown() on the old server first (rejects new calls, releases the listening socket on return, preexisting calls continue), then build+start() the replacement on the freed port; the old server's executors and channel leases are retained until drain finishes via awaitTermination(deadline), escalating to shutdownNow() only on deadline expiry or immediate security revocation. New-port replacement: start the new listener first (no bind conflict, no acceptance gap), then shutdown+drain the old one.
  • Corrects the shutdown() conflation. The immediacy concern is the MQTT handler's own teardown (channel + shutdownGracefully() on both event loop groups), not grpc-java's Server.shutdown(), which at the pinned 1.65.1 is orderly and per its contract releases the listening socket so it "may be reused by another server". The old "never a bare shutdown()" line was wrong and is gone.
  • Documents the bounded acceptance gap (socket release + one bind; affects only new calls) and bind-failure/rollback: since a shut-down Server cannot be restarted (start() throws IllegalStateException), rollback builds a fresh Server from the retained old config while in-flight calls keep draining; if that also fails the listener stays down, is surfaced, and retried, with snapshot/permit/lease state (section 8.3) surviving.

Also propagated to the risk table, the shenyu-protocol-grpc-native test bullet, and a new open question (#10) on whether the same-port acceptance gap is operationally acceptable or zero-gap new-port restarts should be required.

Address review on #8218 (section 6.3). Two grpc-java listeners cannot bind
the same socket concurrently (verified BindException at pinned 1.65.1), so a
same-port restart must release the old socket via orderly Server.shutdown()
before binding the replacement, not start the new listener first.

- Distinguish same-port restart (shutdown releases socket, then rebind, drain
  retained executors/channel leases) from new-port replacement (start first,
  no bind conflict, no acceptance gap).
- Clarify that grpc-java Server.shutdown() is orderly (preexisting calls
  continue, socket released on return) and that the immediacy concern is the
  MQTT handler's own teardown, not Server.shutdown().
- Document the bounded acceptance gap and bind-failure/rollback: a shut-down
  Server cannot be restarted, so rollback builds a fresh Server; snapshot,
  permit accounting and leases survive the outage.
- Extend the risk table, module test bullet and open questions accordingly.
@dmsolr
dmsolr requested a review from Aias00 November 1, 2026 17:19
@dmsolr

dmsolr commented Nov 2, 2026

Copy link
Copy Markdown
Member Author

@Aias00 Thanks for the precise catch — you were right that the previous restart sequence could not work for the common case. Addressed in cd7faca (section 6.3), and re-requested your review.

The old text started the replacement listener before releasing the old socket. Since most restart-class changes (TLS/ALPN, cleartext policy, executor/thread sizing, transport-level message-size limits) keep the same address/port, and two grpc-java listeners cannot bind one socket concurrently (BindException: Address already in use, confirmed at the pinned 1.65.1), that order was wrong.

Section 6.3 now:

  • Splits same-port restart from new-port replacement. Same-port: orderly Server.shutdown() on the old server first — it rejects new calls and releases the listening socket on return while preexisting calls continue — then build+start() the replacement on the freed port. The old server's executors and channel leases are retained until drain finishes (awaitTermination(deadline)), escalating to shutdownNow() only on deadline expiry or immediate security revocation. New-port: start the replacement first (no bind conflict, no acceptance gap), then shutdown+drain the old one.
  • Corrects the shutdown() conflation. The immediacy concern belongs to MqttBootstrapServer.shutdown() (channel + shutdownGracefully() on both event loop groups), not grpc-java's Server.shutdown(), which is orderly and per its contract releases the listening socket so it "may be reused by another server". The misleading "never a bare shutdown()" line is removed.
  • Documents the bounded acceptance gap (socket release + one construction/bind; affects only new calls) and bind-failure/rollback: a shut-down Server cannot be restarted (start() throws IllegalStateException), so rollback builds a fresh Server from the retained old config while in-flight calls keep draining; if that also fails the listener stays down, is surfaced and retried, with snapshot/permit/lease state (section 8.3) surviving.

Also propagated to the risk table (section 16), the shenyu-protocol-grpc-native test bullet (section 14.2), and a new open question (#10) on whether the same-port acceptance gap is operationally acceptable or zero-gap new-port restarts should be required. Documentation-only; no code path or schema is touched.

@dmsolr

dmsolr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

@Aias00 Gentle ping for re-review when you have a moment. The single review item (same-port listener restart ordering) was corrected in cd7faca — section 6.3 now shuts the old server down before binding the replacement, with the two restart cases distinguished — and the branch has just been synced with master (merge commit 07c8096, CI green). Happy to adjust anything else you spot.

This branch has not been deployed

No deployments
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.

[Feature][gRPC] Add a dedicated native grpc-proxy plugin with streaming and interceptor governance

2 participants