rocketmq IndexFile原始碼分析

2021-10-06 07:58:34 字數 2471 閱讀 3226

indexfile 儲存具體訊息索引的檔案,檔案的內容結構如圖

## 自己拼的,以後再好好畫

indexfile類

private static final internallogger log = internallogge***ctory.getlogger(loggername.store_logger_name);

private static int hashslotsize = 4;// 每個 hash 槽所佔的位元組數

private static int indexsize = 20;// 每條indexfile條目占用位元組數

private static int invalidindex = 0;// 用來驗證是否是乙個有效的索引。

private final int hashslotnum;// index 檔案中 hash 槽的總個數

private final int indexnum;// indexfile中包含的條目數

private final filechannel filechannel;

private final indexheader indexheader;// 訊息頭

public indexfile(final string filename, final int hashslotnum, final int indexnum,

final long endphyoffset, final long endtimestamp) throws ioexception

if (endtimestamp > 0)

}

indexservice類
/**

* maximum times to attempt index file creation.

*/private static final int max_try_idx_create = 3;

private final defaultmessagestore defaultmessagestore;

private final int hashslotnum;

private final int indexnum;

private final string storepath;

private final arraylistindexfilelist = new arraylist();

private final readwritelock readwritelock = new reentrantreadwritelock();

public indexservice(final defaultmessagestore store)

public boolean putkey(final string key, final long phyoffset, final long storetimestamp) 

// 時間差 計算訊息的儲存時間與當前 indexfile 存放的最小時間差額(單位為秒

long timediff = storetimestamp - this.indexheader.getbegintimestamp();

timediff = timediff / 1000;

if (this.indexheader.getbegintimestamp() <= 0) else if (timediff > integer.max_value) else if (timediff < 0)

int absindexpos =

indexheader.index_header_size + this.hashslotnum * hashslotsize

+ this.indexheader.getindexcount() * indexsize;

// 訊息體

// 槽儲存 訊息的數量

if (this.indexheader.getindexcount() <= 1)

this.indexheader.inchashslotcount();

this.indexheader.incindexcount();

this.indexheader.setendphyoffset(phyoffset);

this.indexheader.setendtimestamp(storetimestamp);

return true;

} catch (exception e) finally catch (ioexception e) }}

} else

return false;

}

Cartographer原始碼篇 原始碼分析 1

在安裝編譯cartographer 1.0.0的時候,我們可以看到 主要包括cartorgarpher ros cartographer ceres sover三個部分。其中,ceres solver用於非線性優化,求解最小二乘問題 cartographer ros為ros平台的封裝,獲取感測器資料...

AbstractListView原始碼分析3

normal list that does not indicate choices public static final int choice mode none 0 the list allows up to one choice public static final int choice ...

Android AsyncTask原始碼分析

android中只能在主線程中進行ui操作,如果是其它子執行緒,需要借助非同步訊息處理機制handler。除此之外,還有個非常方便的asynctask類,這個類內部封裝了handler和執行緒池。本文先簡要介紹asynctask的用法,然後分析具體實現。asynctask是乙個抽象類,我們需要建立子...