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

KAFKA-17423 Trie implementation #17087

Open
wants to merge 20 commits into
base: trunk
Choose a base branch
from

Conversation

Claudenw
Copy link

@Claudenw Claudenw commented Sep 4, 2024

This change is dependent upon KAFKA-17316: Standard authorizer refactor (#16779) That change will reduce the number of files that are changed in this request.

More detailed description of your change,
if necessary. The PR title and PR message become
the squashed commit message, so use a separate
comment to ping reviewers.

Implements the StandardAuthorizer with a Trie data structure instead of the original sorted list. This results in an order of magnitude speed increase.

Extensive tests are added to verify that the new implementation matches the old implementation.

Summary of testing strategy (including rationale)
for the feature or bug fix. Unit and/or integration
tests are expected for any behaviour change and
system tests should be considered for larger changes.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

Copy link
Contributor

@chiacyu chiacyu left a comment

Choose a reason for hiding this comment

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

Hi, @Claudenw
Thanks for the pr, the implementation of trie and bitmap is cool, left some comments, please take a look and tell me what'd you think. Thanks!

* Creates an empty tree.
*/
public Trie() {
clear();
Copy link
Contributor

Choose a reason for hiding this comment

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

* @throws IndexOutOfBoundsException if bitIndex specifies a bit not in the range being tracked.
*/
public static boolean contains(final int[] bitMaps, final int bitIndex) {
return (bitMaps[getIntIndex(bitIndex)] & getIntBit(bitIndex)) != 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove the != 0 but still remains the logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should check whether the index is out of range or not.

Copy link
Author

Choose a reason for hiding this comment

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

The Bitmap checks are performed on every ACL in the Trie during some operations. While it may make sense to add range checks on a general case library, this is that that. This is a specific case where we know the values of the indexes before we start and where we want to reduce the overhead as much as possible.

* @param numberOfBits the number of bits to store in the array of bit maps.
* @return the number of bit maps necessary.
*/
public static int numberOfBitMaps(final int numberOfBits) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add some conditional check to avoid numberOfBits is a negative value?

Copy link
Author

Choose a reason for hiding this comment

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

The Bitmap checks are performed on every ACL in the Trie during some operations. While it may make sense to add range checks on a general case library, this is that that. This is a specific case where we know the values of the indexes before we start and where we want to reduce the overhead as much as possible.

* @throws IndexOutOfBoundsException if bitIndex specifies a bit not in the range being tracked.
*/
public static void set(final int[] bitMaps, final int bitIndex) {
bitMaps[getIntIndex(bitIndex)] |= getIntBit(bitIndex);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should check whether the index is out of range or not.

Copy link
Author

Choose a reason for hiding this comment

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

The Bitmap checks are performed on every ACL in the Trie during some operations. While it may make sense to add range checks on a general case library, this is that that. This is a specific case where we know the values of the indexes before we start and where we want to reduce the overhead as much as possible.

* @throws IndexOutOfBoundsException if bitIndex specifies a bit not in the range being tracked.
*/
public static boolean contains(final int bitMap, final int bitIndex) {
return (bitMap & getIntBit(bitIndex)) != 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should check whether the index is out of range or not.

Copy link
Author

Choose a reason for hiding this comment

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

The Bitmap checks are performed on every ACL in the Trie during some operations. While it may make sense to add range checks on a general case library, this is that that. This is a specific case where we know the values of the indexes before we start and where we want to reduce the overhead as much as possible.

@@ -0,0 +1,70 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe change the filename to PackageInfo.java and also what's the purpose of this file?

Copy link
Author

Choose a reason for hiding this comment

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

This file is used by the javadoc process to create package information. The name is hard coded into the javadoc tool.

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