Skip to content

[CRE-7138] Bound timeout-based shard failover executions by execution concurrency - #24259

Merged
bolekk merged 3 commits into
developfrom
CRE-7138-bound-failover-execution-concurrency
Nov 24, 2026
Merged

bolekk merged 3 commits into
developfrom
CRE-7138-bound-failover-execution-concurrency

Conversation

@dmitriytymosh

@dmitriytymosh dmitriytymosh commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

CRE-7138

Timeout-based failover on the secondary shard started every due cached event at once. ExecuteTrigger goes straight to startExecution, so it skips the trigger event queue and ExecutionConcurrency. The number of in-flight executions per tick was unbounded.

Changes:

  • FailoverConfig.ExecutionConcurrency: the manager gets the same ExecutionConcurrency limiter that the legacy engine and the coordinator use. A nil limiter leaves executions unbounded.
  • executeDueTimeoutBasedFailovers calls non-blocking Use before popping an event. With no free slot, the tick stops and the remaining events stay cached for a later tick. The slot is freed when ExecuteTrigger returns.
  • If Use fails for a reason other than the limit (missing tenant, stopped), the error is logged. The due events stay cached in both cases.
  • New up/down counter platform_shard_failover_deferred_events, label outcome: concurrency_limit or limiter_error. It shows how many due events wait for a slot right now, node-wide, like platform_shard_failover_cached_events. The limiter's own resource.*.denied is shared with the engine and the coordinator, so it can't tell failover apart.
  • Test: 10 due events with limit 3 start 3 executions and keep 7 cached. After a slot frees, the next tick starts one more.
  • Tests: limiter error keeps events cached; the slot is freed when ExecuteTrigger fails, when the event left the cache before the pop, and when the context is cancelled; deferred_events follows the waiting events and drops to 0 on close.

Out of scope: SYSTEM_ERROR replay (replay) is still unbounded.

Requires

Supports

Deployment Validation Steps

  • Behaviour changes only with sharding and timeout-based failover enabled.
  • Under failover load, executions on the secondary shard stay within the per-workflow ExecutionConcurrency limit, and events over the limit run on later ticks.
  • platform_shard_failover_deferred_events{outcome="concurrency_limit"} is above 0 while the limit is reached and returns to 0 once the events run; limiter_error should stay at 0.

@dmitriytymosh
dmitriytymosh requested review from a team as code owners November 23, 2026 16:45
@github-actions

Copy link
Copy Markdown
Contributor

👋 dmitriytymosh, thanks for creating this pull request!

To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team.

Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks!

@github-actions

Copy link
Copy Markdown
Contributor

✅ No conflicts with other open PRs targeting develop

@dmitriytymosh dmitriytymosh self-assigned this Nov 23, 2026
@mchain0

mchain0 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

few items dropped via dm, mainly:

  1. there is maybe a risk of a permanent error - to be explored
  2. extend the tests by few extra scenarios, things for consideration like: multi-pool limiter, partial failure and rollback, use returning a non-limit error, Slot release on ExecuteTrigger error, panic or close, the popCachedEvent !ok path (a race between the loop and the primary's verdict), expiry of events held back by the limit, avoid time.Sleep, improve channel closing, etc.
  3. there should be some metric to track deferred events - that needs to be added

@dmitriytymosh dmitriytymosh added the ready for review PR is ready for code review label Nov 24, 2026
mchain0
mchain0 previously approved these changes Nov 24, 2026
@mchain0
mchain0 enabled auto-merge November 24, 2026 12:43
@mchain0
mchain0 requested a review from bolekk November 24, 2026 12:53
@mchain0
mchain0 added this pull request to the merge queue Nov 24, 2026
@bolekk
bolekk removed this pull request from the merge queue due to a manual request Nov 24, 2026
TimeoutBasedFailoverGate: h.engineLimiters.TimeoutBasedFailover,
TimeoutBasedFailoverWindow: h.engineLimiters.TimeoutBasedFailoverWindow,
Communicator: h.getShardFailoverComm(),
ExecutionConcurrency: h.engineLimiters.ExecutionConcurrency,

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.

We need to be careful to not reuse the same limiter more than once, otherwise we will double-count.
IIUC it's fine here because ShardFailoverManager calls ExecuteTrigger directly. But that might change in the future when we start putting failover events on the trigger queue. Maybe worth leaving a comment here.

@bolekk
bolekk added this pull request to the merge queue Nov 24, 2026
Merged via the queue into develop with commit 98f7155 Nov 24, 2026
241 of 242 checks passed
@bolekk
bolekk deleted the CRE-7138-bound-failover-execution-concurrency branch November 24, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review PR is ready for code review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants