zookeeper查看事务日志
来源:互联网 发布:玩具战争魔鬼数据 编辑:程序博客网 时间:2024/05/10 05:54
zookeeper的事务日志通过zoo.cfg文件中的dataLogDir配置项配置,文件如下:
zookeeper提供了查看事务日志的工具类LogFormatter ,运行:
java -classpath .:slf4j-api-1.6.1.jar:zookeeper-3.4.5.jar org.apache.zookeeper.server.LogFormatter /export1/zookeeper/logs/version-2/log.1000003d2
将看到格式化的日志内容类似:
ZooKeeper Transactional Log File with dbid 0 txnlog format version 25/12/14 7:06:31 PM CST session 0x145ef610b530000 cxid 0x229e zxid 0x1000003e8 delete '/hbase/region-in-transition/e3d18e83988febe321e563f0852101275/12/14 7:06:31 PM CST session 0x245ef610b52004c cxid 0x0 zxid 0x1000003e9 createSession 400005/12/14 7:06:31 PM CST session 0x245ef610b52004c cxid 0x3 zxid 0x1000003ea closeSession null5/12/14 7:06:31 PM CST session 0x545f01346c60001 cxid 0x0 zxid 0x1000003eb createSession 400005/12/14 7:06:31 PM CST session 0x545f01346c60001 cxid 0x3 zxid 0x1000003ec closeSession null5/12/14 7:06:32 PM CST session 0x445f018d5e00002 cxid 0x0 zxid 0x1000003ed createSession 400005/12/14 7:06:32 PM CST session 0x445f018d5e00002 cxid 0x3 zxid 0x1000003ee closeSession null5/12/14 7:06:32 PM CST session 0x145ef610b530000 cxid 0x22a1 zxid 0x1000003ef setData '/hbase/table/wyp,#ffffffff000146d61737465723a36303030303b36ffffffc765ffffffb0ffffffa5ffffffa3745042554681,55/12/14 7:06:32 PM CST session 0x145ef610b530000 cxid 0x22a3 zxid 0x1000003f0 delete '/hbase/table-lock/wyp/write-master:6000000000000025/12/14 7:06:32 PM CST session 0x145ef610b530033 cxid 0x0 zxid 0x1000003f1 createSession 400005/12/14 7:06:32 PM CST session 0x145ef610b530033 cxid 0x3 zxid 0x1000003f2 closeSession null
LogFormatter 类代码如下:
/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.zookeeper.server;import java.io.ByteArrayInputStream;import java.io.EOFException;import java.io.FileInputStream;import java.io.IOException;import java.text.DateFormat;import java.util.Date;import java.util.zip.Adler32;import java.util.zip.Checksum;import org.apache.jute.BinaryInputArchive;import org.apache.jute.InputArchive;import org.apache.jute.Record;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.apache.zookeeper.server.persistence.FileHeader;import org.apache.zookeeper.server.persistence.FileTxnLog;import org.apache.zookeeper.server.util.SerializeUtils;import org.apache.zookeeper.txn.TxnHeader;public class LogFormatter { private static final Logger LOG = LoggerFactory.getLogger(LogFormatter.class); /** * @param args */ public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("USAGE: LogFormatter log_file"); System.exit(2); } FileInputStream fis = new FileInputStream(args[0]); BinaryInputArchive logStream = BinaryInputArchive.getArchive(fis); FileHeader fhdr = new FileHeader(); fhdr.deserialize(logStream, "fileheader"); if (fhdr.getMagic() != FileTxnLog.TXNLOG_MAGIC) { System.err.println("Invalid magic number for " + args[0]); System.exit(2); } System.out.println("ZooKeeper Transactional Log File with dbid " + fhdr.getDbid() + " txnlog format version " + fhdr.getVersion()); int count = 0; while (true) { long crcValue; byte[] bytes; try { crcValue = logStream.readLong("crcvalue"); bytes = logStream.readBuffer("txnEntry"); } catch (EOFException e) { System.out.println("EOF reached after " + count + " txns."); return; } if (bytes.length == 0) { // Since we preallocate, we define EOF to be an // empty transaction System.out.println("EOF reached after " + count + " txns."); return; } Checksum crc = new Adler32(); crc.update(bytes, 0, bytes.length); if (crcValue != crc.getValue()) { throw new IOException("CRC doesn't match " + crcValue + " vs " + crc.getValue()); } TxnHeader hdr = new TxnHeader(); Record txn = SerializeUtils.deserializeTxn(bytes, hdr); System.out.println(DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG).format(new Date(hdr.getTime())) + " session 0x" + Long.toHexString(hdr.getClientId()) + " cxid 0x" + Long.toHexString(hdr.getCxid()) + " zxid 0x" + Long.toHexString(hdr.getZxid()) + " " + TraceFormatter.op2String(hdr.getType()) + " " + txn); if (logStream.readByte("EOR") != 'B') { LOG.error("Last transaction was partial."); throw new EOFException("Last transaction was partial."); } count++; } }}
0 1
- zookeeper查看事务日志
- zookeeper 事务日志
- zookeeper事务日志可视化
- 查看Zookeeper日志
- 查看SQL事务日志
- 查看MySql事务日志
- ZooKeeper的事务日志可视化
- 可视化zookeeper的事务日志
- ZooKeeper的事务日志可视化
- Zookeeper日志文件&事务日志&数据快照
- 查看数据库事务日志文件
- 查看SQLSERVER事务日志记录
- zookeeper 清理snapshot及事务日志
- ZooKeeper的事务日志和快照
- zookeeper 清理snapshot及事务日志
- 【ZooKeeper Notes 4】可视化zookeeper的事务日志
- 【ZooKeeper Notes 4】可视化ZooKeeper的事务日志
- 如何查看SQL Server的事务日志
- 求教:两个向量求互相关性,用Matlab画出图像后,应该如何分析?
- HSSFWorkBooK用法 Excel导出详细
- 学习嵌入式Linux系统开发基础 第六课(gcc与gdb)
- 解决修改host文件无效的解决方法
- myecplise问题
- zookeeper查看事务日志
- Android之Notification篇
- 用pushlet框架做消息推送需要注意的几个内容
- MATLAB概述
- ios内存管理机制
- Android Mms流程。
- 欧洲哌嗪彩晶薄膜的纳米防骗子谁是富有的足球吗?欧洲哌嗪彩晶薄膜的纳米防骗子谁是富有的足球吗? C罗在最近几年一直在4000年收入
- window远程连接mac os x
- 了解了这些才能开始发挥jQuery的威力