sigram opened a new pull request, #5430: URL: https://github.com/apache/solr/pull/5430
https://issues.apache.org/jira/browse/SOLR-18680 # Description Schema API reads now show the metadata attached to fields, dynamic fields and field types, and replace commands keep it. Builds on the metadata storage and validation in Part 2 (#5416). - **Reads include metadata by default.** An element that has metadata returns it as `meta`, on `/schema` and on the field, dynamic field and field type endpoints, in v1 and v2. `includeMetadata=false` leaves it out. - **Replacing an element keeps its metadata.** `replace-field`, `replace-dynamic-field` and `replace-field-type` without `meta` used to drop the metadata. They now keep it, and `"meta": {}` clears it. # Implementation - `upsert-*` on an existing element follows the same keep rule, since it is a replace. - `"meta": null` counts as absent, so it keeps the metadata. - The existing v2 `meta=true` parameter (package info) is a separate thing and is unaffected. - `SchemaManager` now records whether a replace or upsert batch changed only metadata. Nothing returns that value yet. # Tests New tests in `TestSchemaManagerMetadata`, `TestSchemaMetadata`, `TestBulkSchemaAPI`, `GetSchemaAPITest` and `PackageSchemaReloadTest` cover these changes and run in CI. # Checklist Please review the following and check all that apply: - [x] I have reviewed the guidelines for [How to Contribute](https://github.com/apache/solr/blob/main/CONTRIBUTING.md) and my code conforms to the standards described there to the best of my ability. <details> <summary>For Claude reviewers</summary> **Intent and root cause:** Before this change the Schema API never emitted `meta`, and every `replace-*` rebuilt the element from the request alone, so metadata was silently lost. Now, for `replace-field`, `replace-dynamic-field` and `replace-field-type`, an absent or null `meta` carries over the old element's metadata (`ManagedIndexSchema.createReplacement`, and `setMetadata(oldFieldType.getMetadata())` in `replaceFieldType`). A non-null `meta` replaces it entirely, and `{}` clears it. **Approach specifics:** - `includeMetadata` is read in `IndexSchema.SchemaProps` (default `true`). The `META` handler returns null when it is false, and both `getProperties` overloads remove the `meta` key. `FIELD_TYPES` now goes through `sp::getProperties`. - v2 `GetSchema` takes `SolrParams` by injection and passes only `includeMetadata` to `getNamedPropertyValues`. `SchemaHandler` passes `req.getParams()` to all six `GetSchema` constructions. - `GetSchemaField.insertPackageInfo` skips the `meta` subtree. Metadata is free-form user data, and a `class` key inside it would otherwise be treated as a plugin class. - Metadata-only detection (`SchemaManager.differsOnlyInMetadata`) serializes the schema with `includeMetadata=false` (`IndexSchema.serializeWithoutMetadata`) before and after the batch. - It runs only when every operation is a replace or upsert. - Equal strings are accepted without parsing. Otherwise the two are compared as DOM trees with `isEqualNode`, which ignores attribute order but keeps child order, so a reordered analyzer chain is a change. - The result is the net effect of the batch. Changing a definition and changing it back in one batch counts as metadata-only. - `reindexRequired` is reset at the start of each retry round. - `IndexSchema.persist(Writer)` now calls `SchemaMetadata.validateTotalSize` before writing. - Rejected: a per-element diff class comparing property maps. It needed normalization of lists and named lists, and the serialized comparison replaces it. **Invariants relied on:** - `persist` and `serializeWithoutMetadata` share one writer, so the same schema serializes identically apart from `<meta>`. - A replace op without `meta` in its args never reaches `SchemaField.create` with a `meta` key (`createReplacement` removes it). **Scrutinize here:** - `replaceDynamicField` takes the old metadata from `getPrototype().getMetadata()`. - `canChangeOnlyMetadata` relies on `OpType` for every operation in the batch. **Test coverage:** - `TestSchemaManagerMetadata` (11 tests, managed core): keep, clear and replace for each element kind, null `meta`, upsert of an existing element, mixed batches, net effect of a batch, and an invalid key leaving the schema unchanged. - `TestSchemaMetadata`: `includeMetadata` on the property maps, and `serializeWithoutMetadata` having no `<meta>`. - `TestBulkSchemaAPI.testIncludeMetadataOnReads`: every v1 read endpoint over HTTP. - `GetSchemaAPITest`: v2 `GetSchema` passes only `includeMetadata`. - `PackageSchemaReloadTest`: with a real package classloader, `meta=true` and `includeMetadata` are independent. - Gaps: - v2 over HTTP covers only the single field and single field type reads, not the list endpoints or `/schema`. - There is no SolrCloud test of persistence through ZooKeeper or reload on another node. - Validation errors naming the offending key are checked for `replace-field` only. - No test targets the DOM-compare path alone, for example a reordered-attribute case. - Nothing was run by hand against a live Solr. **Scope:** [SOLR-18680](https://issues.apache.org/jira/browse/SOLR-18680), part of SOLR-18674. Stacked on Part 2 (#5416). Not in this PR, planned next in the same issue: - `reindexRequired` in v1 and v2 write responses. - A bulk `set-schema-meta` command. - Ref guide updates. - A changelog entry. SolrJ and the Admin UI are out of scope. </details> 🤖 Generated with assistance from [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
