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 22:11:20 UTC
[GitHub] sijie closed pull request #1616: Index for lockarray should be
non-negative
sijie closed pull request #1616: Index for lockarray should be non-negative
URL: https://github.com/apache/bookkeeper/pull/1616
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 452e99607c..39ed60cea5 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.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 @@ BufferedLogChannel getLogChannel() {
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 4b52a09b13..9694fae3e9 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 void testCacheMaximumSizeEvictionPolicy() throws Exception {
}
}
+ @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
----------------------------------------------------------------
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