sigram opened a new pull request, #5416: URL: https://github.com/apache/solr/pull/5416
https://issues.apache.org/jira/browse/SOLR-18679 Part 2 of [SOLR-18674](https://issues.apache.org/jira/browse/SOLR-18674): a vocabulary for schema metadata keys, and configurable limits. It builds on the `<meta>` element added in Part 1 (SOLR-18678, #5403). # Description Top-level metadata keys now follow a vocabulary: - **Dublin Core terms are the base vocabulary.** All 55 [DCMI Terms](https://www.dublincore.org/specifications/dublin-core/dcmi-terms/) are accepted under the `dc:` prefix, for example `dc:description` or `dc:subject`. A `dc:` key that is not a DCMI Term is rejected, so `dc:descripton` (missing `i`) fails the load. - **An unqualified key must be a DCMI Term.** `description` means `dc:description`. Solr keeps the key as written and never rewrites the schema, so external copies of schema files (GitOps, Argo CD) don't drift. Giving both spellings in one element is rejected as a duplicate. - **Any other prefix marks an extension**, for example `ext:unit` or `myorg:owner`. The `solr:` prefix is reserved for keys Solr may define later. Keys inside a nested `lst` are checked for syntax only. Values of any type are allowed for every key. The metadata limits can now be changed with system properties or environment variables, and the whole schema has a size cap. A schema over a limit fails to load, and a Schema API change that would go over a limit is rejected; each error names the property to raise. | Limit | Default | System property | |---|---|---| | Key length | 64 characters | `solr.schema.meta.key.length.max` | | String value length | 1024 characters (was 256) | `solr.schema.meta.string.length.max` | | Entries per element | 64 | `solr.schema.meta.entries.max` | | Nesting depth | 3 | `solr.schema.meta.depth.max` | | All metadata in the schema | 256 KB of compact JSON | `solr.schema.meta.total.size.max` | The environment variables are the upper-case forms, e.g. `SOLR_SCHEMA_META_TOTAL_SIZE_MAX`. # Implementation - The vocabulary and the validator move to SolrJ, in a new package `org.apache.solr.common.schema` (`SchemaMetadataVocabulary`, `SchemaMetadataValidator`), so clients can apply the same rules. On a client the limits come from the client's own system properties, so only the server's check is binding. The core `SchemaMetadataValidator` is removed, and `SchemaMetadata` calls the shared one. - `SchemaMetadataVocabulary.qualifiedKey(key)` maps `description` and `dc:description` to one spelling, for readers that need to look up a term under either form (Parts 3 and 4). - The schema-wide total is checked at the end of `IndexSchema.readSchema` and in `IndexSchema.persist(Writer)`, which every save of a managed schema goes through, including the Schema API's non-additive SolrCloud path. - When saving to a local file, `ManagedIndexSchema.persistManagedSchema` now serializes the schema first and writes the file only if that succeeds, so a rejected change leaves the existing file intact. - The key syntax is narrower than in Part 1: a prefix contains only letters and digits, the name has no `:`, and a key has at most one `:`. - The check for characters XML cannot store, added in Part 1, is removed. It covered only metadata, while every string value written to the managed schema from Schema API JSON has the same exposure. A separate ticket (https://issues.apache.org/jira/browse/SOLR-18696) proposes a general fix in `SchemaXmlWriter`. # Tests - `TestSchemaMetadata`: the vocabulary (unqualified DCMI Terms kept as written through save and reload, both spellings rejected, unknown, misspelled and wrongly cased keys, the reserved `solr:` prefix, key syntax edge cases, nested keys), limits set by system property, and the total cap at load and on save, where the existing managed-schema file stays unchanged. Existing tests now use `ext:` keys. - New `SchemaMetadataValidatorTest` in SolrJ: the term list, `qualifiedKey`, custom and default limits, and the total-size error message. - The schema, Schema REST API and Schema Designer suites pass (81 suites, 680 tests), as does `./gradlew :solr:solrj:check :solr:core:check -x test`. # Back-compat No change to the XML or JSON format, and no new rolling-upgrade risk beyond Part 1. Part 1 accepts any key that matches its pattern, so a schema that loads with Part 1 alone may be rejected with this change. Part 1 is not released yet, so both parts should ship in the same release; if Part 1 is backported, this change should be backported with it. # Checklist - [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. 🤖 Generated with [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]
