eolivelli commented on code in PR #4161:
URL: https://github.com/apache/bookkeeper/pull/4161#discussion_r1433807650
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/EntryLogScanner.java:
##########
@@ -27,6 +27,10 @@
* Scan entries in a entry log file.
*/
public interface EntryLogScanner {
+ public static final int READ_ALL = Integer.MAX_VALUE;
+ public static final int READ_NOTHING = 0;
+ public static final int READ_LEDGER_ENTRY_ID = 16;
Review Comment:
what about `READ_LEDGER_ENTRY_ID_LENGTH` ?
but as we basically expect only these 3 values we can use an "enum" and
ensure that the code is not called with other combinations (like negative
numbers or non sense numbers caused by bugs)
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/DefaultEntryLogger.java:
##########
@@ -1036,15 +1036,20 @@ public void scanEntryLog(long entryLogId,
EntryLogScanner scanner) throws IOExce
}
// read the entry
data.clear();
- data.capacity(entrySize);
- int rc = readFromLogChannel(entryLogId, bc, data, pos);
- if (rc != entrySize) {
- LOG.warn("Short read for ledger entry from entryLog {}@{}
({} != {})",
- entryLogId, pos, rc, entrySize);
- return;
+ int capacity = Math.min(scanner.getLengthToRead(), entrySize);
Review Comment:
if getLengthToRead returns READ_NOTHING then maybe "data" can be passed as
"null"
if getLengthToRead returns READ_LEDGER_ENTRY_ID then the caller is
interested only in the initial bytes.
Please consider changing the interface and have 3 different "process" methods
READ_NOTHING:
process(ledgerId, entrySize)
READ_LEDGER_ENTRY_ID;
process(ledgerId, entryId, entrySize)
in this case the entryId is extracted by this code and not by the code
downstream
READ_ALL
process(ledgerId, offset, data)
This way it is clearer what is happening, and the code is safer, as the
implementation of the interface doesn't need to understand the internal format
of the "data" buffer when it doesn't need it.
Using the enum (as suggested below) does not introduce extra costs at runtime
--
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]