Repository navigation
Conversation
When the schema has _nest_path_, a delete-by-query now also deletes all nested descendants of the documents it matches, preventing orphaned child documents. Opt out with the withDescendants=false local param. * New WithDescendantsQuery, optimized for the common case of matching only root docs * Expansion happens in DirectUpdateHandler2, so it applies on every replica and on tlog replay * Fixed SolrTestCaseJ4.json() writing child docs in a list twice * Docs: nested documents page and Solr 10 upgrade notes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Automated PR readiness judgements (LLM-generated; may be wrong; not updated on later pushes).
|
|
I haven't looked through the tests closely yet but I have everything else. Claude initially suggested a match doc iteration over DocValues. I suggested this instead, iterating the paths. Which way is faster depends on how many matching docs there are and maybe depth of nesting and also the overall ratio of nested docs to root docs. Note that nest path's terms index != it's DocValues -- the latter has more info embedded in it. |
|
|
||
| When the schema has the `\_nest_path_` field, a delete-by-query now also deletes all nested descendants of the documents it matches, at any depth. | ||
| Previously, a query matching a parent but not all of its descendants left orphaned child documents behind, violating Solr's integrity assumptions for nested documents. | ||
| To opt out, add the `withDescendants=false` local param to the query, e.g., `{!lucene withDescendants=false}category:obsolete`. |
There was a problem hiding this comment.
Why this parameter belongs to query, but not to handler request parameters? Can such query be a clause of enclosing query? I don't think so.
There was a problem hiding this comment.
Quoting the 2nd sentence of the solution:
Because only the query string is logged and forwarded, expanding it there applies consistently on every replica, to reordered DBQs, and on tlog replay.
Putting request parameters on a /update is really problematic as it's not captured in the update log and thus wouldn't be replayed.
… roots Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… for all paths Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ts filter for roots Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
Versioned DBQ replay deletes a newer child On @Test
public void testReplayOlderDbqAgainstNewerInPlaceChild() throws Exception {
testLogReplayWithReorderedDBQWrapper(
() -> {
updateJ(
jsonAdd(sdoc("id", "RDBQ8", "_version_", 1L, "kids",
sdocs(sdoc("id", "RDBQ8.0", "val_i_dvo", 1)))),
params(DISTRIB_UPDATE_PARAM, FROM_LEADER));
long childVersion =
addAndGetVersion(
sdoc("id", "RDBQ8.0", "_root_", "RDBQ8", "val_i_dvo", map("set", 7)),
null);
assertTrue(childVersion > 2);
updateJ(
jsonDelQ("id:RDBQ8"),
params(DISTRIB_UPDATE_PARAM, FROM_LEADER, "_version_", "-2"));
},
() -> {
assertJQ(req("q", "id:RDBQ8.0"), "/response/numFound==1");
assertJQ(req("q", "id:RDBQ8"), "/response/numFound==1");
});
}Run with The child assertion fails: the query returns 0 documents instead of 1, although replay reports Could the version check also cover descendants, while retaining any ancestors needed by a protected child? AI assistance: AI helped review the code, design and run the reproduction, and draft this comment. |
…nd last match Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…endantsQuery Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…pying them Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
@shihchengwei-lab re: versioned DBQ replay Thanks for the careful repro. The replay result is real: a newer child under an older DBQ-matched root gets deleted. But I don't think a real update stream can produce that sequence. A DBQ only runs with an older This small test demonstrates both points on a single node: the in-place update is rejected after the DBQ, and a client The sequence only arises from hand-built 🤖 This response was AI-generated with Claude Code. |
|
I substantially improved
I moved the intersecting/conjunction DISI to an inner class as we're not using this anywhere else (yet). It could be moved or donated to Lucene if it proves useful. I also stopped computing the cost() as we don't need it. |
https://issues.apache.org/jira/browse/SOLR-18199
Description
Delete-by-query (DBQ) with nested documents could easily leave orphaned child documents: unless the query also matched every descendant of what it deleted, nested-doc integrity was violated.
Solution
When the schema has
_nest_path_,DirectUpdateHandler2.getQuery()wraps the DBQ in a newWithDescendantsQuery, which also matches all nested descendants of the matched docs, at any depth. Because only the query string is logged and forwarded, expanding it there applies consistently on every replica, to reordered DBQs, and on tlog replay.*:*is left alone. Opt out with thewithDescendants=falselocal param, e.g.{!lucene withDescendants=false}....WithDescendantsQueryrelies on descendants being indexed immediately before their ancestor. When all matches in a segment are roots (the common case), it uses the cached roots filter shared with{!parent which=/}. Otherwise it works level by level from the_nest_path_terms. See its javadocs for details. A smallFixedBitSetIntersectionIteratorutility was added for that.Notes:
_nest_path_was added) aren't found as descendants; documented.UpdateLogrequests are never closed (a pre-existing leak risk for any DBQ parser that callsreq.getSearcher()).SolrTestCaseJ4.json(), which wrote child docs in a list twice.Tests
WithDescendantsQueryTest: randomized multi-level trees across segments vs. a reference model, plus Lucene'sQueryUtils.checkDeleteByQueryNestedDocsTest: randomized DBQ shapes vs. a model, opt-out, and a_root_-only schemaTestRecovery: reordered DBQs with tlog replayDeleteByQueryNestedDocsCloudTest: replicas stay consistentFixedBitSetIntersectionIteratorTestChecklist
mainbranch../gradlew check.🤖 Generated with Claude Code