jerryshao opened a new issue, #13312:
URL: https://github.com/apache/gravitino/issues/13312
### Version
main branch (also affects branch-1.3)
### Describe what's wrong
Several entities do not validate the length of their name, alias or comment
before writing to the relational metadata store. A value longer than the store
column fails in the database and the server returns `500 RuntimeException` with
the raw database error in the message.
Names of metalakes, catalogs, schemas, tables, filesets, topics and models
are already validated (64-character name pattern) and return 400. The following
fields are not:
| Entity | Field | Column limit |
|---|---|---|
| Tag, Policy, Role, User, Group, Job template | name | 128 |
| Model version | alias | 128 |
| Metalake, Catalog, Schema, Fileset, Topic, Tag | comment | 256 |
In addition, the `SQLExceptionConverter` implementations (PostgreSQL / MySQL
/ H2) only handle duplicate-key errors. Every other `SQLException` is wrapped
into an `IOException` and ends up as a 500 containing the database message.
### Error message and/or stacktrace
```
POST /api/metalakes/{metalake}/tags {"name": "<129 characters>"}
500
{"code":1002,"type":"RuntimeException",
"message":"... ERROR: value too long for type character varying(128) ..."}
```
### How to reproduce
1. Start Gravitino (main) with a PostgreSQL (or MySQL/H2) metadata store.
2. Create a tag with a 128-character name: 200.
3. Create a tag with a 129-character name: 500 with the error above.
4. Same for the other fields in the table, e.g. a catalog comment of 257
characters.
### Additional context
Proposed fix:
1. Add an optional max length to `Field` and check it in
`Entity#validate()`; set it on the name/comment fields above, and check aliases
in `ModelVersionEntity#validate()`. Entities are validated on both create and
alter, so this covers both paths. The error names the entity type, field and
limit, without echoing the value.
2. Validate comment length early in
`Schema/Fileset/TopicNormalizeDispatcher`, before the catalog creates external
resources (e.g. fileset directories are created before the entity is built).
3. As a fallback, map "value too long" errors (SQLState `22001` for
PostgreSQL/H2, error code `1406` for MySQL) in the three converters to
`IllegalArgumentException` (400), without the database message.
The same class of issue for statistic names was fixed in #12887.
--
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]