henriquejsza opened a new pull request, #14387:
URL: https://github.com/apache/gravitino/pull/14387
### What changes were proposed in this pull request?
In `MetastoreRegisterTableUtils.registerTable`, compare the new metadata
file's table
UUID with the current table's UUID before committing the overwrite. On a
mismatch the
request is rejected with an Iceberg `ValidationException` (mapped to HTTP
400) and the
table is left unchanged. The parsed metadata that was already read is now
kept and used
for the comparison instead of being discarded.
### Why are the changes needed?
`registerTable` with `overwrite: true` swapped the table's metadata location
before it
checked that the new metadata file belonged to the same table:
- it read the new metadata file but discarded the result (no UUID
comparison);
- it committed the swap through `metadataLocationOverwrite.overwrite(...)`;
- it then called `metastoreOps.refresh()`, which throws
`IllegalStateException: Table UUID does not match: current=... !=
refreshed=...`.
`IcebergExceptionMapper` has no mapping for that `IllegalStateException`, so
the request
returned HTTP 500. By then the swap was already committed, so the table
pointed at the
other table's metadata while the client was told the request had failed. An
operator
restoring a table from the wrong backup file would see a server error and
assume nothing
changed, while readers now saw the other table's schema and data.
Comparing UUIDs up front refuses the bad overwrite with a 4xx before
anything is
committed, leaving the table as it was.
Fixes #14303
### Does this PR introduce _any_ user-facing change?
Yes. An overwrite register request whose metadata file belongs to a
different table now
returns HTTP 400 (Iceberg `ValidationException`) and leaves the table
unchanged, instead
of returning 500 after repointing the table. No API or property changes.
### How was this patch tested?
Added `TestMetastoreRegisterTableUtils`:
- `testOverwriteRejectsMetadataFromAnotherTable`: two real metadata files
with distinct
UUIDs; registering table `a` with `b`'s metadata (overwrite) now throws
`ValidationException` and the metadata-location overwrite is never invoked.
- `testOverwriteAcceptsMetadataFromSameTable`: overwrite with a newer
metadata file of
the same table (same UUID) still commits the swap.
Ran the module test suite.
--
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]