You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/08/21 00:01:32 UTC

[GitHub] merlimat commented on a change in pull request #1616: Index for lockarray should be non-negative

merlimat commented on a change in pull request #1616: Index for lockarray should be non-negative
URL: https://github.com/apache/bookkeeper/pull/1616#discussion_r211443783
 
 

 ##########
 File path: bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogManagerForEntryLogPerLedger.java
 ##########
 @@ -93,7 +93,7 @@ BufferedLogChannel getLogChannel() {
         private BufferedLogChannelWithDirInfo entryLogWithDirInfo;
 
         private EntryLogAndLockTuple(long ledgerId) {
-            int lockIndex = Long.hashCode(ledgerId) % lockArrayPool.length();
+            int lockIndex = Math.abs(Long.hashCode(ledgerId) % lockArrayPool.length());
 
 Review comment:
   If `hashCode()` returns a negative, the modulo operation will fail anyway. I think we should use `MathUtils.signSafeMod()` here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services