Zookeeper 持久化與序列化
持久化
Leader 和 Follower 中的資料會在記憶體和磁盤各保存一份, 所以記憶體中的資料會持久化到磁盤, 類似于 HDFS 中的 NameNode

在 zoo.cfg組態檔中配置的路徑下, 存放著 snapShot快照, 和 TxnLog編輯日志


以下相關類都是持久化相關的代碼

SnapShot 快照
public interface SnapShot
//反序列化方法
long deserialize(DataTree dt, Map<Long, Integer> sessions)
throws IOException;
//序列化方法
void serialize(DataTree dt, Map<Long, Integer> sessions,
File name)
throws IOException;
//查找最近的快照檔案
File findMostRecentSnapshot() throws IOException;
//釋放資源
void close() throws IOException;
}
TxnLog 操作日志
public interface TxnLog {
// 設定服務狀態
void setServerStats(ServerStats serverStats);
// 滾動日志
void rollLog() throws IOException;
// 追加
boolean append(TxnHeader hdr, Record r) throws IOException;
// 讀取資料
TxnIterator read(long zxid) throws IOException;
// 獲取最后一個 zxid
long getLastLoggedZxid() throws IOException;
// 洗掉日志
boolean truncate(long zxid) throws IOException;
// 獲取 DbId
long getDbId() throws IOException;
// 提交
void commit() throws IOException;
// 日志同步時間
long getTxnLogSyncElapsedTime();
// 關閉日志
void close() throws IOException;
// 讀取日志的介面
public interface TxnIterator {
// 獲取頭資訊
TxnHeader getHeader();
// 獲取傳輸的內容
Record getTxn();
// 下一條記錄
boolean next() throws IOException;
// 關閉資源
void close() throws IOException;
// 獲取存盤的大小
long getStorageSize() throws IOException;
}
}
持久化的核心類: FileTxnSnapLog

序列化
Zookeeper 集群節點間通訊

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/293901.html
標籤:其他
