Skip to content

[KYUUBI #7079] Improve performance of AccessRequest initialization #7081

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

wForget
Copy link
Member

@wForget wForget commented Jun 5, 2025

Why are the changes needed?

Improve performance of authz rules.

Constantize some properties to reduce object creation:

  • AccessRequest initialization requires reflection methods
  • RuleHelper.ugi (different sparkSession may have different authz ugi)

closes #7079

How was this patch tested?

Was this patch authored or co-authored using generative AI tooling?

No

* @param argClasses the classes of the arguments
* @return an unbound method that can be invoked later
*/
def getMethod(clz: Class[_], methodName: String, argClasses: Class[_]*): UnboundMethod = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not simplify much code, can we inline it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not simplify much code, can we inline it?

Makes sense, changed.

@wForget wForget changed the title [KYUUBI #7079] Improve performance of authz rules [KYUUBI #7079] Improve performance of AccessRequest initialization Jun 5, 2025
@codecov-commenter
Copy link

codecov-commenter commented Jun 5, 2025

Codecov Report

Attention: Patch coverage is 0% with 57 lines in your changes missing coverage. Please review.

Project coverage is 0.00%. Comparing base (cad5a39) to head (bb469c7).
Report is 21 commits behind head on master.

Files with missing lines Patch % Lines
...uubi/plugin/spark/authz/ranger/AccessRequest.scala 0.00% 57 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master   #7081    +/-   ##
=======================================
  Coverage    0.00%   0.00%            
=======================================
  Files         697     700     +3     
  Lines       43203   43457   +254     
  Branches     5854    5887    +33     
=======================================
- Misses      43203   43457   +254     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@wForget wForget marked this pull request as ready for review June 5, 2025 12:17
@wForget wForget requested a review from pan3793 June 6, 2025 02:19
private def getUserGroupsFromUgi(user: UserGroupInformation): JSet[String] = {
user.getGroupNames.toSet.asJava
}

private def getUserGroupsFromUserStore(user: UserGroupInformation): Option[JSet[String]] = {
private lazy val userGroupMappingOpt: Option[JHashMap[String, JSet[String]]] = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is safe to cache

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is safe to cache

userGroupMapping may be updated by RangerUserStoreRefresher, I will only cache reflect methods

@@ -68,17 +70,43 @@ object AccessRequest {
req
}

private val getRolesFromUserAndGroupsMethod: Option[UnboundMethod] =
getMethod(
SparkRangerAdminPlugin.getClass,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SparkRangerAdminPlugin.getClass,
classOf[SparkRangerAdminPlugin],

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SparkRangerAdminPlugin is an object and does not seem to work with classOf.


private lazy val getUserGroupMappingMethod: Option[UnboundMethod] =
getMethod(
Class.forName("org.apache.ranger.plugin.util.RangerUserStore"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's located at ranger-plugins-common, should be always accessible?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's located at ranger-plugins-common, should be always accessible?

I don't get your point, but the logic here seems to be consistent with previous.

val userGroupMapping =
invokeAs[JHashMap[String, JSet[String]]](userStore, "getUserGroupMapping")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, it's a new feature of Ranger 2.1, we must use reflection as long as we support lower Ranger versions

wForget and others added 9 commits July 8, 2025 16:58
…kyuubi/plugin/spark/authz/ranger/AccessRequest.scala

Co-authored-by: Cheng Pan <pan3793@gmail.com>
…kyuubi/plugin/spark/authz/ranger/AccessRequest.scala

Co-authored-by: Cheng Pan <pan3793@gmail.com>
…/apache/kyuubi/plugin/spark/authz/ranger/AccessRequest.scala"

This reverts commit 686c45b.
…/apache/kyuubi/plugin/spark/authz/ranger/AccessRequest.scala"

This reverts commit 99e0bd3.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE][AUTHZ] Improve performance of authz rules
3 participants