Repository navigation
Fix OptionUtil.prefixEndOf carry handling for keys ending in 0xFF - #674
Open
amalsaidov wants to merge 1 commit into
Open
amalsaidov wants to merge 1 commit into
amalsaidov wants to merge 1 commit into
Conversation
prefixEndOf computes the exclusive end of an etcd range query by incrementing the key. It only incremented the last byte, so a key whose last byte is 0xFF wrapped to 0x00 and produced an end key that is lexicographically smaller than the prefix. The resulting range is empty, which breaks prefix watches and child lookups for such keys. Walk the key from the end, increment the first byte that is not 0xFF and drop the trailing 0xFF bytes, matching the standard etcd prefix range semantics. When every byte is 0xFF there is no greater key, so return the NO_PREFIX_END marker to range over the rest of the keyspace. The previous loop that this replaced used a signed `endKey[i] < 0xff` check that was always true; comparing the unsigned value fixes that. Add OptionUtilTest covering the ASCII, trailing-0xFF, all-0xFF and empty cases, and that the input is not mutated. Fixes apache#80 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
OptionUtil.prefixEndOfbuilds the exclusive end key of an etcd range query (used for prefix watches and child lookups in the etcd3 remoting). The current implementation only increments the last byte:When the last byte is
0xFF, incrementing wraps it to0x00. The returned end key is then lexicographically smaller than the prefix itself, so the range[prefix, end)is empty and the watch/lookup silently returns nothing for keys that end in0xFF.This is the problem reported in #80. The original loop there used
endKey[i] < 0xff, which is always true for a signedbyte(max value127<255), so the carry was never handled.The fix
Walk the key from the end, increment the first byte that is not
0xFF, and drop the trailing0xFFbytes, which is the standard etcd prefix-range semantics (same as jetcd's ownOptionUtil). Comparing the unsigned value(endKey[i] & 0xff) < 0xffmakes the check correct. When every byte is0xFFthere is no greater key, so it returns the existingNO_PREFIX_ENDmarker to range over the rest of the keyspace. The empty-prefix guard added in #669 is preserved (an empty key has no non-0xFFbyte, so it falls through toNO_PREFIX_END).Tested
Added
OptionUtilTestcovering:"a"->"b", last byte of a multi-byte key)0xFFcarrying to the previous byte and being dropped0xFFbytes0xFFand empty prefixes returningNO_PREFIX_ENDByteSequencenot being mutated./mvnw -pl dubbo-remoting-extensions/dubbo-remoting-etcd3 -am test -DskipIntegrationTests=false->Tests run: 7, Failures: 0, Errors: 0. The three trailing-0xFFcases fail against the current code and pass with this change. The existing etcd integration tests stay@Disabledas before.Fixes #80
This change was written with the help of Claude Code and directed, reviewed and tested by a human contributor.
🤖 Generated with Claude Code