Repository navigation
Fixes #38016: keep the orphan sweep from failing a live reindex job while it initializes - #38093
Conversation
…hile it initializes The orphan sweep runs on every server every two minutes. A coordinator building a job's partitions held the reindex lock under a placeholder id, and nothing renewed that lock or the job's updatedAt until initialization finished. On a large catalog the sweep therefore failed the live job after ten minutes as "Job abandoned due to server crash or shutdown", and the coordinator could then mark it READY again and run it. - The executor moves the lock onto the job as soon as the job row exists, and renews the lock and updatedAt while the partitions are built. The renewal ends with initialization; execute() starts its own. - The sweep takes the reindex lock before failing an orphan, as it already does before recovering one, and fails it only if its status and updatedAt are unchanged since it was read. Partitions are cancelled and the app run is ended only when that write lands, and only runs that started before the job was created are ended. - The coordinator marks a job READY only while it is still INITIALIZING.
…o build - ADR:2026-11-18-the-reindex-orphan-sweep-fails-a-job-only-under-its-lock-and-unchanged states the lock handoff, the sweep's lock and compare-and-swap, and the STOPPING force-complete exception. - The lock in the sweep's fail path keeps it from acting alongside another server's sweep or a running reindex; the comments and test names now say so. - When partitions fail to build, the job is marked FAILED with the cause once the lock renewal has stopped, unless something else already ended it. Before, it stayed INITIALIZING with a freshly renewed updatedAt and blocked new runs for ten minutes before the sweep failed it as abandoned.
✅ PR checks passedThe linked issue has a description and all required Shipping project fields set. Thanks! |
failIfUnchanged took eight positional parameters, five of them adjacent longs, so a caller could swap a timestamp and a count unnoticed. The job state the sweep read (JobSnapshot: id, status, updatedAt) and the record counts (RecordCounts: processed, success, failed) are now records bound with @BindMethods, as OntologyReferenceDAO binds AxiomPosition.
Code Review ✅ Approved 🔴 High riskMoving reindex lock ownership and renewal, and guarding orphan failures with compare-and-swap, changes shared-state coordination; interruptions could disrupt reindex availability. Keeps a live reindex job's lock and updatedAt renewed while its partitions are built, and makes the orphan sweep fail a job only under the reindex lock with a compare-and-swap on the status and updatedAt it read. No issues found. VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
🤖 Backport to |
|
🤖 Backport to |
… job while it initializes (#38093) (#38120) Backport of #38093. The orphan sweep runs on every server every two minutes. A coordinator building a job's partitions held the reindex lock under a placeholder id, and nothing renewed that lock or the job's updatedAt until initialization finished. On a large catalog the sweep therefore failed the live job after ten minutes as "Job abandoned due to server crash or shutdown", and the coordinator could then mark it READY again and run it. - The executor moves the lock onto the job as soon as the job row exists, and renews the lock and updatedAt while the partitions are built. If they fail to build, the job is marked FAILED with the cause. - The sweep takes the reindex lock before failing an orphan, as it already does before recovering one, and fails it only if its status and updatedAt are unchanged since it was read. Partitions are cancelled and the app run is ended only when that write lands, and only runs that started before the job was created are ended. - The coordinator marks a job READY only while it is still INITIALIZING. - Recorded as ADR:2026-11-18-the-reindex-orphan-sweep-fails-a-job-only-under-its-lock-and-unchanged. On 2.0 the search-index job DAO is still nested in CollectionDAO, so the two new statements live there instead of in SearchReindexDAOs.
Describe your changes:
Fixes #38016
Detail's report still holds on
main.OrphanJobMonitorrunsJobRecoveryManager.performStartupRecovery()on every server every 2 minutes. While a coordinator builds a job's partitions:hasLiveCoordinatorLockcan't tie to the job;updatedAtuntilinitializePartitions()returns. On a large catalog that step walks every entity table and can pass the sweep's 10-minute staleness threshold.The sweep then calls
failJob(), which takes no lock and writes FAILED unconditionally. It also cancels pending partitions and ends every running SearchIndexingApplication run with "Job abandoned due to server crash or shutdown". The coordinator carries on and writes READY over the FAILED row. It then either runs the job while the run record says failed (if the placeholder lock row is still there) or fails it itself at the lock transfer. Later changes didn't close this: #29547 made a live lock under the job's own id count as proof of life, but during initialization the lock isn't under that id.What changed:
createJob): the lock moves onto the job as soon as the job row exists, and a renewal loop keeps the lock and the job'supdatedAtfresh while partitions are built. The loop ends when initialization returns.execute()starts its own, and a run that fails before reachingexecute()must not keep the lock alive. If the partitions fail to build, the job is marked FAILED with the cause instead of staying INITIALIZING. With a freshly renewedupdatedAt, an INITIALIZING row would block new runs for ten minutes and then be failed as "abandoned".JobRecoveryManager): failing an orphan now takes the reindex lock first, as recovering or terminalizing one already did, so it never acts alongside another server's sweep or a running reindex. A job it can't lock waits for a later sweep. The FAILED write is a compare-and-swap on the status andupdatedAtthe sweep read. Partition cancellation, lock release and ending the app run happen only when it lands. Only app runs that started before the job was created are ended, so the run whose start triggered the sweep keeps running. Force-completing a job stuck in STOPPING uses the same compare-and-swap.failIfUnchanged, which takes the job state the sweep read and the record counts as records, andmarkReadyIfInitializing.ADR:2026-11-18-the-reindex-orphan-sweep-fails-a-job-only-under-its-lock-and-unchanged.DISTRIBUTED_INDEXING.mdis updated to match.Type of change:
High-level design:
updatedAt), and make the sweep's FAILED write as careful as its recover/terminalize siblings (reindex lock plus compare-and-swap).coordinator.createJob, and the renewal loop would have to tolerate a missing row. Moving the lock right after the insert gives the sweep the same signal with a smaller change, and nothing can sweep a job before its row exists.createJob()throughexecute(). That would also cover staged-index creation. But if the strategy fails beforeexecute()(for example, staged index creation throws), nothing stops the executor, so the lock would be renewed forever and block every later reindex.updatedAtfresh, so sweepers on the old code leave them alone. Coordinators on the old code renew nothing while they initialize, so their long initializations can still be swept until every server runs this code.createJob()andexecute()is still not renewed, and a failure there isn't recorded on the job. That job is READY, which the sweep recovers rather than fails, so new runs are refused until the job is an hour old and the sweep fails it.mainbehaves the same. A follow-up can fail the job with a READY → FAILED compare-and-swap when the strategy throws beforeexecute().Tests:
Use cases covered
updatedAtare renewed while it builds.Unit tests
JobRecoveryManagerTest(5 new or rewritten tests, fail-path tests moved to the lock and the compare-and-swap),DistributedSearchIndexExecutorTest(3 new),DistributedSearchIndexCoordinatorTest(1 new, 1 updated).testStartupRecovery_FailsJobWhenLockBelongsToDifferentJobasserted the old behaviour: fail an orphan while another holder has the reindex lock. It is nowtestStartupRecovery_LeavesOrphanForALaterSweepWhileTheReindexLockIsHeld.mvn -B package -pl :openmetadata-service -am -Dtest=…at the pushed commit: 182 tests inDistributedSearchIndexCoordinatorTest,DistributedSearchIndexExecutorTest,JobRecoveryManagerTest,JobRecoveryOrphanDetectionTest,OrphanJobMonitorTest,DistributedJobParticipantTestandDistributedIndexingStrategyTest, 0 failures. The planner's focused unit step is the first three (130 tests).JobRecoveryManager35/35,DistributedSearchIndexCoordinator10/10,DistributedSearchIndexExecutor31/33. The two misses are the log infailJobStillInitializing's catch, reached only if reading the job throws while the build failure is already propagating. Measured with JaCoCo 0.8.10 on those three classes' unit tests; whole-class percentages mean little for 1,400-line classes.main's behaviour in one round (sweep fails without the lock; cleanup on a missed compare-and-swap; app runs ended up to now; READY written unconditionally; no renewal during initialization) fails exactly the 6 new or inverted tests and nothing else. One mutation per round for the rest: releasing the placeholder id instead of the job's lock, or leaving a failed build's job INITIALIZING, failscreateJobFailsTheJobAndFreesItsLockWhenBuildingPartitionsFails; failing a job something else already ended failscreateJobKeepsTheOutcomeOfAJobEndedWhileItsPartitionsWereBuilt.Backend integration tests
SearchReindexOrphanSweepIT(@Isolated: it holds the cluster-wide reindex lock). Against the realsearch_index_job/search_reindex_locktables it covers:failIfUnchangedmisses after a write;markReadyIfInitializingmoves an INITIALIZING job and leaves a FAILED one.7a01214, MySQL + Elasticsearch, parallel lane (the planner's focused step:mvn -B verify -pl :openmetadata-integration-tests -am -Pmysql-elasticsearch -DintegrationTests.lane=parallel -Dit.test=SearchReindexOrphanSweepIT …): 5 tests, 0 failures. The merge queue runs the other engines. It also passes on the 2.0 backport, [2.0] Fixes #38016: keep the orphan sweep from failing a live reindex job while it initializes (#38093) #38120.SearchIndexJobDAOthrough Jdbi, set up asJdbiUtilsdoes, on throwaway MySQL 8.3 and PostgreSQL 15 containers with the migration'ssearch_index_jobDDL. On both engines:markReadyIfInitializingmoved 1 row, then 0;failIfUnchangedmoved 0 for a staleupdatedAtor a wrong status, and 1 for the current read;statscleared.Ingestion integration tests
Not applicable.
Playwright (UI) tests
Not applicable.
Visual regression baselines
Manual testing performed
main:createJob()→initializePartitions()→transferReindexLock(), the lock TTL and refresh start,isJobOrphaned()/hasLiveCoordinatorLock(),processOrphanedJob()→failJob(), and the unconditionalupdatebehind both.SearchIndexJobDAOthrough Jdbi on MySQL 8.3 and PostgreSQL 15 (results above).main's behaviour at each fix and confirmed the matching unit test fails (results above).UI screen recording:
Not applicable — backend-only fix.
Checklist:
I have read the CONTRIBUTING document.
My PR title is
Fixes <issue-number>: <short explanation>My PR is linked to a GitHub issue via
Fixes #<issue-number>above.I have commented on my code, particularly in hard-to-understand areas.
For JSON Schema changes: I updated the migration scripts or explained why it is not needed. (no schema change)
For a UI feature or feature task: as part of PR creation, I ran the PR build in Docker with sample data and embedded a verified GitHub-hosted recording plus build/health evidence above (or explained why this requirement is not applicable). (no UI change)
I have added tests (unit / integration / Playwright as applicable) and listed them above.
Self-review: I reviewed the final diff against
REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.Reviewed at
f7df8a7, in two passes. The first pass, atc2d9b2d, raised one 🔴 and two 🟡, all fixed inf7df8a7: the missing decision record (added); comments that credited the sweep's lock with a case that can't occur (reworded, tests renamed); and a failed partition build that left the job INITIALIZING, blocking new runs for ten minutes (now marked FAILED). The second pass found nothing blocking. Greptile's one finding (failIfUnchangedtook eight positional parameters) is fixed in7a01214; 182 unit tests pass there.Decision check: if this PR decides something the next contributor could undo — a schema field, REST path or format another component or repo must agree with, a new default or limit, an ordering that must hold, or a rule stated only in this description — it adds a record under
docs/decisions/(see itsREADME.md). This description is gone fromgit logafter the squash-merge. (ADR:2026-11-18-the-reindex-orphan-sweep-fails-a-job-only-under-its-lock-and-unchanged)I have added a test that covers the exact scenario we are fixing. For complex issues, comment the issue number in the test for future reference.
🤖 Generated with Claude Code


Confidence Score: 5/5
The latest changes appear safe to merge.Summary
No blocking issues found in this follow-up. The latest change groups the job state and record counts into named records without changing how abandoned jobs are failed.
Tests were not run during this review.
Reviews (4) · Last reviewed commit: "Bind failIfUnchanged's read state and co..." · Reviewed by Greptile