Skip to content

SOLR-18391: Fail collection creation cleanly when the collection is missing from cluster state during replica assignment - #4997

Draft
nick-boss-tech wants to merge 6 commits into
apache:mainfrom
nick-boss-tech:solr-18391-submit
Draft

nick-boss-tech wants to merge 6 commits into
apache:mainfrom
nick-boss-tech:solr-18391-submit

Conversation

@nick-boss-tech

@nick-boss-tech nick-boss-tech commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖 (posted on behalf of Nick Shanin)

https://issues.apache.org/jira/browse/SOLR-18391

What happens today

Collection creation can fail with a NullPointerException and leave a zombie collection behind. During a create, the placement plugin reads the new collection's state; because of a timing window between the state being written and the read, that lookup can return null, and PlacementPluginAssignStrategy dereferences it. The NPE is not an exception type the create flow handles, so the failure escapes without the cleanup that a handled failure gets: the half-created collection stays in the cluster state, unusable, until an operator removes it by hand.

What this change does

PlacementPluginAssignStrategy checks the lookup and, when the collection is not found, throws an Assign.AssignmentException naming the collection instead of dereferencing null. That is the exception type CreateCollectionCmd already catches: its existing handling runs DeleteCollectionCmd cleanup and returns a BAD_REQUEST, so the create now fails cleanly and can be retried. The production change is 17 lines in one file; the cleanup path it triggers is existing, unmodified code.

Proof

No automated test ships with this PR, at the reviewer's request: the two test classes drafted for it were mock-heavy and were removed (David Smiley's review feedback; the removal is the head commit of this branch). An earlier version of the branch carried a strategy-level test showing the AssignmentException is thrown in place of the NPE.

Verified at head 3000eee on 2026-10-04: the tree is tidy-clean, compiles with Error Prone enabled, and passes :solr:core:check -x test.

Limits

There is no regression test for this race, per the reviewer request above. The timing window itself is not reproduced by a test; the behavior rests on the code path, where the thrown exception type is the one the create flow already handles.

Changelog: changelog/unreleased/SOLR-18391.yml (fixed)

AI assistance

AI agents assisted with research, implementation, review, and drafting. Nick Shanin directed the work and takes responsibility for this contribution.

…Test

Mockito's thenReturn() cannot accept PlacementPluginFactory<?> for a
method returning PlacementPluginFactory<?> because the two wildcard
captures never unify. Use doReturn(), which takes Object, instead.

@dsmiley dsmiley left a comment

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.

I appreciate the fix; it's better than the status quo. Although the race condition indicated suggests the fix is to resolve the race.

As for the tests... there's so much mock setup that I think the value proposition of retaining them isn't worth it.

The fix is a small null check that is obviously correct by inspection;
the elaborate Mockito scaffolding costs more to maintain than it verifies.
@github-actions github-actions Bot removed the tests label Oct 2, 2026

@nick-boss-tech nick-boss-tech left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropped both test files.

@dsmiley

dsmiley commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

I'm hesitant to merge this. It replaces an NPE with an error, but the null/race shouldn't have happened in the first place. We still have a TODO/problem to be resolved eventually. The fact that the collection is in a failed state is bad; this fixes that for this very narrow case. If you improved collection creation error detection to be graceful -- that would be welcome, and would also address the NPE here and also other bugs TBD. A colleague at my last company did that but didn't contribute it :-(

@nick-boss-tech

nick-boss-tech commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 AI text below 🤖 (posted on behalf of Nick Shanin)

As suggested here, the broader route is now up as #5027: collection creation cleans up after itself when it fails partway, instead of only handling the one NullPointerException case. This draft is superseded by that PR; please review there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants