Skip to content

A recovered firing of an ungrouped trigger counts against its trigger group's execution limit, not RECOVERING_JOBS - #4148

Merged
lahma merged 1 commit into
mainfrom
4142/recovery-limit-group
Oct 19, 2026
Merged

lahma merged 1 commit into
mainfrom
4142/recovery-limit-group

Conversation

@lahma

@lahma lahma commented Oct 19, 2026

Copy link
Copy Markdown
Member

Closes #4142

Under UseTriggerGroupWhenUnset, an ungrouped firing is limited under its trigger's group. A recovery trigger's group is RECOVERING_JOBS, so a replayed firing was limited under that group. It ran beside the firings its own group's limit held back, and was missing from that group's in-flight count until it ended. #4084 recorded this as a known limitation in StoreRecoveryTrigger's remarks. This PR closes it.

What changed

All three paths that build a recovery trigger (cluster recovery, a shutdown hand-back, startup recovery) already write the original trigger's group into its data map as FailedJobOriginalTriggerGroup. Each place that resolves a limit key now reads it for an ungrouped trigger in the recovery group:

Where Change
ExecutionLimits LimitTriggerGroup(TriggerKey, JobDataMap) / (ITrigger), ResolveGroupKeyOf(ITrigger, bool), NeedsOriginalTriggerGroup(…), all internal. The ITrigger form reads the data map only for a trigger in the recovery group, because a trigger's map is allocated on first read
QuartzSchedulerThread The in-flight ledger keys a running firing by ResolveGroupKeyOf(trigger, …)
RAMJobStore Acquisition takes the slot under the resolved group and names it in GroupsAtLimit; the cluster in-flight tally counts reservations and running firings under it
StdAdoDelegate.SelectTriggersToAcquire Slots are taken after the candidate read, in the same order, rather than row by row inside it. An open reader is in the way of a second statement, and a recovery candidate's original group is only in its JOB_DATA. Only an ungrouped candidate in the recovery group, under the derivation, costs that read. The binding and the read are split out into two private methods
TriggerAcquireResult.LimitTriggerGroup Internal init: the group the delegate resolved, which AdoJobStoreBase names in GroupsAtLimit
AdoJobStoreBase acquisition With a cluster-scoped limit and the derivation on, a (null, RECOVERING_JOBS) pair in the cluster in-flight count is replaced by the recovered firings' own groups. They are read with SelectFireInstances filtered to the recovery group, and one SelectTriggerJobDataMap per ungrouped firing
StoreRecoveryTrigger remarks The known-limitation paragraph now says what happens instead
Docs A bullet under "Letting the trigger group stand in" in execution-groups.md; a behaviour row in the 4.6 → 4.7 migration section

Nothing else about RECOVERING_JOBS changes: the trigger's key, context.Recovering, RecoveringTriggerKey, matchers and the execution group routing reads are untouched. No public API, schema or SQL statement changed.

For the reviewer

  • No 3.x companion. 3.x has execution limits and A recovered trigger keeps its job's execution group #4084's port, but no UseTriggerGroupWhenUnset / ResolveGroupKey derivation (checked on origin/3.x at 31c81b1). An ungrouped firing there is always in the ungrouped bucket, so the gap does not exist. The issue's "3.x has the same gap" does not hold.
  • "Both stores" read as RAM and ADO.NET. The in-memory store never builds a recovery trigger. It resolves the same way so that the two stores cannot key a firing differently, and so the scheduler-loop test can run on it.
  • The dashboard's execution-groups panel still keys a recovered firing under RECOVERING_JOBS. It resolves from FireInstanceDto, which carries no data map. That is display only, and left alone.
  • A replay of a replay through startup recovery loses the original group. SelectTriggersForRecoveringJobs overwrites the FailedJobOriginal* markers with the intermediate recovery trigger's, where StoreRecoveryTrigger keeps them. Such a firing is still limited under RECOVERING_JOBS. Aligning the two would change what the job reads as its original trigger, so it is not done here.
  • The delegate restructure keeps the slot order and the row-cap behaviour (An execution group at its limit can hide the due triggers behind it from a batch-size-1 acquisition #3928). A custom delegate that overrides SelectTriggersToAcquire is unaffected; it just keeps keying recovery candidates by their own group.

Tests

  • RecoveredLimitGroupSqliteTest (new, SQLite file, in the style of A recovered trigger keeps its job's execution group #4084's RecoveredExecutionGroupSqliteTest). One test per path: cluster recovery, shutdown hand-back and startup recovery. With the tenant at 0 slots the replay is held back and the round names tenant-a in GroupsAtLimit; with 1 slot it is acquired. Two more tests:
    • A replay in flight holds the tenant's cluster-scoped slot against a due tenant trigger.
    • The control: without the derivation the replay stays ungrouped.
  • SchedulerLoopExecutionLimitWakeTest.ARecoveredFiringHoldsTheSlotOfTheTriggerGroupItReplays: on the frozen-clock loop harness, a running replay fills batch's one slot. The loop hands exactly one firing to the pool before it parks, and the replay's end wakes it for the waiting batch trigger.
  • RAMJobStoreClusterLimitTest.ARecoveredFiringInFlightHoldsTheSlotOfTheTriggerGroupItReplays(reserved / started).
  • ExecutionGroupsTest: the resolution itself, plus three cases. A marker on a non-recovery trigger is ignored, a recovery trigger with no marker keeps its own group, and an explicit execution group wins.

Each part was disabled in turn and its tests failed:

  • LimitTriggerGroup off: the 6 behaviour tests failed.
  • The ADO in-flight expansion off, the ADO GroupsAtLimit change reverted and the ledger reverted: ARecoveredFiringInFlightHoldsItsTriggerGroupsClusterSlot failed, the three per-path tests failed on GroupsAtLimit, and the loop test failed on the thread-pool count.
  • The RAM in-flight tally reverted: both RAM cases failed.

Verification

  • dotnet fallout VerifyMigrations VerifySchema Compile UnitTest BenchmarkSmoke PublishTrimmed PublishAot VerifyDocsSnippets VerifyDocsLogEvents: every target succeeded. This ran before the rebase onto CronExpressionBuilder leaves an unset seconds field at 0, not * #4144, which touched only the cron builder and the migration guide.

    Project Total Failed Skipped
    Unit 9219 0 72
    Interceptors 35 0 0
    AspNetCore 1203 0 1
    Analyzers 525 0 0
  • After the rebase: dotnet fallout IntegrationTest --database sqlite gave 37 passed, 0 failed. IntegrationTest --database postgres gave 338 passed, 0 failed. The touched unit fixtures were re-run: 138 passed.

  • markdownlint-cli2 on the two changed pages: 0 errors.

  • BenchmarkSmoke passed. The delegate's acquisition read is on the benchmarked path, and no timings were taken.

🤖 Generated with Claude Code

@lahma lahma added this to the 4.7 milestone Oct 19, 2026
… group's execution limit, not RECOVERING_JOBS

Under UseTriggerGroupWhenUnset an ungrouped firing is limited under its
trigger's group, and a recovery trigger's group is RECOVERING_JOBS: the
replay ran beside the firings its own group's limit held back, and was
missing from that group's in-flight count until it ended (#4084 left this
as a known limitation).

Every path that builds a recovery trigger - cluster recovery, a shutdown
hand-back and startup recovery - writes the original trigger's group into
its data map. ExecutionLimits.LimitTriggerGroup reads it for an ungrouped
trigger in the recovery group, and every place a limit key is resolved now
goes through it: the scheduler thread's in-flight ledger, both stores'
acquisition filters and the groups a held-back round names, and both stores'
cluster in-flight counts. The ADO.NET delegate takes its slots after the
candidate read, so that a recovery candidate's data map can be read; only
such a candidate, under the derivation, costs that read.

Closes #4142

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lahma
lahma force-pushed the 4142/recovery-limit-group branch from 85f53bc to f97427e Compare October 19, 2026 19:19
@sonarqubecloud

Copy link
Copy Markdown

@lahma
lahma merged commit 560d694 into main Oct 19, 2026
21 checks passed
@lahma
lahma deleted the 4142/recovery-limit-group branch October 19, 2026 19:41
lahma added a commit that referenced this pull request Oct 20, 2026
…nd-after-count zone, recovery markers, and the options table

CronTriggerImpl.Clone used MemberwiseClone rather than base.Clone(), so its clone shared the original's
JobDataMap, which every other trigger type's clone copies: RAMJobStore stores and hands out clones, and a
write to one reached the other. TriggerCloneTest holds all five built-in types to a map of their own.

Startup recovery's SelectTriggersForRecoveringJobs wrote the FailedJobOriginalTrigger* markers over a
replay of a replay, naming the first recovery trigger, where cluster recovery's StoreRecoveryTrigger keeps
them. The second replay lost the original group, and with it the execution limit an ungrouped replay counts
against (#4148). It now keeps the markers a recovery trigger's map already carries.

DailyTimeIntervalScheduleBuilder.EndingDailyAfterCount works out the window's end at build time in
InTimeZone's zone or TimeZoneInfo.Local, which the scheduler's DefaultTimeZone (#4146) cannot reach: it is
applied when the trigger is stored. Left as it is and documented on the builder and in the default time
zone section. Computing it at store time would move it out of the builder for a difference that exists only
on a build day the zone changes its clocks, and EndingDailyAfterCountComputesAgainstTheTriggerBuildersClock
pins that day-dependent check as intended.

The scheduler options table in configuration/reference.md gains DefaultMisfireHandling (4.6, #4131);
DefaultTimeZone was already there. StdAdoConstantsTest.SelectedColumns matches SELECT and FROM as whole
words, so a column with FROM in its name no longer ends the list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lahma added a commit that referenced this pull request Oct 26, 2026
…nd-after-count zone, recovery markers, and the options table

CronTriggerImpl.Clone used MemberwiseClone rather than base.Clone(), so its clone shared the original's
JobDataMap, which every other trigger type's clone copies: RAMJobStore stores and hands out clones, and a
write to one reached the other. TriggerCloneTest holds all five built-in types to a map of their own.

Startup recovery's SelectTriggersForRecoveringJobs wrote the FailedJobOriginalTrigger* markers over a
replay of a replay, naming the first recovery trigger, where cluster recovery's StoreRecoveryTrigger keeps
them. The second replay lost the original group, and with it the execution limit an ungrouped replay counts
against (#4148). It now keeps the markers a recovery trigger's map already carries.

DailyTimeIntervalScheduleBuilder.EndingDailyAfterCount works out the window's end at build time in
InTimeZone's zone or TimeZoneInfo.Local, which the scheduler's DefaultTimeZone (#4146) cannot reach: it is
applied when the trigger is stored. Left as it is and documented on the builder and in the default time
zone section. Computing it at store time would move it out of the builder for a difference that exists only
on a build day the zone changes its clocks, and EndingDailyAfterCountComputesAgainstTheTriggerBuildersClock
pins that day-dependent check as intended.

The scheduler options table in configuration/reference.md gains DefaultMisfireHandling (4.6, #4131);
DefaultTimeZone was already there. StdAdoConstantsTest.SelectedColumns matches SELECT and FROM as whole
words, so a column with FROM in its name no longer ends the list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lahma added a commit that referenced this pull request Oct 26, 2026
…nd-after-count zone, recovery markers, and the options table

CronTriggerImpl.Clone used MemberwiseClone rather than base.Clone(), so its clone shared the original's
JobDataMap, which every other trigger type's clone copies: RAMJobStore stores and hands out clones, and a
write to one reached the other. TriggerCloneTest holds all five built-in types to a map of their own.

Startup recovery's SelectTriggersForRecoveringJobs wrote the FailedJobOriginalTrigger* markers over a
replay of a replay, naming the first recovery trigger, where cluster recovery's StoreRecoveryTrigger keeps
them. The second replay lost the original group, and with it the execution limit an ungrouped replay counts
against (#4148). It now keeps the markers a recovery trigger's map already carries.

DailyTimeIntervalScheduleBuilder.EndingDailyAfterCount works out the window's end at build time in
InTimeZone's zone or TimeZoneInfo.Local, which the scheduler's DefaultTimeZone (#4146) cannot reach: it is
applied when the trigger is stored. Left as it is and documented on the builder and in the default time
zone section. Computing it at store time would move it out of the builder for a difference that exists only
on a build day the zone changes its clocks, and EndingDailyAfterCountComputesAgainstTheTriggerBuildersClock
pins that day-dependent check as intended.

The scheduler options table in configuration/reference.md gains DefaultMisfireHandling (4.6, #4131);
DefaultTimeZone was already there. StdAdoConstantsTest.SelectedColumns matches SELECT and FROM as whole
words, so a column with FROM in its name no longer ends the list.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 6, 2026
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.

A recovered ungrouped trigger limited through UseTriggerGroupWhenUnset counts against RECOVERING_JOBS, not its group

1 participant