Skip to content

Commit

Permalink
4
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Dec 8, 2023
1 parent 4ebbe21 commit 703bee2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 25 deletions.
10 changes: 5 additions & 5 deletions src/shell/commands/debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ bool local_get(command_executor *e, shell_context *sc, arguments args)
dsn::blob user_data;
pegasus::pegasus_extract_user_data(0, std::move(value), user_data);
fmt::print(stderr,
"{} : \"{}\"\n",
expire_ts,
pegasus::utils::c_escape_string(user_data, sc->escape_all));
"{} : \"{}\"\n",
expire_ts,
pegasus::utils::c_escape_string(user_data, sc->escape_all));
}

delete db;
Expand Down Expand Up @@ -335,7 +335,7 @@ bool rdb_value_hex2str(command_executor *e, shell_context *sc, arguments args)
dsn::blob user_data;
pegasus::pegasus_extract_user_data(0, std::move(pegasus_value), user_data);
fmt::print(stderr,
"user_data:\n \"{}\"\n",
pegasus::utils::c_escape_string(user_data.to_string(), sc->escape_all));
"user_data:\n \"{}\"\n",
pegasus::utils::c_escape_string(user_data.to_string(), sc->escape_all));
return true;
}
3 changes: 2 additions & 1 deletion src/shell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ static command_executor commands[] = {
{
"mlog_dump",
"dump mutation log dir",
"<-i|--input log_dir(e.g. '/path/to/replica/reps/2.1.pegasus/plog/')> [-o|--output file_name] [-d|--detailed]",
"<-i|--input log_dir(e.g. '/path/to/replica/reps/2.1.pegasus/plog/')> [-o|--output "
"file_name] [-d|--detailed]",
mlog_dump,
},
{
Expand Down
46 changes: 27 additions & 19 deletions src/tools/mutation_log_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "runtime/task/task_spec.h"
#include "utils/autoref_ptr.h"
#include "utils/blob.h"
#include "utils/defer.h"
#include "utils/error_code.h"
#include "utils/filesystem.h"
#include "utils/flags.h"
Expand All @@ -60,38 +61,46 @@ bool mutation_log_tool::dump(
{
std::string absolute_path;
if (!utils::filesystem::get_absolute_path(log_dir, absolute_path)) {
output << "ERROR: get absolute path failed" << std::endl;
output << fmt::format("ERROR: get absolute path failed\n");
return false;
}
std::string norm_path;
utils::filesystem::get_normalized_path(absolute_path, norm_path);
auto dn = std::make_shared<dir_node>("", norm_path);
auto dn = std::make_unique<dir_node>(/* tag_ */ "", norm_path);
app_info ai;
ai.__set_app_type("pegasus");
auto stub = std::make_shared<replica_stub>();
auto *rep = new replica(stub.get(), pid, ai, dn.get(), false, false);
auto stub = std::make_unique<replica_stub>();
// Constructor of replica is private which can not be accessed by std::make_unique, so use raw
// pointer here.
auto *rep = new replica(stub.get(),
pid,
ai,
dn.get(),
/* need_restore */ false,
/* is_duplication_follower */ false);
auto cleanup = dsn::defer([rep]() { delete rep; });
auto mlog =
std::make_shared<mutation_log_private>(log_dir, FLAGS_log_private_file_size_mb, pid, rep);
error_code err = mlog->open(
[mlog, &output, callback](int log_length, mutation_ptr &mu) -> bool {
std::cout << "1" << std::endl;
if (mlog->max_decree(mu->data.header.pid) == 0) {
mlog->set_valid_start_offset_on_open(mu->data.header.pid, 0);
}
char timestamp_buf[32] = {0};
utils::time_ms_to_string(mu->data.header.timestamp / 1000, timestamp_buf);
output << "mutation [" << mu->name() << "]: "
<< "gpid=" << mu->data.header.pid.get_app_id() << "."
<< mu->data.header.pid.get_partition_index() << ", "
<< "ballot=" << mu->data.header.ballot << ", decree=" << mu->data.header.decree
<< ", "
<< "timestamp=" << timestamp_buf
<< ", last_committed_decree=" << mu->data.header.last_committed_decree << ", "
<< "log_offset=" << mu->data.header.log_offset << ", log_length=" << log_length
<< ", "
<< "update_count=" << mu->data.updates.size();
if (callback && mu->data.updates.size() > 0) {

output << fmt::format("mutation [{}]: gpid={}, ballot={}, decree={}, timestamp={}, "
"last_committed_decree={}, log_offset={}, log_length={}, "
"update_count={}\n",
mu->name(),
mu->data.header.pid,
mu->data.header.ballot,
mu->data.header.decree,
timestamp_buf,
mu->data.header.last_committed_decree,
mu->data.header.log_offset,
log_length,
mu->data.updates.size());
if (callback && !mu->data.updates.empty()) {
dsn::message_ex **batched_requests =
(dsn::message_ex **)alloca(sizeof(dsn::message_ex *) * mu->data.updates.size());
int batched_count = 0;
Expand All @@ -115,9 +124,8 @@ bool mutation_log_tool::dump(
},
nullptr);
mlog->close();
delete rep;
if (err != dsn::ERR_OK) {
output << "ERROR: dump mutation log failed, err = " << err.to_string() << std::endl;
output << fmt::format("ERROR: dump mutation log failed, err = {}\n", err);
return false;
} else {
return true;
Expand Down

0 comments on commit 703bee2

Please sign in to comment.