This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new 4eec3ce Index for lockarray should be non-negative
4eec3ce is described below
commit 4eec3ce0f3dcd16b5ff84f14a95f9acc1d78e552
Author: cguttapalem <[email protected]>
AuthorDate: Tue Aug 21 15:11:10 2018 -0700
Index for lockarray should be non-negative
Descriptions of the changes in this PR:
Make sure lockIndex is non-negative.
Author: cguttapalem <[email protected]>
Reviewers: Enrico Olivelli <[email protected]>, Sijie Guo
<[email protected]>
This closes #1616 from reddycharan/modfix
---
.../EntryLogManagerForEntryLogPerLedger.java | 3 +-
.../org/apache/bookkeeper/bookie/EntryLogTest.java | 46 ++++++++++++++++++++++
2 files changed, 48 insertions(+), 1 deletion(-)
diff --git
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogManagerForEntryLogPerLedger.java
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogManagerForEntryLogPerLedger.java
index 452e996..39ed60c 100644
---
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogManagerForEntryLogPerLedger.java
+++
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/EntryLogManagerForEntryLogPerLedger.java
@@ -62,6 +62,7 @@ import org.apache.bookkeeper.stats.Counter;
import org.apache.bookkeeper.stats.OpStatsLogger;
import org.apache.bookkeeper.stats.StatsLogger;
import org.apache.bookkeeper.util.IOUtils;
+import org.apache.bookkeeper.util.MathUtils;
import org.apache.bookkeeper.util.collections.ConcurrentLongHashMap;
import org.apache.commons.lang3.mutable.MutableInt;
@@ -94,7 +95,7 @@ class EntryLogManagerForEntryLogPerLedger extends
EntryLogManagerBase {
private BufferedLogChannelWithDirInfo entryLogWithDirInfo;
private EntryLogAndLockTuple(long ledgerId) {
- int lockIndex = Long.hashCode(ledgerId) % lockArrayPool.length();
+ int lockIndex = MathUtils.signSafeMod(Long.hashCode(ledgerId),
lockArrayPool.length());
if (lockArrayPool.get(lockIndex) == null) {
lockArrayPool.compareAndSet(lockIndex, null, new
ReentrantLock());
}
diff --git
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/EntryLogTest.java
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/EntryLogTest.java
index 4b52a09..9694fae 100644
---
a/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/EntryLogTest.java
+++
b/bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/EntryLogTest.java
@@ -1098,6 +1098,52 @@ public class EntryLogTest {
}
}
+ @Test
+ public void testLongLedgerIdsWithEntryLogPerLedger() throws Exception {
+ ServerConfiguration conf =
TestBKConfiguration.newServerConfiguration();
+ conf.setEntryLogFilePreAllocationEnabled(true);
+ conf.setEntryLogPerLedgerEnabled(true);
+ conf.setLedgerDirNames(createAndGetLedgerDirs(1));
+ conf.setLedgerStorageClass(InterleavedLedgerStorage.class.getName());
+
+ LedgerDirsManager ledgerDirsManager = new LedgerDirsManager(conf,
conf.getLedgerDirs(),
+ new DiskChecker(conf.getDiskUsageThreshold(),
conf.getDiskUsageWarnThreshold()));
+
+ EntryLogger entryLogger = new EntryLogger(conf, ledgerDirsManager);
+ EntryLogManagerForEntryLogPerLedger entryLogManager =
(EntryLogManagerForEntryLogPerLedger) entryLogger
+ .getEntryLogManager();
+
+ int numOfLedgers = 5;
+ int numOfEntries = 4;
+ long[][] pos = new long[numOfLedgers][numOfEntries];
+ for (int i = 0; i < numOfLedgers; i++) {
+ long ledgerId = Long.MAX_VALUE - i;
+ entryLogManager.createNewLog(ledgerId);
+ for (int entryId = 0; entryId < numOfEntries; entryId++) {
+ pos[i][entryId] = entryLogger.addEntry(ledgerId,
generateEntry(ledgerId, entryId).nioBuffer());
+ }
+ }
+ /*
+ * do checkpoint to make sure entrylog files are persisted
+ */
+ entryLogger.checkpoint();
+
+ for (int i = 0; i < numOfLedgers; i++) {
+ long ledgerId = Long.MAX_VALUE - i;
+ for (int entryId = 0; entryId < numOfEntries; entryId++) {
+ String expectedValue = generateDataString(ledgerId, entryId);
+ ByteBuf buf = entryLogger.readEntry(ledgerId, entryId,
pos[i][entryId]);
+ long readLedgerId = buf.readLong();
+ long readEntryId = buf.readLong();
+ byte[] readData = new byte[buf.readableBytes()];
+ buf.readBytes(readData);
+ assertEquals("LedgerId ", ledgerId, readLedgerId);
+ assertEquals("EntryId ", entryId, readEntryId);
+ assertEquals("Entry Data ", expectedValue, new
String(readData));
+ }
+ }
+ }
+
/*
* when entrylog for ledger is removed from ledgerIdEntryLogMap, then
* ledgermap should be appended to that entrylog, before moving that