You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "ayushtkn (via GitHub)" <gi...@apache.org> on 2026/07/09 14:27:40 UTC

[PR] Eliminate redundant metastore lookups when resolving principal roles [polaris]

ayushtkn opened a new pull request, #5020:
URL: https://github.com/apache/polaris/pull/5020

   `DefaultAuthenticator.resolvePrincipalRoles` runs on every authenticated request and already calls `loadGrantsToGrantee`, which returns both grant records and the resolved securable entities in a single bulk metastore read. The authenticator was ignoring those pre-loaded entities and calling `loadEntity` once per grant record, so a principal with `N` roles caused `1+N` metastore reads per auth instead of one. This change resolves role names from `LoadGrantsResult.getEntitiesAsMap()`, matching the pattern already used in `PolarisAdminService`, while preserving existing behavior: missing entities and non-PRINCIPAL_ROLE securables are still filtered out, and requested-role filtering is unchanged. 
   
   ## Checklist
   - [ ] 🛡️ Don't disclose security issues! (contact security@apache.org)
   - [ ] 🔗 Clearly explained why the changes are needed, or linked related issues: Fixes #
   - [ ] 🧪 Added/updated tests with good coverage, or manually tested (and explained how)
   - [ ] 💡 Added comments for complex logic
   - [ ] 🧾 Updated `CHANGELOG.md` (if needed)
   - [ ] 📚 Updated documentation in `site/content/in-dev/unreleased` (if needed)
   


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Eliminate redundant metastore lookups when resolving principal roles [polaris]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #5020:
URL: https://github.com/apache/polaris/pull/5020#discussion_r3552411255


##########
runtime/service/src/main/java/org/apache/polaris/service/auth/DefaultAuthenticator.java:
##########
@@ -167,17 +169,14 @@ protected Set<String> resolvePrincipalRoles(
     Predicate<String> includeRoleFilter =
         requestedRoles == ALL_ROLES_REQUESTED ? role -> true : requestedRoles::contains;
 
+    Map<Long, PolarisBaseEntity> entitiesById =
+        Objects.requireNonNullElse(loadGrantsResult.getEntitiesAsMap(), Map.of());
+
     Set<String> activeRoles =
         loadGrantsResult.getGrantRecords().stream()

Review Comment:
   `LoadGrantsResult.getEntitiesAsMap()` can legitimately be null (see comment in `LoadGrantsResult` about older code not serializing `entities`). Using `Objects.requireNonNullElse(..., Map.of())` makes the “entities not provided” case indistinguishable from “no entities”, causing roles to resolve to an empty set instead of falling back to `loadEntity(...)` as the previous implementation did. This can break backward compatibility if the metastore layer returns `entities == null`.
   
   Consider matching `PolarisAdminService#getOrLoadEntity(...)`: keep the map nullable and fall back to `loadEntity(...)` only when it’s null (still avoiding N+1 in the common case where entities are preloaded).



-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Eliminate redundant metastore lookups when resolving principal roles [polaris]

Posted by "dimas-b (via GitHub)" <gi...@apache.org>.
dimas-b merged PR #5020:
URL: https://github.com/apache/polaris/pull/5020


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Eliminate redundant metastore lookups when resolving principal roles [polaris]

Posted by "ayushtkn (via GitHub)" <gi...@apache.org>.
ayushtkn commented on code in PR #5020:
URL: https://github.com/apache/polaris/pull/5020#discussion_r3552534710


##########
runtime/service/src/main/java/org/apache/polaris/service/auth/DefaultAuthenticator.java:
##########
@@ -167,17 +169,14 @@ protected Set<String> resolvePrincipalRoles(
     Predicate<String> includeRoleFilter =
         requestedRoles == ALL_ROLES_REQUESTED ? role -> true : requestedRoles::contains;
 
+    Map<Long, PolarisBaseEntity> entitiesById =
+        Objects.requireNonNullElse(loadGrantsResult.getEntitiesAsMap(), Map.of());
+
     Set<String> activeRoles =
         loadGrantsResult.getGrantRecords().stream()

Review Comment:
   done



-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org