In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "RocketMQ DLedger multi-copy storage implementation method", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "RocketMQ DLedger multi-copy storage implementation method"!
The idea of storage implementation of RocketMQ DLedger is similar to that of RocketMQ. This paper no longer analyzes its implementation in detail from the point of view of source code, but only points out the key points of its implementation. We might as well briefly review the design ideas of CommitLog files and ConsumeQueue files.
The form of the document is as follows:
As shown in the figure above, multiple commitlog files form a logically contiguous file, represented by MappedFileQueue, and a single commitlog file is represented by MappedFile.
Warm Tip: if you want to learn more about RocketMQ's explanation on storage, you can pay attention to the author's book "inside RocketMQ Technology".
1. DLedger storage related class diagram
1.1 DLedgerStore
Store abstract classes and define the following core methods:
Public abstract DLedgerEntry appendAsLeader (DLedgerEntry entry)
Append logs (data) to the primary node.
Public abstract DLedgerEntry appendAsFollower (DLedgerEntry entry, long leaderTerm, String leaderId)
Synchronize the log to the slave node.
Public abstract DLedgerEntry get (Long index)
Find the log according to the log subscript.
Public abstract long getCommittedIndex ()
Gets the submitted subscript.
Public abstract long getLedgerEndTerm ()
Gets the current largest voting round of Leader.
Public abstract long getLedgerEndIndex ()
Gets the subscript written to the next log of Leader.
Public abstract long getLedgerBeginIndex ()
Gets the subscript of the first message in Leader.
Public void updateCommittedIndex (long term, long committedIndex)
Update the value of commitedIndex, which is an empty implementation, implemented by a specific storage subclass.
Protected void updateLedgerEndIndexAndTerm ()
Update ledgerEndIndex and ledgerEndTerm maintained by Leader.
Public void flush ()
Brush write, empty method, implemented by specific subclasses.
Public long truncate (DLedgerEntry entry, long leaderTerm, String leaderId)
Delete logs, empty methods, implemented by specific subclasses.
Public void startup ()
Start the storage manager, empty method, implemented by a specific subclass.
Public void shutdown ()
Close the storage manager, empty methods, implemented by specific subclasses.
1.2 DLedgerMemoryStore
Dledger is based on memory-based log storage.
1.3 DLedgerMmapFileStore
Storage implementation based on file memory mapping mechanism. Its core attributes are as follows:
Long ledgerBeginIndex =-1
The starting index of the log, which defaults to-1.
L-ong ledgerEndIndex =-1
The next log subscript defaults to-1.
Long committedIndex =-1
Committed log index.
Long ledgerEndTerm
The current largest voting round.
DLedgerConfig dLedgerConfig
Configuration information for DLedger.
MemberState memberState
State machine.
MmapFileList dataFileList
Memory-mapped Queue for log files (data files).
MmapFileList indexFileList
A collection of memory-mapped files for index files. (RocketMQ MappedFIleQueue can be calibrated).
ThreadLocal
< ByteBuffer>LocalIndexBuffer
Local thread variable, which is used to cache the index ByteBuffer.
ThreadLocal
< ByteBuffer>LocalEntryBuffer
Local thread variable, which is used to cache the data index ByteBuffer.
FlushDataService flushDataService
Data file refresh thread.
CleanSpaceService cleanSpaceService
Clears the expired log file thread.
Boolean isDiskFull = false
Whether the disk is full.
Long lastCheckPointTimeMs
Last detection point (timestamp).
AtomicBoolean hasLoaded
Whether it has been loaded or not is mainly used to avoid repeated loading (initialization) of log files.
AtomicBoolean hasRecovered
Whether it has been restored.
2. DLedger storage (benchmarking RocketMQ)
The storage part mainly includes storage mapping file, message storage format, flushing disk, file loading and file recovery, deletion of expired files, and so on. Since these contents have been described in detail in the RocketMQ storage section, the corresponding reference mappings are as follows:
MappedFile is used in RocketMQ to represent a physical file, while DefaultMmapFIle is used in DLedger to represent a physical file.
MappedFile is used to represent multiple physical files (logically contiguous) in RocketMQ, while MmapFileList is used in DLedger.
DefaultMessageStore is used to encapsulate storage logic in RocketMQ, while DLedgerMmapFileStore is used in DLedger to encapsulate storage logic.
In RocketMQ, the inner class FlushCommitLogService of Commitlog is used to realize the flushing of commitlog files, while in DLedger, the inner class FlushDataService of DLedgerMmapFileStore is used to realize the flushing of files.
The inner class CleanCommitlogService of DefaultMessageStore is used to delete commitlog expired files in RocketMQ, while DLedgerMmapFileStore$CleanSpaceService is used in DLedger.
Because its implementation principle is the same, the above part has been analyzed in detail in Chapter 4 of "RocketMQ Technology Insider", so I will not repeat the analysis here.
3. DLedger data storage format
The meaning of the storage format field is as follows:
Magic
Magic number, 4 bytes.
Size
The total length of the entry, including Header (protocol header) + message body, accounting for 4 bytes.
EntryIndex
The index of the current entry, accounting for 8 bytes.
EntryTerm
The voting round to which the current entry belongs, accounting for 8 bytes.
Pos
The physical offset of this entry, which is similar to the physical offset of the commitlog file, is 8 bytes.
Channel
Reserved field, unused in the current version, accounting for 4 bytes.
Chain crc
The current version is not in use, accounting for 4 bytes.
Body crc
The CRC checksum of body, which is used to distinguish whether the data is corrupted, accounting for 4 bytes.
Body size
Used to store the length of the body, accounting for 4 bytes.
Body
The content of the specific message.
Source code reference point: DLedgerMmapFileStore#recover, DLedgerEntry, DLedgerEntryCoder.
4. DLedger index storage format means that an index entry occupies 32 bytes. At this point, I believe that everyone on the "RocketMQ DLedger multi-copy storage implementation method" have a deeper understanding, might as well to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.