Add OOM protection for Export operations#5511
Merged
apurvabhaleMS merged 15 commits intomainfrom May 7, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5511 +/- ##
==========================================
- Coverage 77.63% 77.38% -0.26%
==========================================
Files 985 985
Lines 36189 36337 +148
Branches 5498 5513 +15
==========================================
+ Hits 28097 28120 +23
- Misses 6738 6856 +118
- Partials 1354 1361 +7 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds OutOfMemoryException (OOM) recovery to export processing jobs, aligning export behavior with the existing reindex OOM mitigation approach to avoid immediate job failure and enable controlled retries.
Changes:
- Added OOM recovery to
ExportProcessingJobwith two strategies: surrogate-id range splitting (SQL) and batch-size reduction retries (Cosmos/non-SQL). - Updated
ExportJobTaskto let OOM exceptions bubble up to the processing job for centralized recovery handling. - Relaxed setters on select
ExportJobRecordfields to allow internal batch/range adjustments during recovery; added/updated unit tests for both recovery paths.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.Health.Fhir.Core/Features/Operations/Export/Models/ExportJobRecord.cs | Allows internal updates to batch size and surrogate id range fields needed for OOM recovery. |
| src/Microsoft.Health.Fhir.Core/Features/Operations/Export/ExportProcessingJob.cs | Implements OOM recovery via range splitting (SQL) or batch reduction (Cosmos/non-SQL). |
| src/Microsoft.Health.Fhir.Core/Features/Operations/Export/ExportJobTask.cs | Removes “fail immediately on OOM” behavior so recovery can be handled by ExportProcessingJob. |
| src/Microsoft.Health.Fhir.Core.UnitTests/Features/Operations/Export/ExportProcessingJobTests.cs | Adds/updates tests validating OOM retries, range splitting calls, and failure after max reductions. |
| src/Microsoft.Health.Fhir.Core.UnitTests/Features/Operations/Export/ExportJobTaskTests.cs | Adds tests ensuring OOM exceptions bubble up from search paths. |
…osmos paths) before retrying. It:
LTA-Thinking
reviewed
May 7, 2026
LTA-Thinking
previously approved these changes
May 7, 2026
LTA-Thinking
approved these changes
May 7, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Export jobs previously failed immediately on
OutOfMemoryExceptionwith no retry. This change adds OOM recovery toExportProcessingJob, following the pattern established by Reindex.Two recovery strategies based on backend
SQL path (jobs with surrogate ID ranges — All and Patient parallel exports):
GetSurrogateIdRangesPatientfor Patient exports, the assigned single type for All exportsCosmos path (jobs without surrogate IDs — Group exports, non-parallel, filtered exports):
Key changes
ExecuteWithSurrogateIdRangeSplittingAsync(SQL) andExecuteWithBatchReductionAsync(Cosmos) methods. InjectedISearchServicefor callingGetSurrogateIdRanges.catch (OutOfMemoryException)that immediately failed the job. OOM now re-throws toExportProcessingJobfor recovery.MaximumNumberOfResourcesPerQuery,StartSurrogateId,EndSurrogateIdchanged tointernal setfor batch size reduction and range updates.Failure behavior preserved
When retries are exhausted, the job fails with the same 413 RequestEntityTooLarge status and
ExportOutOfMemoryExceptionmessage as before, ensuring no change to user-facing error responses.Related Issues
Addresses AB189470, AB187913
Testing
ExportProcessingJobTestsandExportJobTaskTestsGetSurrogateIdRangesis called with correct resource type and range, sub-ranges are processed with reduced batch sizeExportJobTaskverified for all three export types (All, Patient, Group)FHIR Team Checklist
Semver Change (docs)
Patch|Skip|Feature|Breaking (reason)