ZooKeeper源码解析(4)-TxnLog文件格式

在上篇文章中,我们介绍了ZooKeeper中Snapshot文件的格式.在这盘文章中,我们将会介绍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是创建它的时候的zxid,zxid大于current_zxid的Transaction都是保存在这个文件中.默认情况下,这个文件是64MB大小.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容