Skip to content
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

RANGER-5148: Fix redundant role cache modify triggered by role versio… #538

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

Conversation

Gooch0922
Copy link

@Gooch0922 Gooch0922 commented Feb 24, 2025

…n changes in concurrent scenarios.

What changes were proposed in this pull request?

Solve the problem of concurrent cache updates by clients caused by frequent modifications of role IDs.

How was this patch tested?

Tested locally.

if (roleCacheWrapper.getRolesVersion() < rangerRoleVersionInDB) {
ret = roleCacheWrapper.getLatestRangerRoles(
serviceName, roleDBStore, lastKnownRoleVersion, rangerRoleVersionInDB);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

ret should be updated in else clause, right?

if (roleCacheWrapper.getRolesVersion() < rangerRoleVersionInDB) {
  ret = roleCacheWrapper.getLatestRangerRoles(serviceName, roleDBStore, lastKnownRoleVersion, rangerRoleVersionInDB);
} else {
  ret = roleCacheWrapper.getRoles();
}

Copy link
Author

Choose a reason for hiding this comment

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

The variable "ret" has already been initialized and the cache has been retrieved once at line 76. There is no need to retrieve the cache repeatedly, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

ret initialized in line 76 is an older version, hence the if block at line 78 is entered. Consider 2 threads:

  1. thread-1: ret is initialized to version=100; acquired lock at line 81
  2. thread-2: ret is initialized to version=100; waiting for the lock at line 81
  3. thread-1: refreshes roleCacheWrapper and ret to the latest version, say 101, at line 85; releases the lock
  4. thread-2: acquires the lock, finds that roleCacheWrapper has the lastest version; skips line 85; leaves ret at version 100

The call from thread-2 will return version 100; the expected version is 101. Makes sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants