Skip to content

KAFKA-14214: Introduce read-write lock to StandardAuthorizer for consistent ACL reads.#12627

Closed
akhileshchg wants to merge 1 commit intoapache:trunkfrom
akhileshchg:KGLOBAL-14214
Closed

KAFKA-14214: Introduce read-write lock to StandardAuthorizer for consistent ACL reads.#12627
akhileshchg wants to merge 1 commit intoapache:trunkfrom
akhileshchg:KGLOBAL-14214

Conversation

@akhileshchg
Copy link
Copy Markdown
Contributor

@akhileshchg akhileshchg commented Sep 12, 2022

KAFKA-14214: Introduce read-write lock to StandardAuthorizer for consistent ACL reads.

The issue with StandardAuthorizer#authorize is, that it looks up aclsByResources (which is of type ConcurrentSkipListMap)twice for every authorize call and uses Iterator with weak consistency guarantees on top of aclsByResources. This can cause the authorize function call to process the concurrent writes out of order.

Implemented ReadWrite lock at StandardAuthorizer level to make sure the reads are strongly consistent with write order.

…nsistent ACL reads.

The issue with StandardAuthorizer#authorize is, that it looks up
aclsByResources (which is of type ConcurrentSkipListMap)twice for every
authorize call and uses Iterator with weak consistency guarantees on top of
aclsByResources. This can cause the authorize function call to process the
concurrent writes out of order.

Implemented ReadWrite lock at StandardAuthorizer level to make sure the reads
are strongly consistent with write order.
@akhileshchg akhileshchg changed the title KGLOBAL-14214: Introduce read-write lock to StandardAuthorizer for consistent ACL reads. KAFKA-14214: Introduce read-write lock to StandardAuthorizer for consistent ACL reads. Sep 12, 2022
@akhileshchg akhileshchg deleted the KGLOBAL-14214 branch September 12, 2022 22:41
Copy link
Copy Markdown
Contributor

@hachikuji hachikuji left a comment

Choose a reason for hiding this comment

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

Thanks @akhileshchg. I left some initial comments. I do wonder about the tradeoffs between the approach used here and what we do in AclAuthorizer. The advantage of the latter approach is that reads are never blocked. Since the authorizer needs to be accessed on very request, that is a tough advantage to overlook. On the other hand, to make it work, it looks like we would need to add batching methods for adding new ACLs since doing a copy for every ACL is probably a non-starter.

@@ -534,49 +536,19 @@ Iterable<AclBinding> acls(AclBindingFilter filter) {
}

class AclIterable implements Iterable<AclBinding> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we still need this class since it is just wrapping a list iterator?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

results.add(result);
}
return results;
return inReadLock(() -> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know it does not look as pretty, but perhaps we should just do the try/finally blocks. Especially for the case of authorize, it is annoying to have the additional allocations just to pass the calback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay. I'll remove the functions.

@Override
public void addAcl(Uuid id, StandardAcl acl) {
data.addAcl(id, acl);
inWriteLock(() -> data.addAcl(id, acl));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am not sure how much it matters, but it would probably be more efficient for addAcl to be a batched API. Perhaps it is ok since hopefully most of the time the brunt of the initialization is in loadSnapshot.

@mumrah
Copy link
Copy Markdown
Member

mumrah commented Sep 13, 2022

This was closed in favor of #12628

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.

3 participants