在上篇文章中猜揪,我們介紹了ZooKeeper中Snapshot文件的格式.在這盤文章中苫幢,我們將會(huì)介紹TxnLog文件的格式.
在ZooKeeper中,Transaction代表一次客戶端操作,而TxnLog文件就保存了這些Transaction.從ZooKeeper中的FileTxnSnapLog類中风瘦,我們可以看到其格式如下:
FileHeader TxnList ZeroPad
FileHeader:{
magic 4bytes(固定位ZKLG)
version 4bytes
dbid 8bytes
}
TxnList:
Txn || Txn TxnList
Txn:
checksum Txnlen TxnHeader Record 0x42
checksum: 8bytes
Adler32 is currently used, calculated across payload -- Txnlen, TxnHeader, Record and 0x42
Txlen:
len 4bytes
TxnHeader: {
clientId 8bytes
cxid 4bytes
zxid 8bytes
time 8bytes
type 4bytes
}
Record: See Jute definition file for detail on the various record type
ZeroPad: 0 padded to EOF(filled during preallocation stage)
TxnLog的文件名是log.current_zxid的格式舱殿,其中current_zxid是創(chuàng)建它的時(shí)候的zxid宛篇,zxid大于current_zxid的Transaction都是保存在這個(gè)文件中.默認(rèn)情況下芹务,這個(gè)文件是64MB大小.