You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
External clients send every grain request to a gateway without location information, so the gateway addresses each request from its own cache or the grain directory. When the gateway changes or its cache lacks an entry (for example after grains move during silo retirement or rebalancing), the client cannot contribute what it has already learned about where a grain lives.
Solution
Client (Orleans.Core)
ClientGrainLocationCache caches grain locations in a lock-free ConcurrentLruCache. It learns from GrainAddressCacheUpdate entries in response cache invalidation headers (valid addresses are added, invalid addresses removed), and removes a location when that silo rejects a request without a cache update.
Updates are compare-and-set via TryRemove(key, predicate, arg) + TryAdd: an update replaces a cached location only when the cache holds the superseded location or none, so a delayed update does not overwrite a newer location.
Message.IsRelocatableRequest identifies application requests to grains (not system targets, clients, system messages, or local-only messages). For these, the client's TargetSilo is the cached location hint which the gateway routes with; for all other messages it continues to select the gateway. ClientMessageCenter and ClientOutboundConnection check TargetSilo != null before the relocatable check and preserve hints when recycling messages.
Gateway (Orleans.Runtime)
GatewayInboundConnection retains a relocatable request's target silo, and MessageCenter.RerouteMessage sends it directly to the hinted silo when that silo is active and the gateway's own cache holds no live address. The gateway's live placement cache takes precedence over hints.
Hints to silos which are not active are re-addressed through normal placement. Hints to dead silos also add a cache invalidation entry, so the response removes the hint from the client's cache.
Locations come only from cache updates which the runtime already produces, so steady-state responses carry no extra data and the client does no per-response cache writes.
Compatibility
Older gateways clear the target silo of client grain requests, so they ignore hints from newer clients. Newer gateways treat an older client's gateway address as a hint which does not refer to an active silo and address the request normally.
Performance
ConcurrentPing_OneSilo (net10.0, Release, interleaved base/new runs on a shared machine, 30 runs each): base median 117.7k req/s, new median 119.3k req/s (means 116.0k vs 116.3k). No regression within noise.
Tests
ClientGrainLocationCacheTests: learning, compare-and-set replacement, preservation of newer locations, invalidation, rejection handling, and IsRelocatableRequest classification.
ClientGrainLocationRoutingTests (2-silo cluster, single gateway): the gateway routes to the client's cached location, prefers its own cache over a stale hint without detouring through the hinted silo, and re-addresses a hint to a dead silo while clearing it from the client cache. Each test fails when the corresponding gateway behavior is removed.
The current-main baseline is commit fbe240c34e and uses the same reviewed coverage matrix.
Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities.
The comparison remains report-only while normal line and branch variance is calibrated.
The reason will be displayed to describe this comment to others. Learn more.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Invalidate SiloStatus.None hints as well. If a client resumes calls after its cached host's membership entry has been pruned, with no successor at that endpoint, MembershipTableSnapshot.GetSiloStatus scans every membership entry and returns None. Normal placement can then serve the request without a cache update, leaving the obsolete hint in the client's non-expiring cache. Subsequent calls repeat that full scan even when the gateway's placement cache is warm. Include None here so the response removes the hint, and add a regression test for a pruned-silo hint.
…ions
External clients cache grain locations learned from cache invalidation headers on responses and drop locations which reject requests. Relocatable grain requests carry the cached location as a target silo hint, which gateways use when the hinted silo is active and their own cache has no live address. Gateways inform clients of hints to dead silos.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Cross-layer routing and rolling-upgrade compatibility require final human validation beyond the available static review.
No open issues 🎉
Review effort: Balanced
This branch has not been deployed
No deployments
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
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.
Problem
External clients send every grain request to a gateway without location information, so the gateway addresses each request from its own cache or the grain directory. When the gateway changes or its cache lacks an entry (for example after grains move during silo retirement or rebalancing), the client cannot contribute what it has already learned about where a grain lives.
Solution
Client (
Orleans.Core)ClientGrainLocationCachecaches grain locations in a lock-freeConcurrentLruCache. It learns fromGrainAddressCacheUpdateentries in response cache invalidation headers (valid addresses are added, invalid addresses removed), and removes a location when that silo rejects a request without a cache update.TryRemove(key, predicate, arg)+TryAdd: an update replaces a cached location only when the cache holds the superseded location or none, so a delayed update does not overwrite a newer location.Message.IsRelocatableRequestidentifies application requests to grains (not system targets, clients, system messages, or local-only messages). For these, the client'sTargetSilois the cached location hint which the gateway routes with; for all other messages it continues to select the gateway.ClientMessageCenterandClientOutboundConnectioncheckTargetSilo != nullbefore the relocatable check and preserve hints when recycling messages.Gateway (
Orleans.Runtime)GatewayInboundConnectionretains a relocatable request's target silo, andMessageCenter.RerouteMessagesends it directly to the hinted silo when that silo is active and the gateway's own cache holds no live address. The gateway's live placement cache takes precedence over hints.Locations come only from cache updates which the runtime already produces, so steady-state responses carry no extra data and the client does no per-response cache writes.
Compatibility
Older gateways clear the target silo of client grain requests, so they ignore hints from newer clients. Newer gateways treat an older client's gateway address as a hint which does not refer to an active silo and address the request normally.
Performance
ConcurrentPing_OneSilo(net10.0, Release, interleaved base/new runs on a shared machine, 30 runs each): base median 117.7k req/s, new median 119.3k req/s (means 116.0k vs 116.3k). No regression within noise.Tests
ClientGrainLocationCacheTests: learning, compare-and-set replacement, preservation of newer locations, invalidation, rejection handling, andIsRelocatableRequestclassification.ClientGrainLocationRoutingTests(2-silo cluster, single gateway): the gateway routes to the client's cached location, prefers its own cache over a stale hint without detouring through the hinted silo, and re-addresses a hint to a dead silo while clearing it from the client cache. Each test fails when the corresponding gateway behavior is removed.Microsoft Reviewers: Open in CodeFlow