athanatos commented on a change in pull request #1931: (WIP)
GetListOfEntriesOfLedger implementation
URL: https://github.com/apache/bookkeeper/pull/1931#discussion_r253229693
##########
File path:
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/InterleavedLedgerStorage.java
##########
@@ -641,4 +649,233 @@ public void onRotateEntryLog() {
public List<GarbageCollectionStatus> getGarbageCollectionStatus() {
return
Collections.singletonList(gcThread.getGarbageCollectionStatus());
}
+
+ @Override
+ public byte[] getEntriesOfLedger(long ledgerId) throws Exception {
+ return getEntriesOfLedger(ledgerId, Collections.emptyIterator());
+ }
+
+ public static final long INVALID_ENTRYID = -1;
+
+ /*
+ *
+ * Nomenclature:
+ *
+ * - Continuous entries are grouped as a ’Sequence’. - Number of continuous
+ * entries in a ‘Sequence’ is called ‘sequenceSize’. - Gap between
+ * Consecutive sequences is called ‘sequencePeriod’. - Consecutive
sequences
+ * with same sequenceSize and same sequencePeriod in between consecutive
+ * sequences are grouped as a SequenceGroup. - ‘firstSequenceStart’ is the
+ * first entry in the first sequence of the SequenceGroup. -
+ * ‘lastSequenceStart’ is the first entry in the last sequence of the
+ * SequenceGroup.
+ *
+ * To represent a SequenceGroup, two long values and two int values are
+ * needed, so each SequenceGroup can be represented with (2 * 8 + 2 * 4 =
24
+ * bytes).
+ */
+ private static class SequenceGroup {
+ private final long firstSequenceStart;
+ private int sequenceSize;
+ long lastSequenceStart = INVALID_ENTRYID;
+ int sequencePeriod;
+ static final int SEQUENCEGROUP_BYTES = 2 * Long.BYTES + 2 *
Integer.BYTES;
+
+ private SequenceGroup(long firstSequenceStart, int sequenceSize) {
+ this.firstSequenceStart = firstSequenceStart;
+ this.sequenceSize = sequenceSize;
+ }
+
+ void serializeSequenceGroup(byte[] byteArrayForSerialization) {
+ ByteBuffer buffer = ByteBuffer.wrap(byteArrayForSerialization);
+ buffer.putLong(firstSequenceStart);
+ buffer.putLong(lastSequenceStart);
+ buffer.putLong(sequenceSize);
+ buffer.putLong(sequencePeriod);
+ }
+ }
+
+ /*
+ * Ordered collection of SequenceGroups will represent entries of the
ledger
+ * residing in a bookie.
+ *
+ * In the byte array representation of AvailabilityOfEntriesOfLedger, for
+ * the sake of future extensibility it would be helpful to have reserved
+ * space for header at the beginning. So the first 64 bytes will be used
for
+ * header, with the first four bytes specifying the int version number,
next
+ * four bytes specifying the number of sequencegroups for now and the rest
+ * of the bytes in the reserved space will be 0's. The encoded format will
+ * be represented after the first 64 bytes. The ordered collection of
+ * SequenceGroups will be appended sequentially to this byte array, with
+ * each SequenceGroup taking 24 bytes.
+ */
+ static class AvailabilityOfEntriesOfLedger {
Review comment:
Call this something more general -- LedgerEntrySet or something.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services