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

Test queryable built-in role synchronization #118964

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,18 @@ public void clusterChanged(ClusterChangedEvent event) {

private void syncBuiltInRoles(final QueryableBuiltInRoles roles) {
if (synchronizationInProgress.compareAndSet(false, true)) {
try {
final Map<String, String> indexedRolesDigests = readIndexedBuiltInRolesDigests(clusterService.state());
if (roles.rolesDigest().equals(indexedRolesDigests)) {
logger.debug("Security index already contains the latest built-in roles indexed, skipping roles synchronization");
} else {
executor.execute(() -> doSyncBuiltinRoles(indexedRolesDigests, roles, ActionListener.wrap(v -> {
logger.info("Successfully synced [" + roles.roleDescriptors().size() + "] built-in roles to .security index");
}, QueryableBuiltInRolesSynchronizer::handleException)));
}
} finally {
final Map<String, String> indexedRolesDigests = readIndexedBuiltInRolesDigests(clusterService.state());
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this is getting to be a lot but I wonder if we want a try-catch around this whole block after all -- readIndexedBuiltInRolesDigests can technically throw and so can executor.execute.

I spent a bit of time thinking of how to refactor this to avoid four separate calls to synchronizationInProgress.set(false) but nothing straight-forward comes to mind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely, I'll wrap it with try-catch block. I don't see other option.

if (roles.rolesDigest().equals(indexedRolesDigests)) {
logger.debug("Security index already contains the latest built-in roles indexed, skipping roles synchronization");
synchronizationInProgress.set(false);
} else {
executor.execute(() -> doSyncBuiltinRoles(indexedRolesDigests, roles, ActionListener.wrap(v -> {
logger.info("Successfully synced [" + roles.roleDescriptors().size() + "] built-in roles to .security index");
synchronizationInProgress.set(false);
}, e -> {
synchronizationInProgress.set(false);
handleException(e);
})));
}
}
}
Expand Down