[Bug report] preloadOwner is not best-effort: an uninitialized GravitinoEnv fails the whole list request
- Dominant language
- Java
- Stars
- 3.2k
- Forks
- 935
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 286
Description
### Version
main branch
### Describe what's wrong
`MetadataAuthzHelper.preloadOwner` is a best-effort cache warm-up - its `catch (Exception e)` logs and ignores any failure. But the entity-store lookup sits *outside* that `try`:
```java
private static void preloadOwner(Entity.EntityType entityType, NameIdentifier[] nameIdentifiers) {
if (!GravitinoEnv.getInstance().cacheEnabled()) {
return;
}
EntityStore entityStore = GravitinoEnv.getInstance().entityStore(); // <-- outside the try
try {
entityStore.relationOperations().batchListEntitiesByRelation(...);
} catch (Exception e) {
LOG.warn("Ignore preloadOwner error:{}", e.getMessage(), e);
}
}
```
`GravitinoEnv.entityStore()` has `Preconditions.checkArgument(initialized, "GravitinoEnv is not initialized.")`, so when the environment is not initialized that `IllegalArgumentException` escapes the warm-up, propagates out of `MetadataAuthzHelper.filterByExpression`, and fails the entire list request with HTTP 400 - even though nothing about the requested listing actually failed.
### Error message and/or stacktrace
```
{"code":1001,"type":"IllegalArgumentException",
"message":"Failed to operate tag(s) operation [LIST] under object [object1.object2], reason [GravitinoEnv is not initialized.]"}
java.lang.IllegalArgumentException: GravitinoEnv is not initialized.
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:143)
at org.apache.gravitino.GravitinoEnv.entityStore(GravitinoEnv.java:261)
at org.apache.gravitino.server.authorization.MetadataAuthzHelper.preloadOwner(MetadataAuthzHelper.java:552)
at org.apache.gravitino.server.authorization.MetadataAuthzHelper.filterByExpression(MetadataAuthzHelper.java:364)
at org.apache.gravitino.server.web.rest.MetadataObjectTagOperations.lambda$listTagsForMetadataObject$9(MetadataObjectTagOperations.java:217)
```
### How to reproduce
Version: main branch. Any list endpoint that routes through `MetadataAuthzHelper.filterByExpression` while `GravitinoEnv` is uninitialized returns 400. Observable on `main` with:
```bash
./gradlew :server:test -PskipITs --tests "org.apache.gravitino.server.web.rest.TestMetadataObjectTagOperations"
```
Three tests fail with 400 instead of 200: `testListTagsForObject`, `testListTagsForObjectUnderHierarchicalSchema`, `testListTagsDeduplicatesDifferentAssignmentValues`.
A booted server initializes `GravitinoEnv`, so production traffic does not hit this today - the defect is that a helper documented and coded as ignorable can still abort the request.
### Additional context
Found while adding tag support for Semantic Models (#12615). The fix is to move the lookup inside the existing `try`.
Contributor guide
Research direction
Start in server authorization MetadataAuthzHelper.preloadOwner around line 552, then run the named TestMetadataObjectTagOperations tests with ./gradlew :server:test -PskipITs --tests "org.apache.gravitino.server.web.rest.TestMetadataObjectTagOperations". Done means an uninitialized GravitinoEnv no longer aborts list requests and testListTagsForObject, testListTagsForObjectUnderHierarchicalSchema, and testListTagsDeduplicatesDifferentAssignmentValues return 200.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- authorization, backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 90/100