[Bug report] preloadOwner is not best-effort: an uninitialized GravitinoEnv fails the whole list request

Open Beginner friendly
#12,901 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
90/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
java

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.

Description

2.0.0 bug
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:

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:

./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.

Dominant language
Java
Stars
3.2k
Forks
940
Avg merge
1d 19h
Merged PRs (30d)
364

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apache/gravitino

All issues in apache/gravitino

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.