[ISSUE #6406] Add more visual comments on IndexFile & IndexHeader & ConsumeQueue

1. add more visual comments
This commit is contained in:
TheR1sing3un
2023-03-21 08:42:40 +08:00
committed by GitHub
parent 38ce7c891d
commit d75ab111f3
3 changed files with 39 additions and 0 deletions
@@ -43,6 +43,19 @@ import org.apache.rocketmq.store.queue.ReferredIterator;
public class ConsumeQueue implements ConsumeQueueInterface, FileQueueLifeCycle {
private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME);
/**
* ConsumeQueue's store unit. Format:
* <pre>
* ┌───────────────────────────────┬───────────────────┬───────────────────────────────┐
* │ CommitLog Physical Offset │ Body Size │ Tag HashCode │
* │ (8 Bytes) │ (4 Bytes) │ (8 Bytes) │
* ├───────────────────────────────┴───────────────────┴───────────────────────────────┤
* │ Store Unit │
* │ │
* </pre>
* ConsumeQueue's store unit. Size:
* CommitLog Physical Offset(8) + Body Size(4) + Tag HashCode(8) = 20 Bytes
*/
public static final int CQ_STORE_UNIT_SIZE = 20;
public static final int MSG_TAG_OFFSET_INDEX = 12;
private static final Logger LOG_ERROR = LoggerFactory.getLogger(LoggerName.STORE_ERROR_LOGGER_NAME);
@@ -30,6 +30,19 @@ import org.apache.rocketmq.store.logfile.MappedFile;
public class IndexFile {
private static final Logger log = LoggerFactory.getLogger(LoggerName.STORE_LOGGER_NAME);
private static int hashSlotSize = 4;
/**
* Each index's store unit. Format:
* <pre>
* ┌───────────────┬───────────────────────────────┬───────────────┬───────────────┐
* │ Key HashCode │ Physical Offset │ Time Diff │ Next Index Pos│
* │ (4 Bytes) │ (8 Bytes) │ (4 Bytes) │ (4 Bytes) │
* ├───────────────┴───────────────────────────────┴───────────────┴───────────────┤
* │ Index Store Unit │
* │ │
* </pre>
* Each index's store unit. Size:
* Key HashCode(4) + Physical Offset(8) + Time Diff(4) + Next Index Pos(4) = 20 Bytes
*/
private static int indexSize = 20;
private static int invalidIndex = 0;
private final int hashSlotNum;
@@ -20,6 +20,19 @@ import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
/**
* Index File Header. Format:
* <pre>
* ┌───────────────────────────────┬───────────────────────────────┬───────────────────────────────┬───────────────────────────────┬───────────────────┬───────────────────┐
* │ Begin Timestamp │ End Timestamp │ Begin Physical Offset │ End Physical Offset │ Hash Slot Count │ Index Count │
* │ (8 Bytes) │ (8 Bytes) │ (8 Bytes) │ (8 Bytes) │ (4 Bytes) │ (4 Bytes) │
* ├───────────────────────────────┴───────────────────────────────┴───────────────────────────────┴───────────────────────────────┴───────────────────┴───────────────────┤
* │ Index File Header │
* │
* </pre>
* Index File Header. Size:
* Begin Timestamp(8) + End Timestamp(8) + Begin Physical Offset(8) + End Physical Offset(8) + Hash Slot Count(4) + Index Count(4) = 40 Bytes
*/
public class IndexHeader {
public static final int INDEX_HEADER_SIZE = 40;
private static int beginTimestampIndex = 0;