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

Fix parseSeq incorrectly parsing negative sequence number #65

Merged
merged 2 commits into from
Feb 9, 2022

Conversation

colinmcintosh
Copy link

@colinmcintosh colinmcintosh commented Sep 2, 2021

This PR includes a change to the parseSeq function used by the lock to parse sequence numbers. When the Zookeeper sequence number rolls over it rolls to -2147483647 rather than 0. parseSeq splits on a "-" symbol so when the path is split into parts the negative symbol is stripped away incorrectly. I changed this to split on the full prefix of "lock-" instead which saves the negative symbol. A test for this is included.

@pmazzini
Copy link

pmazzini commented Sep 2, 2021

From the ZK docs:

the counter used to store the next sequence number is a signed int (4bytes) maintained by the parent node, the counter will overflow when incremented beyond 2147483647 (resulting in a name "< path >-2147483647").

@codecov
Copy link

codecov bot commented Sep 2, 2021

Codecov Report

Merging #65 (c1e98b7) into master (8866d76) will increase coverage by 1.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #65      +/-   ##
==========================================
+ Coverage   75.27%   76.28%   +1.00%     
==========================================
  Files           7        7              
  Lines        1189     1189              
==========================================
+ Hits          895      907      +12     
+ Misses        202      193       -9     
+ Partials       92       89       -3     
Impacted Files Coverage Δ
lock.go 63.38% <100.00%> (ø)
conn.go 73.46% <0.00%> (+1.88%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8866d76...c1e98b7. Read the comment docs.

pmazzini
pmazzini previously approved these changes Sep 2, 2021
Copy link

@pmazzini pmazzini left a comment

Choose a reason for hiding this comment

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

lgtm

@colinmcintosh
Copy link
Author

Thanks for that link to the ZK docs @pmazzini! After I encountered this I searched for details in the docs but hadn't come across that paragraph.

@nemith
Copy link

nemith commented Sep 2, 2021

Another option would just do a SplitN(..., 1) to only split on the first -

@colinmcintosh
Copy link
Author

I think SplitN wouldn't work for the lock paths because CreateProtectedEphemeralSequential adds a "-" to beginning of the lock node path. I think it would probably also encounter an issue if a "-" is present in the parent path which also gets passed to parseSeq.

@pmazzini pmazzini dismissed their stale review September 3, 2021 04:01

re request review

@pmazzini
Copy link

pmazzini commented Sep 3, 2021

What I am confused about is that the Java implementation does not look to be checking negative numbers:
https://github.com/apache/zookeeper/blob/master/zookeeper-recipes/zookeeper-recipes-lock/src/main/java/org/apache/zookeeper/recipes/lock/ZNodeName.java#L54

@colinmcintosh
Copy link
Author

Interesting, that does seem to be a bug in the Java implementation as well. I've open an issue in the Apache JIRA regarding that: https://issues.apache.org/jira/browse/ZOOKEEPER-4372

@colinmcintosh
Copy link
Author

I submitted a PR for the Java implementation as well: apache/zookeeper#1751

@nemith
Copy link

nemith commented Sep 9, 2021

Seems good to me, @pmazzini any thoughts or good to merge?

@pmazzini
Copy link

Looks good to me

@colinmcintosh
Copy link
Author

Hi, just wanted to see if we could get this merged in as it sounds like there were no major concerns with this PR. Thanks!

@nemith nemith merged commit 21b4929 into go-zookeeper:master Feb 9, 2022
@colinmcintosh colinmcintosh deleted the cm/fix-lock-seq branch February 9, 2022 18:56
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