Skip to content

Commit

Permalink
Fix NoSuchElementException when rereplicate empty ledgers (#4039)
Browse files Browse the repository at this point in the history
### Motivation
Master issue: #4036 

### Changes
Set the `numberOfEntriesToReplicate` to 0 when ledger is empty
  • Loading branch information
chenhongSZ authored Sep 20, 2023
1 parent abb5981 commit 95320f4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ static Set<LedgerFragment> splitIntoSubFragments(LedgerHandle lh,
assert false;
}

long numberOfEntriesToReplicate = (lastEntryId - firstEntryId) + 1;
long numberOfEntriesToReplicate = firstEntryId == INVALID_ENTRY_ID ? 0 : (lastEntryId - firstEntryId) + 1;
long splitsWithFullEntries = numberOfEntriesToReplicate
/ rereplicationEntryBatchSize;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ public void testSplitIntoSubFragmentsWithDifferentFragmentBoundaries()
testSplitIntoSubFragments(22, 103, 11, 8, lh);
testSplitIntoSubFragments(49, 51, 1, 3, lh);
testSplitIntoSubFragments(11, 101, 3, 31, lh);
testSplitIntoSubFragments(0, -1, 1, 1, lh);
testSplitIntoSubFragments(0, -1, 10, 1, lh);
}

/**
Expand All @@ -272,17 +274,7 @@ void testSplitIntoSubFragments(final long oriFragmentFirstEntry,
final long oriFragmentLastEntry, long entriesPerSubFragment,
long expectedSubFragments, LedgerHandle lh) {
LedgerFragment fr = new LedgerFragment(lh, oriFragmentFirstEntry,
oriFragmentLastEntry, Sets.newHashSet(0)) {
@Override
public long getLastStoredEntryId() {
return oriFragmentLastEntry;
}

@Override
public long getFirstStoredEntryId() {
return oriFragmentFirstEntry;
}
};
oriFragmentLastEntry, Sets.newHashSet(0));
Set<LedgerFragment> subFragments = LedgerFragmentReplicator
.splitIntoSubFragments(lh, fr, entriesPerSubFragment);
assertEquals(expectedSubFragments, subFragments.size());
Expand Down

0 comments on commit 95320f4

Please sign in to comment.