Skip to content

Commit 9c1acb5

Browse files
author
maxlisongsong
committed
IllegalArgumentException("inconsistent range") from ConcurrentSkipListMap
fix
1 parent f148f63 commit 9c1acb5

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

bookkeeper-server/src/main/java/org/apache/bookkeeper/replication/ReplicationWorker.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public class ReplicationWorker implements Runnable {
146146
private final Counter numNotAdheringPlacementLedgersReplicated;
147147
private final Map<String, Counter> exceptionCounters;
148148
final LoadingCache<Long, AtomicInteger> replicationFailedLedgers;
149+
@VisibleForTesting
149150
final LoadingCache<Long, ConcurrentSkipListSet<Long>> unableToReadEntriesForReplication;
150151

151152
/**
@@ -322,8 +323,7 @@ private void logBKExceptionAndReleaseLedger(BKException e, long ledgerIdToReplic
322323
.releaseUnderreplicatedLedger(ledgerIdToReplicate);
323324
getExceptionCounter(e.getClass().getSimpleName()).inc();
324325
}
325-
326-
private boolean tryReadingFaultyEntries(LedgerHandle lh, LedgerFragment ledgerFragment) {
326+
public boolean tryReadingFaultyEntries(LedgerHandle lh, LedgerFragment ledgerFragment) {
327327
long ledgerId = lh.getId();
328328
ConcurrentSkipListSet<Long> entriesUnableToReadForThisLedger = unableToReadEntriesForReplication
329329
.getIfPresent(ledgerId);
@@ -332,6 +332,9 @@ private boolean tryReadingFaultyEntries(LedgerHandle lh, LedgerFragment ledgerFr
332332
}
333333
long firstEntryIdOfFragment = ledgerFragment.getFirstEntryId();
334334
long lastEntryIdOfFragment = ledgerFragment.getLastKnownEntryId();
335+
if (firstEntryIdOfFragment > lastEntryIdOfFragment) {
336+
return true;
337+
}
335338
NavigableSet<Long> entriesOfThisFragmentUnableToRead = entriesUnableToReadForThisLedger
336339
.subSet(firstEntryIdOfFragment, true, lastEntryIdOfFragment, true);
337340
if (entriesOfThisFragmentUnableToRead.isEmpty()) {

bookkeeper-server/src/test/java/org/apache/bookkeeper/replication/TestReplicationWorker.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.net.URI;
3838
import java.net.UnknownHostException;
3939
import java.util.Enumeration;
40+
import java.util.HashSet;
4041
import java.util.List;
4142
import java.util.Map.Entry;
4243
import java.util.Objects;
@@ -57,6 +58,7 @@
5758
import org.apache.bookkeeper.client.ClientUtil;
5859
import org.apache.bookkeeper.client.EnsemblePlacementPolicy;
5960
import org.apache.bookkeeper.client.LedgerEntry;
61+
import org.apache.bookkeeper.client.LedgerFragment;
6062
import org.apache.bookkeeper.client.LedgerHandle;
6163
import org.apache.bookkeeper.client.RackawareEnsemblePlacementPolicy;
6264
import org.apache.bookkeeper.client.ZoneawareEnsemblePlacementPolicy;
@@ -1296,6 +1298,33 @@ public void testReplicationStats() throws Exception {
12961298
RackawareEnsemblePlacementPolicy.class, checkReplicationStats);
12971299
}
12981300

1301+
/**
1302+
* Test the tryReadingFaultyEntries function, where firstEntryId > lastKnownEntryId
1303+
* and unableToReadEntriesForReplication not empty, there is a IllegalArgumentException.
1304+
* java.lang.IllegalArgumentException: inconsistent range
1305+
*/
1306+
@Test
1307+
public void testTryReadingFaultyEntriesFromEmptyFragment() throws Exception {
1308+
LedgerHandle lh = bkc.createLedger(3, 3, BookKeeper.DigestType.CRC32,
1309+
TESTPASSWD);
1310+
1311+
HashSet<Integer> bookieIndexes = new HashSet<>();
1312+
bookieIndexes.add(0);
1313+
bookieIndexes.add(1);
1314+
bookieIndexes.add(2);
1315+
LedgerFragment fragment = new LedgerFragment(lh, 2, 1, bookieIndexes);
1316+
1317+
ReplicationWorker rw = new ReplicationWorker(baseConf);
1318+
rw.start();
1319+
rw.unableToReadEntriesForReplication.getUnchecked(lh.getId()).add(0L);
1320+
1321+
try {
1322+
rw.tryReadingFaultyEntries(lh, fragment);
1323+
} catch (IllegalArgumentException e) {
1324+
fail("should fail with exception: " + e);
1325+
}
1326+
}
1327+
12991328
private void testRepairedNotAdheringPlacementPolicyLedgerFragments(
13001329
Class<? extends EnsemblePlacementPolicy> placementPolicyClass,
13011330
BiConsumer<Boolean, ReplicationWorker> checkReplicationStats) throws Exception {

0 commit comments

Comments
 (0)