Skip to content

Commit

Permalink
dump plog tool
Browse files Browse the repository at this point in the history
  • Loading branch information
acelyc111 committed Dec 7, 2023
1 parent d74c7a7 commit c154745
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/replica/mutation.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class replica;
class mutation_queue
{
public:
explicit mutation_queue() {}
mutation_queue(gpid gpid, int max_concurrent_op = 2, bool batch_write_disabled = false);

~mutation_queue()
Expand Down
4 changes: 2 additions & 2 deletions src/replica/mutation_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,14 @@ void mutation_log_private::commit_pending_mutations(log_file_ptr &lf,
mutation_log::mutation_log(const std::string &dir, int32_t max_log_file_mb, gpid gpid, replica *r)
{
_dir = dir;
_is_private = (gpid.value() != 0);
_is_private = true;
_max_log_file_size_in_bytes = static_cast<int64_t>(max_log_file_mb) * 1024L * 1024L;
_min_log_file_size_in_bytes = _max_log_file_size_in_bytes / 10;
_owner_replica = r;
_private_gpid = gpid;

if (r) {
CHECK_EQ(_private_gpid, r->get_gpid());
// CHECK_EQ(_private_gpid, r->get_gpid());
}
mutation_log::init_states();
}
Expand Down
12 changes: 12 additions & 0 deletions src/replica/replica.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ DSN_DECLARE_int32(checkpoint_max_interval_hours);

const std::string replica::kAppInfo = ".app-info";

replica::replica()
: serverlet<replica>("replica"),
replica_base(),
_primary_states(),
_potential_secondary_states(this)
{
}

replica::replica(replica_stub *stub,
gpid gpid,
const app_info &app,
Expand Down Expand Up @@ -468,6 +476,10 @@ bool replica::verbose_commit_log() const { return _stub->_verbose_commit_log; }

void replica::close()
{
if (status() == partition_status::PS_INVALID) {
return;
}

CHECK_PREFIX_MSG(status() == partition_status::PS_ERROR ||
status() == partition_status::PS_INACTIVE ||
_disk_migrator->status() == disk_migration_status::IDLE ||
Expand Down
4 changes: 4 additions & 0 deletions src/replica/replica.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class learn_notify_response;
class learn_request;
class learn_response;
class learn_state;
class mutation_log_tool;
class replica;
class replica_backup_manager;
class replica_bulk_loader;
Expand Down Expand Up @@ -304,6 +305,8 @@ class replica : public serverlet<replica>, public ref_counter, public replica_ba
dir_node *dn,
bool need_restore,
bool is_duplication_follower = false);

explicit replica();
error_code initialize_on_new();
error_code initialize_on_load();
error_code init_app_and_prepare_list(bool create_new);
Expand Down Expand Up @@ -523,6 +526,7 @@ class replica : public serverlet<replica>, public ref_counter, public replica_ba

private:
friend class ::dsn::replication::test::test_checker;
friend class mutation_log_tool;
friend class ::dsn::replication::mutation_queue;
friend class ::dsn::replication::replica_stub;
friend class mock_replica;
Expand Down
2 changes: 2 additions & 0 deletions src/replica/replica_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ struct replica_base
{
}

explicit replica_base() {}

gpid get_gpid() const { return _gpid; }

const char *replica_name() const { return _name.c_str(); }
Expand Down
1 change: 1 addition & 0 deletions src/replica/replica_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ typedef std::unordered_map<::dsn::rpc_address, remote_learner_state> learner_map
class primary_context
{
public:
explicit primary_context() {}
primary_context(gpid gpid, int max_concurrent_2pc_count = 1, bool batch_write_disabled = false)
: next_learning_version(0),
write_queue(gpid, max_concurrent_2pc_count, batch_write_disabled),
Expand Down
6 changes: 5 additions & 1 deletion src/tools/mutation_log_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "consensus_types.h"
#include "replica/mutation.h"
#include "replica/mutation_log.h"
#include "replica/replica.h"
#include "runtime/rpc/rpc_message.h"
#include "runtime/task/task_spec.h"
#include "utils/autoref_ptr.h"
Expand All @@ -53,8 +54,10 @@ bool mutation_log_tool::dump(
std::function<void(int64_t decree, int64_t timestamp, dsn::message_ex **requests, int count)>
callback)
{
app_info ai;
auto rep = new replica();
auto mlog = std::make_shared<mutation_log_private>(
log_dir, FLAGS_log_private_file_size_mb, gpid(0, 0), nullptr);
log_dir, FLAGS_log_private_file_size_mb, gpid(2, 0), rep);
error_code err = mlog->open(
[mlog, &output, callback](int log_length, mutation_ptr &mu) -> bool {
if (mlog->max_decree(mu->data.header.pid) == 0) {
Expand Down Expand Up @@ -97,6 +100,7 @@ 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;
return false;
Expand Down

0 comments on commit c154745

Please sign in to comment.