RocketMQ 存儲文件

磁盤存儲文件

-rw-r--r-- 1 root root    0 Jan 18 11:54 abort
-rw-r--r-- 1 root root 4.0K Mar 14 17:39 checkpoint
drwxr-xr-x 2 root root   34 Feb 14 14:33 commitlog
drwxr-xr-x 2 root root  280 Mar 14 17:40 config
drwxr-xr-x 7 root root  138 Feb 20 10:28 consumequeue
drwxr-xr-x 2 root root   31 Feb 20 10:18 index
-rw-r--r-- 1 root root    4 Feb 20 10:18 lock

abort:RocketMQ 啓動時生成,正常關閉時刪除,若是啓動時存在該文件,表明 RocketMQ 被異常關閉
checkpoint:文件檢查點,存儲 commitlog 、consumequeue、indexfile 最後一次刷盤時間或時間戳
index:消息索引文件存儲目錄
consumequeue:消息消費隊列存儲目錄
commitlog:消息存儲目錄
config:運行時的配置信息,包含主席消息過濾信息、集羣消費模式消息消費進度、延遲消息隊列拉取進度、消息消費組配置信息、topic配置屬性等

CommitLog 文件

drwxr-xr-x 2 root root   34 Feb 14 14:33 .
drwxr-xr-x 6 root root  113 Feb 14 13:59 ..
-rw-r--r-- 1 root root 1.0G Mar 14 17:48 00000000000000000000
-rw-r--r-- 1 root root 1.0G Mar 19 21:33 00000000006000000000

文件名爲 20 位數字組織,以該文件第一條消息的偏移量爲文件名,長度不足 20 的在前面補 0。文件默認大小爲 1G,可根據 mappedFileSizeCommitLog 屬性改變文件大小。app

存儲全部消息內容,寫滿一個文件後生成新的 commitlog 文件。全部 topic 的數據存儲在一塊兒,邏輯視圖以下:佈局

clipboard.png

ConsumeQueue 文件

RocketMQ 基於主題的訂閱模式實現消息消費,因爲同一主題的消息不連續的存儲在 CommitLog 文件中,遍歷 CommitLog 文件會致使效率很是低下,爲了適應消息消費的檢索需求,設計了消息消費隊列文件。一個 ConsumeQueue 文件能夠做爲檢索指定 topic 的消息索引。spa

[root@xxxx consumequeue]# tree -L 3
|-- smsCallbackReply
|   |-- 0
|   |   `-- 00000000000000000000
|   |-- 1
|   |   `-- 00000000000000000000
|   |-- 2
|   |   `-- 00000000000000000000
|   `-- 3
|       `-- 00000000000000000000
|-- smsCallbackStatus
|   |-- 0
|   |   |-- 00000000000000000000
|   |   `-- 00000000000006000000
|   |-- 1
|   |   |-- 00000000000000000000
|   |   `-- 00000000000006000000
|   |-- 2
|   |   |-- 00000000000000000000
|   |   `-- 00000000000006000000
|   `-- 3
|       |-- 00000000000000000000
|       `-- 00000000000006000000

ConsumeQueue 文件存儲消息的邏輯偏移量,而不存儲消息的所有內容,存儲格式以下:設計

clipboard.png

Index 索引文件

RocketMQ 引入了 Hash 索引機制爲消息創建索引,對 CommitLog 進行數據索引。索引文件佈局以下:code

clipboard.png

IndexHead 數據:
beginTimestamp:該索引文件包含消息的最小存儲時間
endTimestamp:該索引文件包含消息的最大存儲時間
beginPhyoffset:該索引文件中包含消息的最小物理偏移量(commitlog 文件偏移量)
endPhyoffset:該索引文件中包含消息的最大物理偏移量(commitlog 文件偏移量)
hashSlotCount:hashslot個數,並非 hash 槽使用的個數,在這裏意義不大,
indexCount:已使用的 Index 條目個數

Hash 槽:
一個 IndexFile 默認包含 500W 個 Hash 槽,每一個 Hash 槽存儲的是落在該 Hash 槽的 hashcode 最新的 Index 的索引

Index 條目列表
hashcode:key 的 hashcode
phyoffset:消息對應的物理偏移量
timedif:該消息存儲時間與第一條消息的時間戳的差值,小於 0 表示該消息無效
preIndexNo:該條目的前一條記錄的 Index 索引,hash 衝突時,根據該值構建鏈表結構

Checkpoint 文件

記錄 CommitLog,ConsumeQueue,IndexFile 的刷盤時間點,文件固定長度爲 4k,其中只用該文件的前 24個字節,存儲格式以下:索引

clipboard.png

相關文章
相關標籤/搜索