Repository navigation
feat(durable-jobs): discover shards by start time - #11210
ReubenBond wants to merge 30 commits into
Conversation
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes core runtime recovery behavior and a public catalog enumeration API across multiple providers, which warrants final human review despite the added regression coverage.
Review tier: Lite
Findings: None
What changed in this PR
This PR improves Durable Jobs shard recovery responsiveness by switching runtime shard discovery from a “full catalog sweep then start” model to an incremental, bounded discovery loop which retains a catalog enumerator across turns so eligible shards can start executing while the catalog scan continues. In support of this, IJournalStorageCatalog.ListAsync is updated to accept ListOptions and to yield results in provider traversal order (rather than requiring ordinal sorting), enabling paging/scan-based providers to stream identities as they are discovered.
Changes:
- Implement bounded, resumable shard discovery in
JournaledJobShardManager(batching catalog traversal, preserving progress across turns, and disposing enumerators on completion/failure/stop). - Update
IJournalStorageCatalog.ListAsynctoListOptions?and align provider implementations/documentation with traversal-order enumeration semantics. - Add/adjust targeted regressions to validate incremental discovery behavior, cancellation/disposal, page-failure behavior, and ordering assumptions across providers.
| File | Description |
|---|---|
| test/Orleans.Journaling.Tests/VolatileJournalStorageProviderTests.cs | Updates listing calls to ListOptions and removes ordering assumptions from assertions. |
| test/Orleans.Journaling.Tests/S3JournalStorageTests.cs | Updates listing calls to ListOptions and relaxes ordering expectations to match traversal order. |
| test/Orleans.Journaling.Tests/JournalStorageCatalogTests.cs | Adds comprehensive cross-provider catalog enumeration tests (paging, cancellation, stability, disposal, failure propagation). |
| test/Orleans.Journaling.Tests/AzureTableJournalStorageProviderTests.cs | Adjusts tests to expect provider traversal order and updates prefix listing calls to ListOptions. |
| test/Orleans.DurableJobs.Tests/DurableJobs/JournaledJobShardManagerTests.cs | Adds extensive discovery/resume/failure/cancellation/stop coverage for bounded discovery and enumerator lifecycle. |
| test/Orleans.Core.Tests/DurableJobs/LocalDurableJobManagerTests.cs | Adds lifecycle/discovery-loop tests ensuring early activation, retention of signals during sweeps, and shutdown cleanup behavior. |
| test/Extensions/Orleans.Redis.Tests/Journaling/RedisJournalStorageTests.cs | Updates Redis provider list usage to ListOptions and changes assertions to set-membership vs ordering. |
| test/Extensions/Orleans.Redis.Tests/Journaling/RedisJournalStorageCatalogTests.cs | Adds Redis catalog scan tests covering batching, prefix snapshotting, failure/cancel/disposal semantics. |
| src/Redis/Orleans.Journaling.Redis/RedisJournalStorageProvider.cs | Reworks Redis catalog enumeration to stream results in traversal order with bounded metadata batches and duplicate suppression. |
| src/Redis/Orleans.Journaling.Redis/README.md | Documents Redis discovery semantics (batching, traversal order, duplication/cancellation/error behavior). |
| src/Orleans.Journaling/VolatileJournalStorage.cs | Updates volatile catalog listing to ListOptions and traversal-order yielding (no global sort buffer). |
| src/Orleans.Journaling/README.md | Documents new catalog enumeration contract, including traversal order and consumer guidance for batching/retained enumerators. |
| src/Orleans.Journaling/ListOptions.cs | Introduces ListOptions with Prefix for catalog enumeration filtering. |
| src/Orleans.Journaling/IJournalStorageCatalog.cs | Updates catalog API to ListOptions? and clarifies traversal-order + streaming semantics in remarks. |
| src/Orleans.Journaling/CompatibilitySuppressions.xml | Adds package-validation suppressions for the ListAsync signature change. |
| src/Orleans.DurableJobs/README.md | Documents bounded shard discovery behavior, lookahead/interval, and failure/cancellation semantics. |
| src/Orleans.DurableJobs/LocalDurableJobManager.cs | Updates periodic checking to support incremental discovery turns, shorter polling, and stop-time discovery disposal ordering. |
| src/Orleans.DurableJobs/JournaledJobShardManager.cs | Implements resumable, bounded discovery with retained catalog enumerator and pending-assignment delivery semantics. |
| src/Orleans.DurableJobs/JobShardManager.cs | Adds internal discovery abstraction (DiscoverJobShardsAsync, HasMoreCatalogWork, StopDiscoveryAsync). |
| src/Azure/Orleans.Journaling.AzureStorage/README.md | Documents Azure providers’ traversal-order catalog enumeration and paging behavior. |
| src/Azure/Orleans.Journaling.AzureStorage/AzureTableJournalStorageProvider.cs | Switches to paged enumeration and traversal-order yielding with ListOptions. |
| src/Azure/Orleans.Journaling.AzureStorage/AzureBlobJournalStorageProvider.cs | Switches to paged enumeration and traversal-order yielding with ListOptions; adjusts init ordering. |
| src/AWS/Orleans.Journaling.S3/S3JournalStorageProvider.cs | Switches to traversal-order yielding with ListOptions and canonical-WAL filtering per object. |
| src/AWS/Orleans.Journaling.S3/README.md | Documents S3 traversal-order catalog enumeration and continuation behavior. |
| src/api/Orleans.Journaling/Orleans.Journaling.cs | Updates generated public API surface for ListOptions and new ListAsync signature. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Local shutdown currently awaits a pre-cancellation snapshot of running shard tasks, which can miss shard tasks activated during the final membership/periodic loop iterations and allow shutdown to complete with work still running.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/Orleans.DurableJobs/LocalDurableJobManager.cs — In Stop(), runningShards is snapshotted before cancelling/awaiting the background membership +… |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes runtime discovery/shutdown behavior and the public catalog enumeration contract across multiple providers, so it warrants final human review despite the added regression coverage.
Review tier: Lite
Findings: None
Issues resolved since last review (1)
| Severity | Finding |
|---|---|
src/Orleans.DurableJobs/LocalDurableJobManager.cs — In Stop(), runningShards is snapshotted before cancelling/awaiting the background membership +… View resolved comment |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The new public VolatileJournalStorageProvider.ListAsync(ListOptions, ...) overload likely needs a corresponding CP0006 entry in CompatibilitySuppressions.xml to avoid package validation failures.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/Orleans.Journaling/CompatibilitySuppressions.xml — Compatibility suppressions cover the removed ListAsync(JournalId, ...) overload for… |
Issues resolved since last review (1)
| Severity | Finding |
|---|---|
src/Orleans.DurableJobs/LocalDurableJobManager.cs — In Stop(), runningShards is snapshotted before cancelling/awaiting the background membership +… View resolved comment |
119fe76 to
f3e7301
Compare
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The changes are cohesive, validated with targeted unit/regression coverage for batching, cancellation/failure handling, and shutdown ordering, and no blocking issues were found in the updated logic or option validation.
Review tier: Lite
Findings: None
Issues resolved since last review (1)
| Severity | Finding |
|---|---|
src/Orleans.Journaling/CompatibilitySuppressions.xml — Compatibility suppressions cover the removed ListAsync(JournalId, ...) overload for… View resolved comment |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
LocalDurableJobManager’s discovery loop can observe cancellation after a shard is yielded and exit without disposing that just-yielded shard, which can leak resources during shutdown/cancellation.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/Orleans.DurableJobs/LocalDurableJobManager.cs — In ProcessShardDiscoveryAsync, a cancellation can be observed after the shard has been yielded by… |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Bounded shard discovery using a timestamp-based MaxId risks skipping legacy GUID-named shard journals on upgrade, which can prevent overdue shard recovery unless a compatibility/migration path is implemented or explicitly documented.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/Orleans.DurableJobs/JournaledJobShardManager.cs — DiscoverJobShardsAsync always sets ListOptions.MaxId to a timestamp-based value… |
Pre-existing issues (1)
| Severity | Finding |
|---|---|
src/Orleans.DurableJobs/LocalDurableJobManager.cs — In ProcessShardDiscoveryAsync, a cancellation can be observed after the shard has been yielded by… View comment |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It introduces cross-cutting behavioral changes across shard discovery, catalog range semantics, and multiple storage providers, which warrants careful human validation of compatibility and operational impact.
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/Azure/Orleans.Journaling.AzureStorage/AzureTableJournalStorageOptions.cs — The default Azure Table partition-key mapping was changed from percent-encoding to UTF-16 hex… |
Pre-existing issues (2)
| Severity | Finding |
|---|---|
src/Orleans.DurableJobs/JournaledJobShardManager.cs — DiscoverJobShardsAsync always sets ListOptions.MaxId to a timestamp-based value… View comment |
|
src/Orleans.DurableJobs/LocalDurableJobManager.cs — In ProcessShardDiscoveryAsync, a cancellation can be observed after the shard has been yielded by… View comment |
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes core discovery semantics and storage-provider listing behavior across multiple backends (including key layouts and ordering/cutoff logic), warranting final human validation.
Review tier: Lite
Findings: None
Issues resolved since last review (3)
| Severity | Finding |
|---|---|
src/Azure/Orleans.Journaling.AzureStorage/AzureTableJournalStorageOptions.cs — The default Azure Table partition-key mapping was changed from percent-encoding to UTF-16 hex… View resolved comment |
|
src/Orleans.DurableJobs/JournaledJobShardManager.cs — DiscoverJobShardsAsync always sets ListOptions.MaxId to a timestamp-based value… View resolved comment |
|
src/Orleans.DurableJobs/LocalDurableJobManager.cs — In ProcessShardDiscoveryAsync, a cancellation can be observed after the shard has been yielded by… View resolved comment |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The nullable projected ETag path can cause an unconditional ownership write; Redis request-cost documentation also needs clarification.
Get a fresh assessment by requesting another Copilot review.
Review tier: Lite
Findings: 4
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Unresolved storage-layout compatibility, legacy-shard recovery, duplicate initialization, and Redis telemetry issues block approval.
Get a fresh assessment by requesting another Copilot review.
Review tier: Lite
Findings: 1
Open (1)
Resolved since last review (5)
Split the time-addressable discovery implementation from dotnet#11210, preserving the final source behavior and contributor fixes at 7c8dae0.
|
Closing this combined source PR in favor of the focused constituent PRs: #11257 (catalog queries and storage layouts), #11258 (time-based discovery), and #11259 (provider telemetry). The independent shutdown-safety slice, #11256, has already merged. The branch and discussion remain preserved as the historical combined reference. |




Split review map
This work is published as four focused PRs. The storage and shutdown roots can be reviewed and merged independently.
The dependent PRs target
mainand include their prerequisite commits. The linked comparisons isolate each review slice. After maintainers merge the prerequisites, rebase the dependent branches ontomainto present their final standalone diffs, including when prerequisites are squash-merged.This PR remains open as the combined design and source reference, with its branch preserved at
7c8dae07d451cda3ebc949fc02ce23c15476d169. The four published heads compose without conflicts into Git tree8754c3ed61d2b5ce2036cdc0773882f3c89f374e, exactly matching that source snapshot across all 60 changed files and 565 diff hunks. The independent roots' mechanical catalog-caller and list-readiness adaptations are superseded by the discovery slice in that exact combined tree.Problem
Random shard journal names require discovery to inspect metadata for every shard, including jobs scheduled far into the future. Recovery work should scale with the due range, and providers should use their native prefix and key-range capabilities to limit traversal and data transfer. Runtime metrics should expose the logical operations and underlying SDK work which drive latency and API costs.
Solution
Name shard journals
jobs/shards/<yyyyMMddTHHmmssfffffffZ>-<unique-id>, using fixed-width UTC start time before the unique suffix. Discovery selects the rawjobs/shards/prefix through the configured lookahead horizon, including every overdue shard. Each check owns a fresh, locally scoped sweep: deduplicate and order selected entries, use projected ownership metadata or read it when absent, then claim oldest first and deliver shards as they open. Successful assignments already delivered continue executing if a later candidate fails. Storage errors surface and a later check starts a fresh sweep. The local manager tracks yielded shards before observing cancellation. Shutdown closes activation admission, awaits discovery and registered execution tasks through cleanup, then disposes remaining inactive cached shards, including when a running task faults.IJournalStorageCatalog.ListAsyncstreamsJournalCatalogEntryvalues containingIdand optionalMetadata.ListOptionssupports raw ordinalPrefixmatching, including partial time segments, inclusiveMinId/MaxIdbounds, andIncludeMetadata. Options are snapshotted when enumeration begins and range constraints intersect. A shared helper derives tighter native prefixes from common lower/upper prefixes. Empty ranges perform no storage queries.IncludeMetadatadefaults to false. When requested, Blob, Table, and Volatile catalogs project complete snapshots containing the journal format, storage ETag, and caller-owned properties observed together. S3 and Redis return null metadata because their listings supply identities rather than complete journal metadata. Projection adds no separate per-journal metadata requests. Durable Jobs requests projection and reads metadata only for entries without snapshots. Claims retain ETag-conditional updates, so a stale listing cannot overwrite a concurrent ownership change. Provider-internal reads needed to preserve metadata during updates remain part of those updates.DurableJobsOptions.ShardLoadLookaheadPerioddefaults to ten minutes andShardCheckIntervalto five minutes, with startup validation. Recovery leaves the lower time bound open so long-overdue work is included. Other catalog callers can select narrower day/hour prefixes or explicit intervals.Provider efficiency
wal/namespace, raw/common id prefix, nativeStartFrom, and ordered upper cutoffUseOrderedListing=true, default mappingStartAfter, ordered upper cutoffwal/SCAN MATCH; local range checksBlob WALs use
wal/<journalId>and checkpoints usecheckpoints/<journalId>/<snapshotId>. S3 uses the correspondingwal/<mapped-base-key>andcheckpoints/<mapped-base-key>/<snapshotId>layout. Catalog listing selects the WAL namespace before pagination, including for unbounded queries. Recovery and checkpoint cleanup follow the full checkpoint name published in WAL metadata. Blob custom naming delegates participating in the catalog produce the default WAL name in the configured container; direct storage access retains configurable names. S3 custom mapping delegates map logical identities/prefixes to base keys, and the provider adds the WAL namespace and validates reverse mappings against canonical keys.Blob and ordered S3 lower/upper optimizations apply to order-compatible bounds such as the fixed-width ASCII shard names. Blob translates its lower seek and upper cutoff to
wal/<MinId>andwal/<MaxId>. S3's exclusiveStartAfteruses a conservative marker strictly before the inclusive lower key:wal/plus the lower bound with its final character removed, sent only when it narrows beyond the native prefix. Later pages use continuation tokens alone, including after empty responses. Both ordered providers finish consumption after the upper boundary page. The shared suffixed-key cutoff logic is removed now that both layouts use a leading WAL prefix. S3 ordered listing is an explicit capability independent of append mode; directory buckets leave it disabled.The default Table mapping accepts printable ASCII (
0x20through0x7E) and uses two uppercase hex digits per byte, preserving ordinal order and raw prefixes exactly. Its 1,024-character PK limit permits journal ids up to 512 characters. Storage creation validates this default-mapping contract before client access. Query bounds retain their original ordinal meaning, including bounds outside the stored alphabet. Custom Table mappings and other providers retain their existing journal-id contracts. Redis keeps the existing SHA-256 hash tag for data/metadata co-location and includes the reversible key name outside the tag.Runtime observability
Shared
Microsoft.Orleansmetrics provide two layers across S3, Azure Blob, Azure Table, Redis, and Volatile storage:orleans-journaling-provider-operationsandorleans-journaling-provider-operation-durationmeasure provider-created storage handles, catalog enumeration, and applicable lifecycle operations with boundedprovider,operation, andstatuslabels.orleans-journaling-provider-api-callsandorleans-journaling-provider-api-call-durationmeasure underlying SDK invocations and exposed service pages with boundedprovider,api, andstatuslabels.Outcomes distinguish success, errors, cancellation, conditional conflicts, missing journals, already-existing journals, unapplied updates, early disposal, throttling, unavailability, and timeouts. Catalog latency accumulates active execution and excludes consumer pauses. Empty logical ranges issue zero SDK calls; successful empty service pages count as calls, and advancing beyond the final page adds no request. All provider-issued S3/Azure SDK I/O sites are instrumented, including metadata/part-count HEADs, checkpoint operations, entity transactions, replay queries, cleanup, and initialization. Redis records key-scan enumerations, canonical-id reads, script evaluation, and owned-connection closure.
These metrics measure SDK work. SDK-internal retries, chunked uploads, and Redis cursor paging can produce additional wire requests within one measured invocation. Service-side transaction metrics or SDK transport telemetry provide billing-grade counts. Resource identities stay in logs and traces instead of metric labels. The operator guide and metrics catalog document these distinctions and latency-histogram guidance.
Representative recovery work
The synthetic identity-only catalog workload has 256 predecessor hosts, one overdue shard per predecessor, and either one or thirty future time buckets:
Each case uses one bounded catalog enumeration. Zero- and three-claim budgets preserve the candidate-read count and select oldest claims first. Metadata-enabled regressions separately demonstrate using projected snapshots without initial candidate metadata reads, reading only entries without metadata, and rejecting claims based on stale ETags. Native request regressions cover lower seeks, future-tail termination, retained checkpoint exclusion before pagination, Table PK filters, and zero Redis identity metadata reads with default keys. These measurements distinguish selected candidates and transferred keys from provider-internal scan work and cloud latency.
Dependency and review scope
The streaming journal-catalog API landed in #11211. Review the current changes for time-addressable naming, simplified discovery, native provider selection, WAL/checkpoint layouts, optional catalog metadata, runtime API metrics, generated APIs, focused regressions, and documentation.
Extracted and refined from #9903, with contributor attribution preserved in the commits.
Microsoft Reviewers: Open in CodeFlow