jerryshao opened a new pull request, #13322:
URL: https://github.com/apache/gravitino/pull/13322

   ### What changes were proposed in this pull request?
   
   Names, aliases and comments are now checked against their store column width 
before they are written. Values that are too long are rejected with a 400 that 
names the entity, the field and the limit, e.g. `The name of the tag must not 
exceed 128 characters`.
   
   - **Entity layer:** `Field` supports an optional max length, and 
`Entity#validate()` passes the entity type into the error message. Entities are 
validated when built, which covers both create and alter.
     - Name (128): tag, policy, role, user, group, job template.
     - Comment (256): metalake, catalog, schema, fileset, topic, tag.
     - Alias (128): model version aliases, checked in 
`ModelVersionEntity#validate()`.
     - The limits are defined in `EntityFieldLimits` and match every schema 
script. Length is counted in code points, as MySQL (utf8mb4) and PostgreSQL do.
   - **Early checks** where the catalog creates external resources before the 
entity is built:
     - fileset and schema create in `FilesetCatalogOperations`, before the 
directories are created;
     - topic create and comment update in `TopicNormalizeDispatcher`, before 
Kafka is called.
   - **Model rename:** `ModelNormalizeDispatcher` now applies the name 
specification to `ModelChange.rename`, as table, fileset and view renames 
already do. Previously a model rename skipped the name check.
   - **Fallback:** the SQL exception converters map value-too-long errors 
(PostgreSQL and H2 `22001`, MySQL `1406`) to `IllegalArgumentException`. The 
SQL exception is logged on the server but not attached as the cause, because 
the error response serializes the full stack trace.
   
   ### Why are the changes needed?
   
   Values longer than the column reached the database, and the server returned 
500 with the raw database error. For topics, the store failure was swallowed: 
the Kafka topic was created but the entity was not persisted.
   
   Fix: #13312
   
   Remaining gaps are tracked in #13317.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes.
   - Too-long values now return 400 instead of 500, and the error no longer 
contains the database message.
   - A topic with a too-long comment is rejected before it is created in Kafka.
   - Renaming a model now follows the same name rules as creating one: at most 
64 characters, no reserved words, only letters, digits, `_`, `/`, `=` and `-`. 
New names outside these rules return 400.
   
   ### How was this patch tested?
   
   - **Unit tests:**
     - `TestEntityFieldLimits`: every limited field at and over its limit, plus 
code-point counting.
     - `TestField` and the converter tests.
     - `TestModelNormalizeDispatcher` (new): model rename name rules.
   - **Real H2 store:**
     - Tag create, rename and comment update in `TestTagManager`.
     - Fileset and schema create in `TestFilesetCatalogOperations`: no 
directory is left behind.
     - Fileset comment update in `TestFilesetCatalogOperations`.
     - `TestFilesetMetaService`: the rollback test now fails the version insert 
on a real H2 column, which also covers the `22001` fallback end to end.
   - **Integration tests:**
     - New `NameAndCommentLengthIT`: tag, policy, catalog, schema and fileset. 
It needs no Docker, so it runs on every metadata backend.
     - `MetalakeIT`, `AccessControlIT`, and `ModelCatalogOperationsIT` (alias 
length and model rename).
   - `./gradlew :core:test :server:test :catalogs:catalog-fileset:test 
:catalogs:catalog-model:test -PskipITs` passes, and the ITs above pass in 
embedded mode on H2.
   
   🤖 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]

Reply via email to