support parse meta log for arbserver and more friendly output.
This commit is contained in:
		@ -556,7 +556,7 @@ void ObTxRedoLog::reset_mutator_buf()
 | 
			
		||||
//      unused_encrypt_info can work. This may be perfected in the future.
 | 
			
		||||
int ObTxRedoLog::ob_admin_dump(memtable::ObMemtableMutatorIterator *iter_ptr,
 | 
			
		||||
                               ObAdminMutatorStringArg &arg,
 | 
			
		||||
                               palf::block_id_t block_id,
 | 
			
		||||
                               const char *block_name,
 | 
			
		||||
                               palf::LSN lsn,
 | 
			
		||||
                               int64_t tx_id,
 | 
			
		||||
                               SCN scn,
 | 
			
		||||
@ -592,8 +592,8 @@ int ObTxRedoLog::ob_admin_dump(memtable::ObMemtableMutatorIterator *iter_ptr,
 | 
			
		||||
      has_output = true;
 | 
			
		||||
    } else {
 | 
			
		||||
      if (!has_dumped_tx_id) {
 | 
			
		||||
        databuff_printf(arg.buf_, arg.buf_len_, arg.pos_, "{BlockID: %ld; LSN:%ld, TxID:%ld; SCN:%s",
 | 
			
		||||
                        block_id, lsn.val_, tx_id, to_cstring(scn));
 | 
			
		||||
        databuff_printf(arg.buf_, arg.buf_len_, arg.pos_, "{BlockID: %s; LSN:%ld, TxID:%ld; SCN:%s",
 | 
			
		||||
                        block_name, lsn.val_, tx_id, to_cstring(scn));
 | 
			
		||||
      }
 | 
			
		||||
      databuff_printf(arg.buf_, arg.buf_len_, arg.pos_,
 | 
			
		||||
                      "<TxRedoLog>: {TxCtxInfo: {%s}; MutatorMeta: {%s}; MutatorRows: {",
 | 
			
		||||
 | 
			
		||||
@ -252,7 +252,7 @@ public:
 | 
			
		||||
  //for ob_admin dump self
 | 
			
		||||
  int ob_admin_dump(memtable::ObMemtableMutatorIterator *iter_ptr,
 | 
			
		||||
                    share::ObAdminMutatorStringArg &arg,
 | 
			
		||||
                    palf::block_id_t block_id,
 | 
			
		||||
                    const char *block_name,
 | 
			
		||||
                    palf::LSN lsn,
 | 
			
		||||
                    int64_t tx_id,
 | 
			
		||||
                    share::SCN scn,
 | 
			
		||||
 | 
			
		||||
@ -18,6 +18,9 @@
 | 
			
		||||
#include "logservice/palf/log_define.h"
 | 
			
		||||
#include "logservice/palf/log_group_entry.h"
 | 
			
		||||
#include "logservice/palf/log_meta.h"
 | 
			
		||||
#define private public
 | 
			
		||||
#include "logservice/archiveservice/ob_archive_define.h"
 | 
			
		||||
#undef private
 | 
			
		||||
#include "../parser/ob_admin_parser_log_entry.h"
 | 
			
		||||
#include "../parser/ob_admin_parser_group_entry.h"
 | 
			
		||||
namespace oceanbase
 | 
			
		||||
@ -27,30 +30,116 @@ using namespace share;
 | 
			
		||||
using namespace palf;
 | 
			
		||||
namespace tools
 | 
			
		||||
{
 | 
			
		||||
int mmap_log_file(char *&buf_out, const int64_t buf_len, const char *path, int &fd)
 | 
			
		||||
int ObAdminDumpBlockHelper::mmap_log_file(char *&buf_out,
 | 
			
		||||
                                          const int64_t buf_len,
 | 
			
		||||
                                          const char *path,
 | 
			
		||||
                                          const int64_t header_size,
 | 
			
		||||
                                          int &fd_out)
 | 
			
		||||
{
 | 
			
		||||
  int ret = OB_SUCCESS;
 | 
			
		||||
  void *buf = NULL;
 | 
			
		||||
  struct stat stat_buf;
 | 
			
		||||
  if (-1 == (fd = open(path, O_RDONLY))) {
 | 
			
		||||
    ret = OB_IO_ERROR;
 | 
			
		||||
  if (-1 == (fd_out = ::open(path, O_RDONLY))) {
 | 
			
		||||
    ret = palf::convert_sys_errno();
 | 
			
		||||
    LOG_WARN("open file fail", K(path), KERRMSG, K(ret));
 | 
			
		||||
  } else if (MAP_FAILED == (buf = ::mmap(NULL, buf_len, PROT_READ, MAP_SHARED, fd, 0 + MAX_INFO_BLOCK_SIZE)) || NULL == buf) {
 | 
			
		||||
    ret = OB_ERR_UNEXPECTED;
 | 
			
		||||
    LOG_WARN("failed to mmap file", K(path), K(errno), KERRMSG, K(ret));
 | 
			
		||||
  } else if (NULL == (buf = ::mmap(NULL, buf_len, PROT_READ, MAP_SHARED, fd_out, 0 + header_size))) {
 | 
			
		||||
    ret = palf::convert_sys_errno();
 | 
			
		||||
    LOG_WARN("failed to mmap file", K(buf_len), K(path), K(errno), KERRMSG, K(ret), K(fd_out), K(header_size));
 | 
			
		||||
  } else {
 | 
			
		||||
    buf_out = static_cast<char *>(buf);
 | 
			
		||||
    LOG_INFO("map_log_file success", K(path), K(buf), K(fd));
 | 
			
		||||
    LOG_INFO("map_log_file success", K(path), K(buf), K(fd_out));
 | 
			
		||||
  }
 | 
			
		||||
  return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void unmap_log_file(char *buf_in, const int64_t buf_len, const int64_t fd)
 | 
			
		||||
void ObAdminDumpBlockHelper::unmap_log_file(char *buf_in,
 | 
			
		||||
                                            const int64_t buf_len,
 | 
			
		||||
                                            const int64_t fd_in)
 | 
			
		||||
{
 | 
			
		||||
  if (NULL != buf_in && -1 != fd) {
 | 
			
		||||
  if (NULL != buf_in && -1 != fd_in) {
 | 
			
		||||
    ::munmap(reinterpret_cast<void*>(buf_in), buf_len);
 | 
			
		||||
    ::close(fd_in);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ObAdminDumpBlockHelper::get_file_meta(const char *path,
 | 
			
		||||
                                          palf::LSN &start_lsn,
 | 
			
		||||
                                          int64_t &header_size,
 | 
			
		||||
                                          int64_t &body_size)
 | 
			
		||||
{
 | 
			
		||||
  int ret = OB_SUCCESS;
 | 
			
		||||
  int fd = -1;
 | 
			
		||||
  ReadBufGuard read_buf_guard("ObAdmin", MAX_INFO_BLOCK_SIZE);
 | 
			
		||||
  char *read_buf = read_buf_guard.read_buf_.buf_;
 | 
			
		||||
  int64_t out_read_size = 0;
 | 
			
		||||
  int16_t magic_num = 0;
 | 
			
		||||
  int64_t pos = 0;
 | 
			
		||||
  struct stat block_stat;
 | 
			
		||||
  if (-1 == (fd = open(path, O_RDONLY))) {
 | 
			
		||||
    ret = palf::convert_sys_errno();
 | 
			
		||||
    LOG_WARN("open file fail", K(path), KERRMSG, K(ret));
 | 
			
		||||
  } else if (-1 == (::fstat(fd, &block_stat))) {
 | 
			
		||||
    ret = palf::convert_sys_errno();
 | 
			
		||||
    LOG_WARN("fstat file fail", K(path), KERRMSG, K(ret));
 | 
			
		||||
  } else if (MAX_INFO_BLOCK_SIZE != (out_read_size = ob_pread(fd, read_buf, MAX_INFO_BLOCK_SIZE, 0))) {
 | 
			
		||||
    ret = palf::convert_sys_errno();
 | 
			
		||||
    LOG_WARN("read file fail", K(path), KERRMSG, K(ret));
 | 
			
		||||
  } else if (OB_FAIL(serialization::decode_i16(read_buf, MAX_INFO_BLOCK_SIZE, pos, &magic_num))) {
 | 
			
		||||
    LOG_WARN("serialization::decode_i16 failed", K(path), KERRMSG, K(ret));
 | 
			
		||||
  } else if (archive::ObArchiveFileHeader::ARCHIVE_FILE_HEADER_MAGIC == magic_num) {
 | 
			
		||||
    ret = parse_archive_header_(read_buf, MAX_INFO_BLOCK_SIZE, start_lsn);
 | 
			
		||||
  } else if (palf::LogBlockHeader::MAGIC == magic_num) {
 | 
			
		||||
    ret = parse_palf_header_(read_buf, MAX_INFO_BLOCK_SIZE, start_lsn);
 | 
			
		||||
  } else {
 | 
			
		||||
    LOG_ERROR("Invalid block header", K(path), K(magic_num), K(read_buf));
 | 
			
		||||
  }
 | 
			
		||||
  if (OB_SUCC(ret)) {
 | 
			
		||||
    header_size = MAX_INFO_BLOCK_SIZE;
 | 
			
		||||
    body_size = block_stat.st_size - MAX_INFO_BLOCK_SIZE;
 | 
			
		||||
    LOG_INFO("get_file_meta success", K(path), K(start_lsn), K(header_size), K(body_size));
 | 
			
		||||
  }
 | 
			
		||||
  if (-1 != fd) {
 | 
			
		||||
    ::close(fd);
 | 
			
		||||
  }
 | 
			
		||||
  return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ObAdminDumpBlockHelper::parse_archive_header_(const char *buf_in,
 | 
			
		||||
                                                  const int64_t buf_len,
 | 
			
		||||
                                                  palf::LSN &start_lsn)
 | 
			
		||||
{
 | 
			
		||||
  int ret = OB_SUCCESS;
 | 
			
		||||
  archive::ObArchiveFileHeader header;
 | 
			
		||||
  int64_t pos = 0;
 | 
			
		||||
  if (OB_FAIL(header.deserialize(buf_in, buf_len, pos))) {
 | 
			
		||||
    LOG_WARN("deserialize ObArchiveFileHeader failed", K(pos), K(buf_len));
 | 
			
		||||
  } else if (false == header.is_valid()) {
 | 
			
		||||
    ret = OB_INVALID_DATA;
 | 
			
		||||
    LOG_ERROR("ObArchiveFileHeader data invalid", K(header));
 | 
			
		||||
  } else {
 | 
			
		||||
    start_lsn = LSN(header.start_lsn_);
 | 
			
		||||
    LOG_INFO("parse_archive_header_ success", K(header));
 | 
			
		||||
  }
 | 
			
		||||
  return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ObAdminDumpBlockHelper::parse_palf_header_(const char *buf_in,
 | 
			
		||||
                                                const int64_t buf_len,
 | 
			
		||||
                                                palf::LSN &start_lsn)
 | 
			
		||||
{
 | 
			
		||||
  int ret = OB_SUCCESS;
 | 
			
		||||
  palf::LogBlockHeader header;
 | 
			
		||||
  int64_t pos = 0;
 | 
			
		||||
  if (OB_FAIL(header.deserialize(buf_in, buf_len, pos))) {
 | 
			
		||||
    LOG_WARN("deserialize LogBlockHeader failed", K(pos), K(buf_len));
 | 
			
		||||
  } else if (false == header.check_integrity()) {
 | 
			
		||||
    ret = OB_INVALID_DATA;
 | 
			
		||||
    LOG_ERROR("LogBlockHeader data invalid", K(header));
 | 
			
		||||
  } else {
 | 
			
		||||
    start_lsn = header.get_min_lsn();
 | 
			
		||||
    LOG_INFO("parse_palf_header_ success", K(header));
 | 
			
		||||
  }
 | 
			
		||||
  return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ObAdminDumpBlock::ObAdminDumpBlock(const char *block_path,
 | 
			
		||||
@ -63,33 +152,45 @@ ObAdminDumpBlock::ObAdminDumpBlock(const char *block_path,
 | 
			
		||||
int ObAdminDumpBlock::dump()
 | 
			
		||||
{
 | 
			
		||||
  int ret = OB_SUCCESS;
 | 
			
		||||
  char *block_name  = basename((char*)block_path_);
 | 
			
		||||
  if (NULL == block_name) {
 | 
			
		||||
    ret = OB_ERR_UNEXPECTED;
 | 
			
		||||
    LOG_ERROR("invalid block_path", K(block_path_), KP(block_name));
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
  ObAdminDumpIterator iter;
 | 
			
		||||
  const block_id_t block_id = static_cast<palf::block_id_t>(atoi(block_path_));
 | 
			
		||||
  const LSN start_lsn(block_id * PALF_BLOCK_SIZE);
 | 
			
		||||
  const LSN end_lsn((block_id + 1) * PALF_BLOCK_SIZE);
 | 
			
		||||
  ObAdminDumpBlockHelper helper;
 | 
			
		||||
  int64_t header_size, body_size;
 | 
			
		||||
  LSN start_lsn;
 | 
			
		||||
  if (OB_FAIL(helper.get_file_meta(block_path_, start_lsn, header_size, body_size))) {
 | 
			
		||||
    LOG_WARN("ObAdminDumpBlockHelper get_file_meta failed", K(block_path_));
 | 
			
		||||
  } else {
 | 
			
		||||
    MemoryStorage mem_storage;
 | 
			
		||||
  auto get_file_size = [&]() -> LSN { return end_lsn; };
 | 
			
		||||
    char *buf = NULL;
 | 
			
		||||
  int fd = -1;
 | 
			
		||||
    int fd_out = -1;
 | 
			
		||||
    const LSN end_lsn = start_lsn + body_size;
 | 
			
		||||
    auto get_file_size = [&]() -> LSN { return end_lsn; };
 | 
			
		||||
    if (mem_storage.init(start_lsn)) {
 | 
			
		||||
      LOG_WARN("MemoryIteratorStorage init failed", K(ret), K(block_path_));
 | 
			
		||||
  } else if (OB_FAIL(mmap_log_file(buf, PALF_BLOCK_SIZE, block_path_, fd))) {
 | 
			
		||||
    } else if (OB_FAIL(helper.mmap_log_file(buf, body_size, block_path_, header_size, fd_out))) {
 | 
			
		||||
      LOG_WARN("mmap_log_file_ failed", K(ret));
 | 
			
		||||
  } else if (OB_FAIL(mem_storage.append(buf, PALF_BLOCK_SIZE))) {
 | 
			
		||||
    } else if (OB_FAIL(mem_storage.append(buf, body_size))) {
 | 
			
		||||
      LOG_WARN("MemoryStorage append failed", K(ret));
 | 
			
		||||
    } else if (OB_FAIL(iter.init(start_lsn, get_file_size, &mem_storage))) {
 | 
			
		||||
      LOG_WARN("LogIteratorImpl init failed", K(ret), K(start_lsn), K(end_lsn));
 | 
			
		||||
  } else if (OB_FAIL(do_dump_(iter, block_id))) {
 | 
			
		||||
    } else if (OB_FAIL(do_dump_(iter, block_name))) {
 | 
			
		||||
      LOG_WARN("ObAdminDumpIterator do_dump_ failed", K(ret), K(iter));
 | 
			
		||||
    } else {
 | 
			
		||||
    LOG_INFO("ObAdminDumpBlock dump success", K(ret), K(block_path_));
 | 
			
		||||
      LOG_INFO("ObAdminDumpBlock dump success", K(ret), K(block_path_), K(start_lsn), K(header_size),
 | 
			
		||||
               K(body_size));
 | 
			
		||||
    }
 | 
			
		||||
    helper.unmap_log_file(buf, body_size, fd_out);
 | 
			
		||||
  }
 | 
			
		||||
  unmap_log_file(buf, PALF_BLOCK_SIZE, fd);
 | 
			
		||||
  return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ObAdminDumpBlock::do_dump_(ObAdminDumpIterator &iter,
 | 
			
		||||
                               block_id_t block_id)
 | 
			
		||||
                               const char *block_name)
 | 
			
		||||
{
 | 
			
		||||
  int ret = OB_SUCCESS;
 | 
			
		||||
  LogGroupEntry entry;
 | 
			
		||||
@ -105,10 +206,10 @@ int ObAdminDumpBlock::do_dump_(ObAdminDumpIterator &iter,
 | 
			
		||||
      const int64_t total_size = entry.get_serialize_size();
 | 
			
		||||
      if (str_arg_.flag_ == LogFormatFlag::NO_FORMAT
 | 
			
		||||
          && str_arg_.flag_ != LogFormatFlag::STAT_FORMAT ) {
 | 
			
		||||
        fprintf(stdout, "BlockID:%ld, LSN:%s, SIZE:%ld, GROUP_ENTRY:%s\n", block_id, to_cstring(lsn), total_size,
 | 
			
		||||
        fprintf(stdout, "BlockID:%s, LSN:%s, SIZE:%ld, GROUP_ENTRY:%s\n", block_name, to_cstring(lsn), total_size,
 | 
			
		||||
                to_cstring(entry));
 | 
			
		||||
      }
 | 
			
		||||
      if (OB_FAIL(parse_single_group_entry_(entry, block_id, lsn))) {
 | 
			
		||||
      if (OB_FAIL(parse_single_group_entry_(entry, block_name, lsn))) {
 | 
			
		||||
        LOG_WARN("parser_single_group_entry_ success", K(ret), K(entry));
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
@ -127,27 +228,29 @@ int ObAdminDumpBlock::do_dump_(ObAdminDumpIterator &iter,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ObAdminDumpBlock::parse_single_group_entry_(const LogGroupEntry &group_entry,
 | 
			
		||||
                                                block_id_t block_id,
 | 
			
		||||
                                                const char *block_name,
 | 
			
		||||
                                                LSN lsn)
 | 
			
		||||
{
 | 
			
		||||
  int ret = OB_SUCCESS;
 | 
			
		||||
  LSN curr_lsn = lsn;
 | 
			
		||||
  ObAdminParserGroupEntry parser_ge(group_entry.get_data_buf(), group_entry.get_data_len(), str_arg_);
 | 
			
		||||
  do {
 | 
			
		||||
    LogEntry entry;
 | 
			
		||||
    if (OB_FAIL(parser_ge.get_next_log_entry(entry))) {
 | 
			
		||||
      if (OB_ITER_END != ret) {
 | 
			
		||||
        LOG_WARN("ObAdminParserGroupEntry get_next_log_entry failed",
 | 
			
		||||
                 K(ret), K(block_id), K(lsn), K(group_entry));
 | 
			
		||||
                 K(ret), K(block_name), K(lsn), K(group_entry));
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      if (str_arg_.flag_ == LogFormatFlag::NO_FORMAT
 | 
			
		||||
          && str_arg_.flag_ != LogFormatFlag::STAT_FORMAT ) {
 | 
			
		||||
        fprintf(stdout, "LSN:%s, LOG_ENTRY:%s", to_cstring(lsn), to_cstring(entry));
 | 
			
		||||
        fprintf(stdout, "LSN:%s, LOG_ENTRY:%s", to_cstring(curr_lsn), to_cstring(entry));
 | 
			
		||||
      }
 | 
			
		||||
      str_arg_.log_stat_->log_entry_header_size_ += entry.get_header_size();
 | 
			
		||||
      str_arg_.log_stat_->total_log_entry_count_++;
 | 
			
		||||
      curr_lsn = curr_lsn + entry.get_serialize_size();
 | 
			
		||||
      int tmp_ret = OB_SUCCESS;
 | 
			
		||||
      if (OB_SUCCESS != (tmp_ret = parse_single_log_entry_(entry, block_id, lsn))) {
 | 
			
		||||
      if (OB_SUCCESS != (tmp_ret = parse_single_log_entry_(entry, block_name, lsn))) {
 | 
			
		||||
        LOG_WARN("parse_single_log_entry_ failed", K(tmp_ret), K(entry));
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
@ -160,15 +263,15 @@ int ObAdminDumpBlock::parse_single_group_entry_(const LogGroupEntry &group_entry
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ObAdminDumpBlock::parse_single_log_entry_(const LogEntry &entry,
 | 
			
		||||
                                              block_id_t block_id,
 | 
			
		||||
                                              const char *block_name,
 | 
			
		||||
                                              palf::LSN lsn)
 | 
			
		||||
{
 | 
			
		||||
  int ret = OB_SUCCESS;
 | 
			
		||||
  ObAdminParserLogEntry parser_le(entry, block_id, lsn, str_arg_);
 | 
			
		||||
  ObAdminParserLogEntry parser_le(entry, block_name, lsn, str_arg_);
 | 
			
		||||
  if (OB_FAIL(parser_le.parse())) {
 | 
			
		||||
    LOG_WARN("ObAdminParserLogEntry failed", K(ret), K(entry), K(block_id), K(lsn));
 | 
			
		||||
    LOG_WARN("ObAdminParserLogEntry failed", K(ret), K(entry), K(block_name), K(lsn));
 | 
			
		||||
  } else {
 | 
			
		||||
    LOG_INFO("YYY parse_single_log_entry_ success",K(entry), K(str_arg_));
 | 
			
		||||
    LOG_INFO("parse_single_log_entry_ success",K(entry), K(str_arg_));
 | 
			
		||||
  }
 | 
			
		||||
  return ret;
 | 
			
		||||
}
 | 
			
		||||
@ -183,32 +286,47 @@ ObAdminDumpMetaBlock::ObAdminDumpMetaBlock(const char *block_path,
 | 
			
		||||
int ObAdminDumpMetaBlock::dump()
 | 
			
		||||
{
 | 
			
		||||
  int ret = OB_SUCCESS;
 | 
			
		||||
  char *block_name  = basename((char*)block_path_);
 | 
			
		||||
  if (NULL == block_name) {
 | 
			
		||||
    ret = OB_ERR_UNEXPECTED;
 | 
			
		||||
    LOG_ERROR("invalid block_path", K(block_path_), KP(block_name));
 | 
			
		||||
    return ret;
 | 
			
		||||
  }
 | 
			
		||||
  ObAdminDumpIterator iter;
 | 
			
		||||
  const block_id_t block_id = static_cast<palf::block_id_t>(atoi(block_path_));
 | 
			
		||||
  const LSN start_lsn(block_id * PALF_BLOCK_SIZE);
 | 
			
		||||
  const LSN end_lsn((block_id + 1) * PALF_BLOCK_SIZE);
 | 
			
		||||
  MemoryStorage mem_storage;
 | 
			
		||||
  int64_t header_size, body_size;
 | 
			
		||||
  LSN start_lsn;
 | 
			
		||||
  ObAdminDumpBlockHelper helper;
 | 
			
		||||
  if (OB_FAIL(helper.get_file_meta(block_path_, start_lsn, header_size, body_size))) {
 | 
			
		||||
    LOG_WARN("ObAdminDumpBlockHelper init failed", K(ret), K(block_path_));
 | 
			
		||||
  } else {
 | 
			
		||||
    // The LSN (Log Sequence Number) used for metadata files does not have any real significance or use.
 | 
			
		||||
    // Therefore, just set start_lsn to 0
 | 
			
		||||
    start_lsn = LSN(PALF_INITIAL_LSN_VAL);
 | 
			
		||||
    const LSN end_lsn = start_lsn + body_size;
 | 
			
		||||
    auto get_file_size = [&]() -> LSN { return end_lsn; };
 | 
			
		||||
    char *buf = NULL;
 | 
			
		||||
  int fd = -1;
 | 
			
		||||
    int fd_out = -1;
 | 
			
		||||
    if (mem_storage.init(start_lsn)) {
 | 
			
		||||
      LOG_WARN("MemoryIteratorStorage init failed", K(ret), K(block_path_));
 | 
			
		||||
  } else if (OB_FAIL(mmap_log_file(buf, PALF_BLOCK_SIZE, block_path_, fd))) {
 | 
			
		||||
    } else if (OB_FAIL(helper.mmap_log_file(buf, body_size, block_path_, header_size, fd_out))) {
 | 
			
		||||
      LOG_WARN("mmap_log_file_ failed", K(ret));
 | 
			
		||||
  } else if (OB_FAIL(mem_storage.append(buf, PALF_BLOCK_SIZE))) {
 | 
			
		||||
    } else if (OB_FAIL(mem_storage.append(buf, body_size))) {
 | 
			
		||||
      LOG_WARN("MemoryStorage append failed", K(ret));
 | 
			
		||||
    } else if (OB_FAIL(iter.init(start_lsn, get_file_size, &mem_storage))) {
 | 
			
		||||
      LOG_WARN("LogIteratorImpl init failed", K(ret), K(start_lsn), K(end_lsn));
 | 
			
		||||
  } else if (OB_FAIL(do_dump_(iter, block_id))) {
 | 
			
		||||
    } else if (OB_FAIL(do_dump_(iter, block_name))) {
 | 
			
		||||
      LOG_WARN("ObAdminDumpIterator do_dump_ failed", K(ret), K(iter));
 | 
			
		||||
    } else {
 | 
			
		||||
      LOG_INFO("ObAdminDumpBlock dump success", K(ret), K(block_path_));
 | 
			
		||||
    }
 | 
			
		||||
  unmap_log_file(buf, PALF_BLOCK_SIZE, fd);
 | 
			
		||||
    helper.unmap_log_file(buf, body_size, fd_out);
 | 
			
		||||
  }
 | 
			
		||||
  return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ObAdminDumpMetaBlock::do_dump_(ObAdminDumpIterator &iter, palf::block_id_t block_id)
 | 
			
		||||
int ObAdminDumpMetaBlock::do_dump_(ObAdminDumpIterator &iter,
 | 
			
		||||
                                   const char *block_name)
 | 
			
		||||
{
 | 
			
		||||
  int ret = OB_SUCCESS;
 | 
			
		||||
  LogMetaEntry entry;
 | 
			
		||||
@ -223,7 +341,7 @@ int ObAdminDumpMetaBlock::do_dump_(ObAdminDumpIterator &iter, palf::block_id_t b
 | 
			
		||||
      if (OB_FAIL(log_meta.deserialize(entry.get_buf(), entry.get_data_len(), pos))) {
 | 
			
		||||
        LOG_WARN("deserialize log_meta failed", K(ret), K(iter));
 | 
			
		||||
      } else {
 | 
			
		||||
        fprintf(stdout, "BlockID:%ld, LSN:%s, SIZE:%ld, META_ENTRY:%s\n", block_id, to_cstring(lsn), total_size,
 | 
			
		||||
        fprintf(stdout, "BlockID:%s, LSN:%s, SIZE:%ld, META_ENTRY:%s\n", block_name, to_cstring(lsn), total_size,
 | 
			
		||||
                to_cstring(log_meta));
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -22,8 +22,29 @@ namespace oceanbase
 | 
			
		||||
namespace tools
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
int mmap_log_file_(char *&buf_out, const int64_t buf_len, const char *path, int &fd);
 | 
			
		||||
void unmap_log_file(char *buf_in, const int64_t buf_len, const int64_t fd);
 | 
			
		||||
class ObAdminDumpBlockHelper {
 | 
			
		||||
public:
 | 
			
		||||
  int mmap_log_file(char *&buf_out,
 | 
			
		||||
                    const int64_t buf_len,
 | 
			
		||||
                    const char *path,
 | 
			
		||||
                    const int64_t header_size,
 | 
			
		||||
                    int &fd_out);
 | 
			
		||||
  void unmap_log_file(char *buf_in,
 | 
			
		||||
                      const int64_t buf_len,
 | 
			
		||||
                      const int64_t fd);
 | 
			
		||||
 | 
			
		||||
  int get_file_meta(const char *path,
 | 
			
		||||
                    palf::LSN &start_lsn,
 | 
			
		||||
                    int64_t &header_size,
 | 
			
		||||
                    int64_t &body_size);
 | 
			
		||||
private:
 | 
			
		||||
  int parse_archive_header_(const char *buf_in,
 | 
			
		||||
                            const int64_t buf_len,
 | 
			
		||||
                            palf::LSN &start_lsn);
 | 
			
		||||
  int parse_palf_header_(const char *buf_in,
 | 
			
		||||
                         const int64_t buf_len,
 | 
			
		||||
                         palf::LSN &start_lsn);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class ObAdminDumpBlock
 | 
			
		||||
{
 | 
			
		||||
@ -36,12 +57,12 @@ private:
 | 
			
		||||
  typedef palf::MemPalfGroupBufferIterator ObAdminDumpIterator;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
  int do_dump_(ObAdminDumpIterator &iter, palf::block_id_t block_id);
 | 
			
		||||
  int do_dump_(ObAdminDumpIterator &iter, const char *block_namt);
 | 
			
		||||
  int parse_single_group_entry_(const palf::LogGroupEntry &entry,
 | 
			
		||||
                                palf::block_id_t block_id,
 | 
			
		||||
                                const char *block_name,
 | 
			
		||||
                                palf::LSN lsn);
 | 
			
		||||
  int parse_single_log_entry_(const palf::LogEntry &entry,
 | 
			
		||||
                              palf::block_id_t block_id,
 | 
			
		||||
                              const char *block_name,
 | 
			
		||||
                              palf::LSN lsn);
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
@ -58,7 +79,7 @@ private:
 | 
			
		||||
  typedef palf::MemPalfMetaBufferIterator ObAdminDumpIterator;
 | 
			
		||||
private:
 | 
			
		||||
  int do_dump_(ObAdminDumpIterator &iter,
 | 
			
		||||
               palf::block_id_t block_id);
 | 
			
		||||
               const char *block_name);
 | 
			
		||||
private:
 | 
			
		||||
  const char *block_path_;
 | 
			
		||||
  share::ObAdminMutatorStringArg str_arg_;
 | 
			
		||||
 | 
			
		||||
@ -65,14 +65,20 @@ void ObAdminLogExecutor::print_usage()
 | 
			
		||||
{
 | 
			
		||||
  fprintf(stdout,
 | 
			
		||||
          "Usages:\n"
 | 
			
		||||
          "$ob_admin log_tool dump_log log_files ## ./ob_admin log_tool dump_log 1 2 3 ##将log文件中的内容全部打印出来\n"
 | 
			
		||||
          "$ob_admin log_tool dump_tx_format log_files ## ./ob_admin log_tool dump_tx_format 1 2 3 ##将log文件中的事务相关内容以json格式打印\n"
 | 
			
		||||
          "$ob_admin log_tool dump_filter 'filter_conditions' log_files ## ./ob_admin log_tool dump_filter 'tx_id=xxxx;tablet_id=xxx' 1 2 3"
 | 
			
		||||
          "##按照过滤条件将log文件中的事务相关内容打印,目前支持按照事务id(tx_id=xxxx),tablet_id(tablet_id=xxxx)进行过滤,多个条件之间以;隔开\n"
 | 
			
		||||
          "$ob_admin log_tool dump_log log_files ## ./ob_admin log_tool dump_log log_files... ##将log文件中的内容全部打印出来\n"
 | 
			
		||||
          "$ob_admin log_tool dump_tx_format log_files ## ./ob_admin log_tool dump_tx_format log_files ##将log文件中的事务相关内容以json格式打印\n"
 | 
			
		||||
          "$ob_admin log_tool dump_filter 'filter_conditions' log_files ## ./ob_admin log_tool dump_filter 'tx_id=xxxx;tablet_id=xxx' '$path'"
 | 
			
		||||
          "## 按照过滤条件将log文件中的事务相关内容打印,目前支持按照事务id(tx_id=xxxx),tablet_id(tablet_id=xxxx)进行过滤,多个条件之间以;隔开\n"
 | 
			
		||||
          "$ob_admin log_tool stat log_files ## ./ob_admin log_tool stat 1\n"
 | 
			
		||||
          "如何通过LSN快速定位日志:\n"
 | 
			
		||||
          "1. 获取文件ID: BLOCK_ID=LSN/(64MB-4KB)\n"
 | 
			
		||||
          "2. 根据LSN去输出文件中执行grep操作"
 | 
			
		||||
          "$ob_admin log_tool dmp_meta log_files ## ./ob_admin log_tool dump_meta 1\n"
 | 
			
		||||
          "一些注意事项:\n"
 | 
			
		||||
          "1. 为避免在clog目录生成一些ob_amdin的输出文件,强烈建议使用绝对路径\n"
 | 
			
		||||
          "2. log_files 支持绝对路径、相对路径\n"
 | 
			
		||||
          "3. log_files 支持同时解析多个文件\n"
 | 
			
		||||
          "4. 支持解析归档文件\n"
 | 
			
		||||
          "5. 如何通过LSN快速定位日志:\n"
 | 
			
		||||
          "   1. 获取文件ID: BLOCK_ID=LSN/(64MB-4KB)\n"
 | 
			
		||||
          "   2. 根据LSN去输出文件中执行grep操作"
 | 
			
		||||
         );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -41,12 +41,14 @@ using namespace palf;
 | 
			
		||||
namespace tools
 | 
			
		||||
{
 | 
			
		||||
ObAdminParserLogEntry::ObAdminParserLogEntry(const LogEntry &entry,
 | 
			
		||||
                                             const block_id_t block_id,
 | 
			
		||||
                                             const char *block_name,
 | 
			
		||||
                                             const LSN lsn,
 | 
			
		||||
                                             const ObAdminMutatorStringArg &str_arg)
 | 
			
		||||
    : buf_(entry.get_data_buf()), buf_len_(entry.get_data_len()), pos_(0),
 | 
			
		||||
    scn_val_(entry.get_scn().get_val_for_logservice()), block_id_(block_id), lsn_(lsn), str_arg_()
 | 
			
		||||
      scn_val_(entry.get_scn().get_val_for_logservice()), lsn_(lsn), str_arg_()
 | 
			
		||||
{
 | 
			
		||||
  memset(block_name_, '\0', OB_MAX_FILE_NAME_LENGTH);
 | 
			
		||||
  memcpy(block_name_, block_name, OB_MAX_FILE_NAME_LENGTH);
 | 
			
		||||
  str_arg_ = str_arg;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -91,7 +93,7 @@ int ObAdminParserLogEntry::parse_trans_service_log_(ObTxLogBlock &tx_log_block)
 | 
			
		||||
    LOG_WARN("ObTxLogBlock init failed", K(ret));
 | 
			
		||||
  } else if (str_arg_.filter_.is_tx_id_valid() && tx_id != str_arg_.filter_.get_tx_id()) {
 | 
			
		||||
    //just skip this
 | 
			
		||||
    LOG_TRACE("skip with tx_id", K(str_arg_), K(tx_id), K(block_id_), K(lsn_));
 | 
			
		||||
    LOG_TRACE("skip with tx_id", K(str_arg_), K(tx_id), K(block_name_), K(lsn_));
 | 
			
		||||
  } else {
 | 
			
		||||
 | 
			
		||||
    str_arg_.log_stat_->tx_block_header_size_ += tx_block_header.get_serialize_size();
 | 
			
		||||
@ -114,7 +116,7 @@ int ObAdminParserLogEntry::parse_trans_service_log_(ObTxLogBlock &tx_log_block)
 | 
			
		||||
      if (LogFormatFlag::NO_FORMAT != str_arg_.flag_) {
 | 
			
		||||
        //print block_id and lsn for tx_format and filter_format
 | 
			
		||||
        str_arg_.writer_ptr_->dump_key("BlockId");
 | 
			
		||||
        str_arg_.writer_ptr_->dump_uint64(block_id_);
 | 
			
		||||
        str_arg_.writer_ptr_->dump_key(block_name_);
 | 
			
		||||
        str_arg_.writer_ptr_->dump_key("LSN");
 | 
			
		||||
        str_arg_.writer_ptr_->dump_int64((int64_t)(lsn_.val_));
 | 
			
		||||
      }
 | 
			
		||||
@ -683,8 +685,8 @@ int ObAdminParserLogEntry::parse_trans_redo_log_(ObTxLogBlock &tx_log_block,
 | 
			
		||||
    LOG_WARN("tx_log_block.deserialize_log_body failed", K(ret), K(redolog));
 | 
			
		||||
  } else if (OB_FAIL(scn.convert_for_logservice(scn_val_))) {
 | 
			
		||||
    LOG_WARN("failed to convert", K(ret), K(scn_val_));
 | 
			
		||||
  } else if (OB_FAIL(redolog.ob_admin_dump(&mmi, str_arg_, block_id_, lsn_, tx_id, scn, has_dumped_tx_id))) {
 | 
			
		||||
    LOG_WARN("get mutator json string failed", K(block_id_), K(lsn_), K(tx_id), K(ret));
 | 
			
		||||
  } else if (OB_FAIL(redolog.ob_admin_dump(&mmi, str_arg_, block_name_, lsn_, tx_id, scn, has_dumped_tx_id))) {
 | 
			
		||||
    LOG_WARN("get mutator json string failed", K(block_name_), K(lsn_), K(tx_id), K(ret));
 | 
			
		||||
  } else {/*do nothing*/}
 | 
			
		||||
  return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -39,7 +39,7 @@ class ObAdminParserLogEntry
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
  ObAdminParserLogEntry(const palf::LogEntry &log_entry,
 | 
			
		||||
                        const palf::block_id_t block_id,
 | 
			
		||||
                        const char *block_name,
 | 
			
		||||
                        const palf::LSN lsn,
 | 
			
		||||
                        const share::ObAdminMutatorStringArg &str_arg);
 | 
			
		||||
  ~ObAdminParserLogEntry();
 | 
			
		||||
@ -81,7 +81,7 @@ private:
 | 
			
		||||
  int64_t pos_;
 | 
			
		||||
 | 
			
		||||
  int64_t scn_val_;
 | 
			
		||||
  palf::block_id_t block_id_;
 | 
			
		||||
  char block_name_[OB_MAX_FILE_NAME_LENGTH];
 | 
			
		||||
  palf::LSN lsn_;
 | 
			
		||||
  share::ObAdminMutatorStringArg str_arg_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user