提交 e7f1eb7a 编写于 作者: G gjw2284740 提交者: LINGuanRen

[opensource] refine ob_admin to print clog without user data

上级 60a0eee9
......@@ -65,9 +65,17 @@ int ObAdminClogV2Executor::execute(int argc, char* argv[])
LOG_INFO("finish encode", K(ret));
} else if (OB_NEED_RETRY != (ret = CmdCallSimple(new_argc, new_argv, dump_ilog) : OB_NEED_RETRY)) {
LOG_INFO("finish encode", K(ret));
} else if (OB_NEED_RETRY != (ret = CmdCallSimple(new_argc, new_argv, dump_meta) : OB_NEED_RETRY)) {
LOG_INFO("finish encode", K(ret));
} else {
fprintf(stderr, "failed %d", ret);
print_usage();
if (OB_NEED_RETRY == ret) {
LOG_WARN("unrecognized command");
fprintf(stdout, "unrecognized command\n");
print_usage();
} else {
LOG_WARN("failed to execute clog tool", K(ret));
fprintf(stderr, "failed %d\n", ret);
}
}
}
return ret;
......@@ -107,29 +115,43 @@ void ObAdminClogV2Executor::print_usage()
"$ob_admin clog_tool dump_filter filter_str log_files ## ./ob_admin clog_tool dump_filter "
"'table_id=123;partition_id=123;log_id=123' 1 2 3\n"
"$ob_admin clog_tool dump_hex log_files ## ./ob_admin clog_tool dump_hex 1 2 3\n"
"$ob_admin clog_tool dump_format log_files ## ./ob_admin clog_tool dump_format 1 2 3\n");
"$ob_admin clog_tool dump_format log_files ## ./ob_admin clog_tool dump_format 1 2 3\n"
"$ob_admin clog_tool dump_meta log_files ## ./ob_admin clog_tool dump_meta 1 2 3\n");
}
int ObAdminClogV2Executor::dump_all(int argc, char* argv[])
{
int ret = OB_SUCCESS;
const bool is_hex = false;
if (OB_FAIL(dump_inner(argc, argv, is_hex))) {
const bool without_data = false;
if (OB_FAIL(dump_inner(argc, argv, is_hex, without_data))) {
LOG_WARN("failed to dump all", K(ret));
}
return ret;
}
int ObAdminClogV2Executor::dump_meta(int argc, char* argv[])
{
int ret = OB_SUCCESS;
const bool is_hex = false;
const bool without_data = true;
if (OB_FAIL(dump_inner(argc, argv, is_hex, without_data))) {
LOG_WARN("failed to dump meta", K(ret));
}
return ret;
}
int ObAdminClogV2Executor::dump_filter(int argc, char* argv[])
{
int ret = OB_SUCCESS;
const bool is_hex = false;
const bool without_data = false;
if (OB_FAIL(filter_.parse(argv[0]))) {
LOG_WARN("parse filter failed", K(ret), K(argv[0]));
} else {
LOG_INFO("dump with filter", K_(filter), K(argv[0]));
if (OB_FAIL(dump_inner(argc - 1, argv + 1, is_hex))) {
LOG_WARN("failed to dump all", K(ret));
if (OB_FAIL(dump_inner(argc - 1, argv + 1, is_hex, without_data))) {
LOG_WARN("failed to dump filter", K(ret));
}
}
return ret;
......@@ -139,22 +161,23 @@ int ObAdminClogV2Executor::dump_hex(int argc, char* argv[])
{
int ret = OB_SUCCESS;
const bool is_hex = true;
if (OB_FAIL(dump_inner(argc, argv, is_hex))) {
const bool without_data = false;
if (OB_FAIL(dump_inner(argc, argv, is_hex, without_data))) {
LOG_WARN("failed to dump hex", K(ret));
}
return ret;
}
int ObAdminClogV2Executor::dump_inner(int argc, char* argv[], bool is_hex)
int ObAdminClogV2Executor::dump_inner(int argc, char* argv[], bool is_hex, bool without_data)
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(argc < 1) || OB_ISNULL(argv)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid arguments", K(argc), K(ret));
} else {
LOG_INFO("begin to dump all ", K(is_hex), K(ret));
LOG_INFO("begin to dump all ", K(is_hex), K(without_data), K(ret));
for (int64_t i = 0; i < argc; ++i) {
if (OB_FAIL(dump_single_clog(argv[i], is_hex)) && OB_ITER_END != ret) {
if (OB_FAIL(dump_single_clog(argv[i], is_hex, without_data)) && OB_ITER_END != ret) {
LOG_WARN("failed to dump log ", K(argv[i]), K(ret));
} else if (OB_ITER_END == ret) {
ret = OB_SUCCESS;
......@@ -382,7 +405,7 @@ int ObAdminClogV2Executor::encode_int(
return ret;
}
int ObAdminClogV2Executor::dump_single_clog(const char* path, bool is_hex)
int ObAdminClogV2Executor::dump_single_clog(const char* path, bool is_hex, bool without_data)
{
int ret = OB_SUCCESS;
int fd = -1;
......@@ -398,7 +421,7 @@ int ObAdminClogV2Executor::dump_single_clog(const char* path, bool is_hex)
ObLogEntryParser entry_parser;
if (OB_FAIL(entry_parser.init(file_id, buf, buf_len, filter_, DB_host_, DB_port_, config_file_, is_ofs))) {
LOG_WARN("failed to init entry parser", K(path), K(ret));
} else if (OB_FAIL(entry_parser.dump_all_entry(is_hex))) {
} else if (OB_FAIL(entry_parser.dump_all_entry(is_hex, without_data))) {
if (OB_ITER_END == ret) {
LOG_INFO("succ to dump_all_entry", K(path));
} else {
......
......@@ -31,10 +31,11 @@ private:
int dump_all(int argc, char* argv[]);
int dump_filter(int argc, char* argv[]);
int dump_hex(int argc, char* argv[]);
int dump_inner(int argc, char* argv[], bool is_hex);
int dump_inner(int argc, char* argv[], bool is_hex, bool without_data);
int dump_format(int argc, char* argv[]);
int stat_clog(int argc, char* argv[]);
int dump_ilog(int argc, char* argv[]);
int dump_meta(int argc, char* argv[]);
void print_usage();
int parse_options(int argc, char* argv[]);
......@@ -42,7 +43,7 @@ private:
int grep(int argc, char* argv[]);
int encode_int(char* buf, int64_t& pos, int64_t buf_len, const char* encode_type, int64_t int_value);
int dump_single_clog(const char* path, bool is_hex);
int dump_single_clog(const char* path, bool is_hex, bool without_data);
int dump_single_ilog(const char* path);
int dump_format_single_file(const char* path);
int stat_single_log(const char* path);
......
......@@ -220,7 +220,7 @@ int ObLogEntryParser::get_type_(ObCLogItemType& type)
return ret;
}
int ObLogEntryParser::dump_all_entry(bool is_hex)
int ObLogEntryParser::dump_all_entry(bool is_hex, bool without_data)
{
int ret = OB_SUCCESS;
if (OB_UNLIKELY(!is_inited_)) {
......@@ -228,6 +228,7 @@ int ObLogEntryParser::dump_all_entry(bool is_hex)
CLOG_LOG(ERROR, "log entry parser is not inited", K(is_inited_), K(ret));
} else {
dump_hex_ = is_hex;
without_data_ = without_data;
while (OB_SUCC(ret)) {
if (OB_FAIL(parse_next_entry())) {
if (OB_ITER_END != ret) {
......@@ -690,7 +691,9 @@ int ObLogEntryParserImpl::dump_memtable_mutator(const char* buf, int64_t len)
ret = OB_SUCCESS;
break;
} else {
if (dump_hex_) {
if (without_data_) {
fprintf(stdout, " MutatorRow={*} | OLD_ROW={");
} else if (dump_hex_) {
int64_t pos = row.rowkey_.to_smart_string(print_buf_, PRINT_BUF_SIZE - 1);
print_buf_[pos] = '\0';
fprintf(stdout, " MutatorRow={%s} HexedRowkey={%s} | OLD_ROW={", to_cstring(row), print_buf_);
......@@ -1444,7 +1447,9 @@ int ObLogEntryParserImpl::dump_freeze_log(const char* buf, const int64_t buf_len
int ObLogEntryParserImpl::dump_obj(const common::ObObj& obj, uint64_t column_id)
{
int ret = OB_SUCCESS;
if (dump_hex_) {
if (without_data_) {
fprintf(stdout, "*");
} else if (dump_hex_) {
int64_t buf_len = PRINT_BUF_SIZE - 1; // reserver one character for '\0'
int64_t pos = 0;
if (OB_UNLIKELY(!is_inited_)) {
......
......@@ -107,6 +107,7 @@ public:
ObLogEntryParserImpl()
: is_inited_(false),
dump_hex_(false),
without_data_(false),
file_id_(-1),
cur_offset_(OB_INVALID_OFFSET),
print_buf_(NULL),
......@@ -178,6 +179,7 @@ protected:
static const int64_t PRINT_BUF_SIZE = 5 * 1024 * 1024;
bool is_inited_;
bool dump_hex_;
bool without_data_;
uint64_t file_id_;
int64_t cur_offset_;
ObTransID cur_trans_id_;
......@@ -199,7 +201,7 @@ public:
int init(uint64_t file_id, char* buf, int64_t buf_len, const ObLogEntryFilter& filter, const common::ObString& host,
const int32_t port, const char* config_file, const bool is_ofs);
int dump_all_entry(bool is_hex);
int dump_all_entry(bool is_hex, bool without_data);
int format_dump_entry();
int stat_log();
const ObLogStat& get_log_stat() const
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册