diff --git a/src/replica/mutation.h b/src/replica/mutation.h index d5b7f238ad..190d425e39 100644 --- a/src/replica/mutation.h +++ b/src/replica/mutation.h @@ -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() diff --git a/src/replica/mutation_log.cpp b/src/replica/mutation_log.cpp index c08ec6c5e2..0b8b2efea9 100644 --- a/src/replica/mutation_log.cpp +++ b/src/replica/mutation_log.cpp @@ -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(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(); } diff --git a/src/replica/replica.cpp b/src/replica/replica.cpp index 38cc478ad7..863fdb6532 100644 --- a/src/replica/replica.cpp +++ b/src/replica/replica.cpp @@ -92,6 +92,14 @@ DSN_DECLARE_int32(checkpoint_max_interval_hours); const std::string replica::kAppInfo = ".app-info"; +replica::replica() + : serverlet("replica"), + replica_base(), + _primary_states(), + _potential_secondary_states(this) +{ +} + replica::replica(replica_stub *stub, gpid gpid, const app_info &app, @@ -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 || diff --git a/src/replica/replica.h b/src/replica/replica.h index 68965a7d8c..9b363615a5 100644 --- a/src/replica/replica.h +++ b/src/replica/replica.h @@ -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; @@ -304,6 +305,8 @@ class replica : public serverlet, 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); @@ -523,6 +526,7 @@ class replica : public serverlet, 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; diff --git a/src/replica/replica_base.h b/src/replica/replica_base.h index 325f0905df..169b638650 100644 --- a/src/replica/replica_base.h +++ b/src/replica/replica_base.h @@ -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(); } diff --git a/src/replica/replica_context.h b/src/replica/replica_context.h index 32da41d38b..88fce667e3 100644 --- a/src/replica/replica_context.h +++ b/src/replica/replica_context.h @@ -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), diff --git a/src/tools/mutation_log_tool.cpp b/src/tools/mutation_log_tool.cpp index 96021e66a4..54dacafda8 100644 --- a/src/tools/mutation_log_tool.cpp +++ b/src/tools/mutation_log_tool.cpp @@ -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" @@ -53,8 +54,10 @@ bool mutation_log_tool::dump( std::function callback) { + app_info ai; + auto rep = new replica(); auto mlog = std::make_shared( - 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) { @@ -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;