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;
long getLastLoggedZxid() throws IOException;
boolean truncate(long zxid) throws IOException;
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 集群节点间通讯
|