Skip to content

refactor(ucore): use a single grpc channel with a name resolver instead of replacing channels - #3920

Merged
PanternBao merged 5 commits into
3.20.11.99/ltsfrom
fix/ucore-channel-resolver
Nov 16, 2026
Merged

PanternBao merged 5 commits into
3.20.11.99/ltsfrom
fix/ucore-channel-resolver

Conversation

@PanternBao

@PanternBao PanternBao commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Replacing the shared channel on every failed rpc made other threads, which had already read the old stub, fail with "UNAVAILABLE: Channel shutdownNow invoked" (seen in unlockKey right after a reload).

Follow the grpc-java examples instead (nameresolve, retrying, waitforready):

  • UcoreNameResolverProvider feeds the ucore ip list to one long-lived channel; ip list changes are pushed through the channel's SynchronizationContext
  • the default pick_first policy selects the node and reconnects with backoff, so the per-method "try every ip with a new channel" loops are replaced by one call() helper
  • the stub is derived per call, so the deadline is computed at call time
  • a service config enables retries (UNAVAILABLE, 3 attempts) only for the idempotent calls; LockOnSession, Alert/AlertResolve and the long polls rely on transparent retry only
  • wait-for-ready queues an rpc while the channel connects, bounded by its deadline
  • only connection level failures are reported as IOException, other statuses are rethrown unchanged

lock()'s renew thread handling is intentionally left as it was.

Not compiled and not tested: the build environment had no JDK.

Reason:
  BUG #. or Improve #.
Type:
  BUG/Improve
Influences:
   fix xx

…ad of replacing channels

Replacing the shared channel on every failed rpc made other threads, which had
already read the old stub, fail with "UNAVAILABLE: Channel shutdownNow invoked"
(seen in unlockKey right after a reload).

Follow the grpc-java examples instead (nameresolve, retrying, waitforready):
- UcoreNameResolverProvider feeds the ucore ip list to one long-lived channel;
  ip list changes are pushed through the channel's SynchronizationContext
- the default pick_first policy selects the node and reconnects with backoff, so
  the per-method "try every ip with a new channel" loops are replaced by one
  call() helper
- the stub is derived per call, so the deadline is computed at call time
- a service config enables retries (UNAVAILABLE, 3 attempts) only for the
  idempotent calls; LockOnSession, Alert/AlertResolve and the long polls rely on
  transparent retry only
- wait-for-ready queues an rpc while the channel connects, bounded by its deadline
- only connection level failures are reported as IOException, other statuses
  are rethrown unchanged

lock()'s renew thread handling is intentionally left as it was.

Not compiled and not tested: the build environment had no JDK.
@github-actions
github-actions Bot requested a review from wenyh1 November 16, 2026 08:16
@PanternBao
PanternBao removed the request for review from wenyh1 November 16, 2026 08:17
The build failed at the validate phase with 6 violations:
- SeparatorWrap: the '.' of the chained ManagedChannelBuilder calls has to
  stay at the end of the line
- OperatorWrap: the '+' joining the error message has to stay at the end of
  the line

No behaviour change.
UcoreNameResolverProviderTest (offline, 6 cases):
- the provider binds to the ucore scheme and can be registered the way
  UcoreSender.initChannel does it
- every ucore ip becomes its own EquivalentAddressGroup, with the authority
  staying ip:port as the channel used to send it
- a node list change reaches every started resolver, an empty list is reported
  as UNAVAILABLE, a shut-down resolver stops receiving updates

UcoreChannelIntegrationTest (real cluster on 5700, 5 cases):
- read-only rpcs over the channel built from the resolver: health check,
  leader lookup and usage all answer
- the channel reaches READY, and pick_first skips an unreachable address
- skipped automatically when no ucore node is reachable, so the suite stays
  green without the cluster

Verified against 10.186.63.94, 10.186.63.93 and 10.186.57.108: 11 tests pass.
@github-actions
github-actions Bot requested a review from wenyh1 November 16, 2026 09:22
maxAttempts 3 produces exactly two backoffs (0.2s then 0.4s), so the 2s
ceiling copied from the grpc example was never reached and only suggested a
cap the policy does not have. 0.5s states the same thing without implying
behaviour that does not happen.

No runtime change: neither ceiling is reached by this policy.
Two cases around a fake ucore node on 127.0.0.1 (accepts and hangs up at
once, which grpc sees as a failed transport):

- deadAddressIsDialledOnceThenTheNextNodeAnswers: with a dead address first
  and three live nodes behind it, the dead one is dialled once and the next
  address is started right away; the rpc still succeeds. Pins down that
  pick_first has no per-address retry and no delay between addresses
- retryingTheWholeListIsThrottledByBackoff: with the dead node as the only
  address, the rpc ends with DEADLINE_EXCEEDED after roughly three rounds,
  which is the exponential backoff (1s, multiplier 1.6, jitter 20%) and not
  an unbounded retry loop

Both are skipped when 127.0.0.1:5700 is taken. 13 tests pass against the real
cluster (10.186.63.94, 10.186.63.93, 10.186.57.108).
@PanternBao PanternBao changed the title refactor(ucore): use a single grpc channel with a name resolver inste… refactor(ucore): use a single grpc channel with a name resolver instead of replacing channels Nov 16, 2026
@PanternBao
PanternBao merged commit a72ffe8 into 3.20.11.99/lts Nov 16, 2026
4 checks passed
@PanternBao
PanternBao deleted the fix/ucore-channel-resolver branch November 16, 2026 10:43
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.

1 participant