Repository navigation
Conversation
Fields, dynamic fields and field types each have PUT/DELETE routes in the v2
Schema API; copy-fields were the one resource left reachable only through
/schema/bulk. The routes had been sketched out and commented out, with a TODO
noting that copy-field rules have no name to address them by.
Address them by source field instead: PUT /schema/copyfields/{sourceField}
takes a destinations list in the body, and DELETE removes every rule with that
source unless 'destination' query parameters narrow the selection. Deleting a
source that has no rules answers 404 rather than silently succeeding.
The source-addressed shape means one request covers a 1:many fan-out, at the
cost of the path naming a set of rules rather than a single one. Enumerating
the destinations for an unqualified DELETE goes through
IndexSchema.getCopyFieldProperties so that glob rules are covered as well as
explicit ones.
The ref guide's v2 copy-field examples are updated to the new endpoints; they
previously showed a v1 keyed-object body POSTed to /schema, which that path
answers with a 405 since it only carries GET.
The underlying 'add-copy-field' operation is purely additive: registerCopyField appends a rule without checking whether an identical one is already present, so PUTting the same destinations twice left the source copied twice over at index time. That breaks PUT's idempotency contract, and it also meant the body could only ever state the rules being added rather than the rules the caller wanted. Clear the source's existing rules as part of the same SchemaManager operation list, so the destinations in the body become the complete set for that source. Applying both operations as a unit keeps the change transactional: a rejected replacement leaves the previous rules in place. Renamed the endpoint method to upsertCopyFields, since 'add' no longer describes what it does. Adding a destination while keeping the others now means either listing them all, or using add-copy-field through the bulk endpoint, which still only appends; the ref guide spells out both, along with the duplicate hazard of the additive operation.
Rounds out /schema/copyfields/{sourceField} so the whole resource is addressed
through the path rather than partly through query parameters:
GET /copyfields/{source} the source's rules
PUT /copyfields/{source} set the complete destination list
POST /copyfields/{source} append destinations
DELETE /copyfields/{source} remove all of the source's rules
DELETE /copyfields/{source}/{destinations} remove the named ones
The 'destination' query parameter is gone; a trailing path segment names the
destinations instead, several at a time as a comma-separated list. Splitting
goes through StrUtils.splitSmart so a separator inside quotes or behind a
backslash does not split; it does not trim, so surrounding whitespace (which can
only arrive percent-encoded) is dropped separately.
POST appends without disturbing the rules already in place, which PUT cannot do
without a read-modify-write, and which therefore avoids losing one of two
concurrent appends. Destinations the source already copies to are skipped rather
than appended a second time, so a retried POST is harmless -- worth having for a
caller that timed out without learning whether its first attempt landed.
GET by source overlaps the existing source.fl query parameter on /copyfields,
but reads the resource at the path the write verbs use, so the ref guide leads
with it and presents source.fl as the alternative for filtering by destination
or by several sources at once.
The replace and append operations worked out which rules to remove or skip in the resource method, before handing SchemaManager a fixed list of operations. That read happens outside the schema update lock, while doOperations takes the lock, refreshes the schema and replays the operations on every retry. The list could therefore be stale precisely when it mattered: a concurrently added destination survived a replace, and a retry triggered by another node's change could fail with "Copy field directive not found" for a rule that had since been removed. Move the diffing into two internal-only operations, upsert-copy-field and append-copy-field, alongside the existing internal upsert-field. They inspect managedIndexSchema, which doOperations refreshes under the lock, so each attempt diffs against the rules actually in effect. Append builds a fresh operation rather than narrowing the caller's, so a retry does not inherit the previous attempt's filtering. Deleting every rule for a source now goes through the same path, by replacing its rules with none; the remaining out-of-lock read is only to report 404 for a source that has no rules at all. Also from review: - A path segment naming no destinations, e.g. /copyfields/src/,,, answered 404 claiming the source had no rules, when the request was simply malformed and the source may well have rules. It is now a 400. - A request body whose 'source' contradicts the path was silently overwritten; it is now rejected. - Documented that a PUT with an empty destinations list clears the source, and that a GET for a source with no rules returns an empty list rather than 404. The test setup uses the former to reset state, which no longer needs to swallow a 404.
# Conflicts: # solr/solr-ref-guide/modules/indexing-guide/pages/schema-api.adoc
Contributor
Author
|
i was worried we would have too much churn in #4943... |
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.
The v2 Schema API uses
destinationconsistently for copy-field writes and reads. Per-source requests use destination objects with independentmaxChars; bulk add/delete operations name one destination each, and destination filtering usesdestination.fl. V1 retainsdest, its existing bulk syntax, and its response format through explicit adapters.This draft follows #4943 and should merge after it. GitHub's PR diff includes the parent until that work reaches
main; the follow-up-only comparison shows the naming change separately. Rebase ontomainafter #4943 merges before marking this ready.The change updates the request models, generated clients, Admin UI, reference guide, upgrade notes, and changelog. Compatibility coverage checks v1 scalar/array
destrequests, v1 reads and filters, and the generated v2 bulk client.Validation: 85 targeted core API, legacy schema, serialization, and browser tests passed.
./gradlew tidyandcheck -x testpassed. The latter used a temporary source-scan exclusion for unrelated local.claude/worktrees/; repository build files are unchanged. The full test suite was not run.Developed with OpenAI Codex assistance.