-
Notifications
You must be signed in to change notification settings - Fork 11
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
Optimize paginated getChildren #8
Optimize paginated getChildren #8
Conversation
5b799eb
to
7fc3e33
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed first part. Will review the later ones.
zookeeper-server/src/main/java/org/apache/zookeeper/PaginationNextPage.java
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/PaginationNextPage.java
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/ChildrenBatchIterator.java
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/PaginationNextPage.java
Show resolved
Hide resolved
1aa85ac
to
4ac2e1a
Compare
37adb17
to
60d5e51
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no test. And I think some of the business logic has not been completed yet. Please comment if I missed anything.
Please add enough tests to cover the new logic.
zookeeper-server/src/main/java/org/apache/zookeeper/PaginationNextPage.java
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/PaginationNextPage.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/server/DataTree.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/server/FinalRequestProcessor.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to split the PR into smaller ones. Since the logic on client and server in the original patch is not independent, I can not split the changes and make the tests pass. So I decided to put all the changes in one PR that we could review the logic.
zookeeper-server/src/main/java/org/apache/zookeeper/PaginationNextPage.java
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/PaginationNextPage.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/server/FinalRequestProcessor.java
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/server/DataTree.java
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/server/DataTree.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that I click Approve by mistake...
zookeeper-server/src/main/java/org/apache/zookeeper/ChildrenBatchIterator.java
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/PaginationNextPage.java
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/PaginationNextPage.java
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/server/DataTree.java
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/server/DataTree.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
Outdated
Show resolved
Hide resolved
zookeeper-server/src/main/java/org/apache/zookeeper/ZooKeeper.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we add a todo to have a test for the the case that I raised as a followup, namely not clearing the hash set having may miss some data?
If we want to add a unit test, we have to mock the required states for the API to simulate the read/write race condition. It'll take some time for me to complete the test. Since the logic is carefully reviewed and manually tested, I will merge the code first and create an issue (#9) for adding the unit test later. |
The optimizes the paginated getChildren API to satisfy use cases better. The changes include: - On zk server, uses a formulate to pre-calculate the children's packet length when adding the children to the returning list, so the children packet is ensured within the jute.maxbuffer limit. - Adds an API getAllChildrenPaginated to fetch all children by leveraging the paginated getChildren API. - Optimize the sorting logic for paginated getChildren in DataTree: only when pagination is needed, children are sorted. 99% of the case for returning all children, the children could be returned in the 1st page. No need to sort them to avoid performance downgrade. - Returning a list of child name string for the API, instead of a list of PathWithStat - Add more tests to cover the new logic
The optimizes the paginated getChildren API to satisfy use cases better. The changes include: - On zk server, uses a formulate to pre-calculate the children's packet length when adding the children to the returning list, so the children packet is ensured within the jute.maxbuffer limit. - Adds an API getAllChildrenPaginated to fetch all children by leveraging the paginated getChildren API. - Optimize the sorting logic for paginated getChildren in DataTree: only when pagination is needed, children are sorted. 99% of the case for returning all children, the children could be returned in the 1st page. No need to sort them to avoid performance downgrade. - Returning a list of child name string for the API, instead of a list of PathWithStat - Add more tests to cover the new logic
Description
Resolves #7
Changes for the PR:
jute.maxbuffer
limit. Formula:totalLength = (CHILD_EXTRA_BYTES + childLength) * numChildren + BASE_BYTES
. As an example and tested in zk 3.6.x, the formula is like:total packet length = (4 + childNameLength) * numChildren + 100
maxReturned == MAX_INT, minCzxid == -1
. The pagination requests will be handled in the getChildren API, until there is no more page of children left.DataTree
: only when pagination is needed, children are sorted. 99% of the case for returning all children, the children could be returned in the 1st page. No need to sort them to avoid performance downgrade.PathWithStat
.Run Test
zookeeper-server