欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

RocketMQ存儲(chǔ)中如何實(shí)現(xiàn)日志文件創(chuàng)建與映射

這篇文章將為大家詳細(xì)講解有關(guān)RocketMQ存儲(chǔ)中如何實(shí)現(xiàn)日志文件創(chuàng)建與映射,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。

成都創(chuàng)新互聯(lián)2013年開創(chuàng)至今,是專業(yè)互聯(lián)網(wǎng)技術(shù)服務(wù)公司,擁有項(xiàng)目成都網(wǎng)站建設(shè)、成都做網(wǎng)站網(wǎng)站策劃,項(xiàng)目實(shí)施與項(xiàng)目整合能力。我們以讓每一個(gè)夢(mèng)想脫穎而出為使命,1280元格爾木做網(wǎng)站,已為上家服務(wù),為格爾木各地企業(yè)和個(gè)人服務(wù),聯(lián)系電話:028-86922220

1.問(wèn)題描述

日志目錄(可配置)/data/rocketmq/store/commitlog會(huì)有20位長(zhǎng)度的日志文件。
1.日志文件什么時(shí)候創(chuàng)建的?
2.日志文件創(chuàng)建流程是什么?
3.日志文件和內(nèi)存映射是怎么樣的?

-rw-rw-r-- 1 baseuser baseuser 1073741824 Jun 27 22:50 00000117290188144640
-rw-rw-r-- 1 baseuser baseuser 1073741824 Jun 27 22:52 00000117291261886464
-rw-rw-r-- 1 baseuser baseuser 1073741824 Jun 27 22:54 00000117292335628288
-rw-rw-r-- 1 baseuser baseuser 1073741824 Jun 27 22:56 00000117293409370112
-rw-rw-r-- 1 baseuser baseuser 1073741824 Jun 27 22:57 00000117294483111936
-rw-rw-r-- 1 baseuser baseuser 1073741824 Jun 27 22:56 00000117295556853760
2.日志映射相關(guān)類初始化

在Broker啟動(dòng)時(shí)實(shí)例化了兩個(gè)類DefaultMessageStore和AllocateMappedFileService。
AllocateMappedFileService是線程類繼承了Runnable接口,該線程類持有DefaultMessageStore的引用(即:可操作管理DefaultMessageStore),并啟動(dòng)該線程類。
調(diào)用鏈

//Broker啟動(dòng)時(shí)調(diào)用
@1 BrokerStartup#main#createBrokerController()
boolean initResult = controller.initialize();
@2 Controller#initialize()
this.messageStore = new DefaultMessageStore(this.messageStoreConfig, this.brokerStatsManager, this.messageArrivingListener, this.brokerConfig);
@3 DefaultMessageStore#DefaultMessageStore()
//將DefaultMessageStore自身引用傳給AllocateMappedFileService
this.allocateMappedFileService = new AllocateMappedFileService(this);
this.allocateMappedFileService.start();//啟動(dòng)該線程類
@4 class AllocateMappedFileService extends ServiceThread
public AllocateMappedFileService(DefaultMessageStore messageStore) {
this.messageStore = messageStore;
}
3.線程類一直運(yùn)行在干啥

既然在Broker啟動(dòng)時(shí)該線程類AllocateMappedFileService就啟動(dòng)了,那么在做什么呢?run方法為while循環(huán),即:只要服務(wù)不停止并且mmapOperation()返回true則一直運(yùn)行。

//異步處理,調(diào)用mmapOperation完成請(qǐng)求的處理
public void run() {
log.info(this.getServiceName() + " service started");
//while循環(huán),只要服務(wù)部停止即調(diào)用 mmapOperation方法
while (!this.isStopped() && this.mmapOperation()) {
}
log.info(this.getServiceName() + " service end");
}

mmapOperation方法流程圖

RocketMQ存儲(chǔ)中如何實(shí)現(xiàn)日志文件創(chuàng)建與映射

小結(jié):mmapOperation方法主要做了兩件事:初始化MappedFile和預(yù)熱MappedFile。只要服務(wù)不停止和線程不被中斷,這個(gè)過(guò)程一直重復(fù)運(yùn)行。

4.提交映射文件請(qǐng)求(AllocateRequest)

既然AllocateMappedFileService一直從容器(優(yōu)先級(jí)隊(duì)列和ConcurrentHashMap)中獲取AllocateRequest。AllocateRequest是什么時(shí)候產(chǎn)生并放到容器中的呢?
RocketMQ消息存儲(chǔ)概覽【源碼筆記】中寫入commitLog流程,獲取最新的日志文件。
調(diào)用鏈

@1 CommitLog#putMessage
//文件已滿或者沒(méi)有映射文件重新創(chuàng)建一個(gè)文件
if (null == mappedFile || mappedFile.isFull()) {
mappedFile = this.mappedFileQueue.getLastMappedFile(0);
// Mark: NewFile may be cause noise
}
@2 MappedFileQueue#getLastMappedFile

流程圖

RocketMQ存儲(chǔ)中如何實(shí)現(xiàn)日志文件創(chuàng)建與映射

小結(jié):MappedFileQueue#getLastMappedFile會(huì)向線程類AllocateMappedFileServic提交兩個(gè)映射文件創(chuàng)建請(qǐng)求:分別為nextFilePath和nextNextFilePath;如果線程類AllocateMappedFileServic為null,則直接new一個(gè)MappedFile,此時(shí)只會(huì)創(chuàng)建一個(gè)文件。

下面為提交兩個(gè)映射文件請(qǐng)求流程,即:

AllocateMappedFileServic#putRequestAndReturnMappedFile


調(diào)用鏈

@1 MappedFileQueue#getLastMappedFile
if (this.allocateMappedFileService != null) {
mappedFile = this.allocateMappedFileService.putRequestAndReturnMappedFile(nextFilePath,
nextNextFilePath, this.mappedFileSize);
}
@2 AllocateMappedFileService#putRequestAndReturnMappedFile

流程圖

RocketMQ存儲(chǔ)中如何實(shí)現(xiàn)日志文件創(chuàng)建與映射

小結(jié):處理提交的映射文件請(qǐng)求指的是:
實(shí)例化兩個(gè)AllocateRequest并把他們提交到requestTable(ConcurrentHashMap)
和requestQueue(PriorityBlockingQueue)中,等待5秒,此段時(shí)間線程會(huì)從這兩個(gè)容器中獲取請(qǐng)求并創(chuàng)建MappedFile,并將結(jié)果返回。

5.MappedFile初始化

本段梳理下上文中mmapOperation方法流程圖第5步初始化MappedFile的流程
調(diào)用鏈

@1 AllocateMappedFileService#mmapOperation
mappedFile = new MappedFile(req.getFilePath(), req.getFileSize());
@2 MappedFile#init(fileName, fileSize);

流程圖

RocketMQ存儲(chǔ)中如何實(shí)現(xiàn)日志文件創(chuàng)建與映射

MappedFile主要干了兩件事:1.創(chuàng)建日志文件。2.并將文件映射到內(nèi)存中。

關(guān)于“RocketMQ存儲(chǔ)中如何實(shí)現(xiàn)日志文件創(chuàng)建與映射”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。

分享名稱:RocketMQ存儲(chǔ)中如何實(shí)現(xiàn)日志文件創(chuàng)建與映射
文章地址:http://chinadenli.net/article20/jhhhjo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供建站公司、品牌網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站建設(shè)網(wǎng)站設(shè)計(jì)、微信公眾號(hào)、做網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站建設(shè)