You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
EntryMemTable.getLastEntry reports incorrect last entry when ledger metadata is present #4895
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.
publicvoidtestFindingLastEntryWithMetadata() throwsIOException {
finallongtestLedgerCount = 8 * 1024;
finalbyte[] payload = newbyte[0];
for (longi = 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 (longi = 0; i < testLedgerCount; i++) {
finalEntryKeyValueekv = 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.
Activity