djsweet opened a new issue, #4895:
URL: https://github.com/apache/bookkeeper/issues/4895
**BUG REPORT**
***Describe the bug***
`EntryMemTable.getLastEntry` reports an incorrect last entry if ledger
metadata is being used.
This is caused by a long overflow in `KeyComparator`: if any ledger metadata
is present within the `EntryMemTable` (with a negative entry ID), then the
`Long.MAX_VALUE` passed in through `getLastEntry` causes a comparison
subtraction to overflow.
***To Reproduce***
The following unit test, added to EntryMemTableTest, will fail.
```java
public void testFindingLastEntryWithMetadata() throws IOException {
final long testLedgerCount = 8 * 1024;
final byte[] payload = new byte[0];
for (long i = 0; i < testLedgerCount; i++) {
memTable.addEntry(i, BookieImpl.METAENTRY_ID_LEDGER_KEY,
ByteBuffer.wrap(payload), this);
memTable.addEntry(i, 0, ByteBuffer.wrap(payload), this);
}
for (long i = 0; i < testLedgerCount; i++) {
final EntryKeyValue ekv = memTable.getLastEntry(i);
assertNotNull(String.format("Null entry for ledger %d", i), ekv);
assertEquals(String.format("Wrong ledger ID at ledger %d", i), i,
ekv.getLedgerId());
assertEquals(String.format("Wrong last entry ID at ledger %d", i),
0, ekv.getEntryId());
}
}
```
This test will fail with the message "Null entry for ledger 0".
***Expected behavior***
The posted test should pass: having ledger metadata present in the
`EntryMemTable` should preserve expected ordering semantics within the table.
***Additional context***
This method is used in SortedLedgerStorage, for determining whether the
ledger exists before the entry has been flushed into InterleavedLedgerStorage,
and for retrieving the LastAddConfirmed entry if requested by the Bookie
protocol. This bug results in incorrectly reporting that ledgers do not exist,
and incorrectly reporting the LastAddConfirmed entry, when SortedLedgerStorage
is in use.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]