Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: XiaoMi/rdsn
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 02654dff1aa8d743616e4ee16bbbc8b494a9cc28
Choose a base ref
..
head repository: XiaoMi/rdsn
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 674c417551b749279d6bd145487f716dd7313f6e
Choose a head ref
Showing with 15 additions and 37 deletions.
  1. +12 −15 src/replica/duplication/test/load_from_private_log_test.cpp
  2. +3 −4 src/replica/mutation_log_replay.cpp
  3. +0 −15 src/replica/mutation_log_utils.cpp
  4. +0 −3 src/replica/mutation_log_utils.h
27 changes: 12 additions & 15 deletions src/replica/duplication/test/load_from_private_log_test.cpp
Original file line number Diff line number Diff line change
@@ -24,7 +24,6 @@ class load_from_private_log_test : public duplication_test_base
public:
load_from_private_log_test()
{
utils::filesystem::remove_path(_log_dir);
_replica->init_private_log(_log_dir);
duplicator = create_test_duplicator();
}
@@ -202,43 +201,39 @@ class load_from_private_log_test : public duplication_test_base
_replica->dir(), private_log_size_mb, id, _replica.get(), 1024, 512, 10000);
error_code err = mlog->open(cb, nullptr, replay_condition);
if (err == ERR_OK) {
return mlog;
break;
}
derror_f("mlog open failed, encountered error: {}, try count: {}", err, try_cnt);
derror_f("mlog open failed, encountered error: {}", err);
}
return nullptr;
return mlog;
}

void test_restart_duplication2()
{
std::string tmp_file_path = "./log.tmp";
boost::filesystem::remove(tmp_file_path);

load_from_private_log load(_replica.get(), duplicator.get());

// create a log file indexed 3, starting from 38200
for (int f = 0; f < 3; f++) {
mutation_log_ptr mlog = create_private_log();
ASSERT_NE(mlog, nullptr);
for (int i = 0; i < 100; i++) {
std::string msg = "hello!";
mutation_ptr mu = create_test_mutation(38000 + 100 * f + i, msg);
mlog->append(mu, LPC_AIO_IMMEDIATE_CALLBACK, nullptr, nullptr, 0);
}
mlog->tracker()->wait_outstanding_tasks();
ASSERT_EQ(open_log_file_map(_log_dir).size(), f + 1);
}
auto files1 = open_log_file_map(_log_dir);
ASSERT_EQ(files1.size(), 3);
boost::filesystem::remove(files1[1]->path());
boost::filesystem::remove(files1[2]->path());
// temporarily keep the new file under the working dir for later usage.
boost::filesystem::rename(files1[3]->path(), tmp_file_path);
boost::filesystem::rename(
files1[3]->path(),
fmt::format("./log.{}.{}", files1[3]->index(), files1[3]->start_offset()));

// initiates a clean log dir, the first log starts from 39100
// first log is 39100
{
for (int f = 0; f < 2; f++) {
mutation_log_ptr mlog = create_private_log();
ASSERT_NE(mlog, nullptr);
for (int i = 0; i < 100; i++) {
std::string msg = "hello!";
mutation_ptr mu = create_test_mutation(39000 + 100 * f + i, msg);
@@ -253,13 +248,15 @@ class load_from_private_log_test : public duplication_test_base
// This test simulates the following case:
// the replica has written logs [39100 -> 39199], but after some sort of failure,
// it became learner and copied plogs starting from 38200.
boost::filesystem::rename(tmp_file_path, files1[3]->path());
boost::filesystem::rename(
fmt::format("./log.{}.{}", files1[3]->index(), files1[3]->start_offset()),
files1[3]->path());
}

// log.2.xxx starts from 39100
// log.3.xxx starts from 38200
// all log files are reserved for duplication
mutation_log_ptr mlog = create_private_log();
ASSERT_NE(mlog, nullptr) << log_utils::list_files_to_string(open_log_file_map(_log_dir));
auto files = mlog->get_log_file_map();
ASSERT_EQ(files.size(), 2);

7 changes: 3 additions & 4 deletions src/replica/mutation_log_replay.cpp
Original file line number Diff line number Diff line change
@@ -151,10 +151,9 @@ namespace replication {
log_file_ptr &log = kv.second;

if (log->start_offset() != end_offset) {
derror_f("offset mismatch in log file ({}) offset and global offset: {} vs {}",
log->path(),
log->start_offset(),
end_offset);
derror("offset mismatch in log file offset and global offset %" PRId64 " vs %" PRId64,
log->start_offset(),
end_offset);
return ERR_INVALID_DATA;
}

15 changes: 0 additions & 15 deletions src/replica/mutation_log_utils.cpp
Original file line number Diff line number Diff line change
@@ -93,21 +93,6 @@ error_s check_log_files_continuity(const std::map<int, log_file_ptr> &logs)
return error_s::ok();
}

/*extern*/ std::string list_files_to_string(const std::map<int, log_file_ptr> &logs)
{
bool first = true;
std::string all_log_files_str;
for (const auto &id_file : logs) {
if (!first) {
all_log_files_str += ", ";
}
first = false;
all_log_files_str +=
fmt::format("log.{}.{}", id_file.second->index(), id_file.second->start_offset());
}
return all_log_files_str;
}

} // namespace log_utils
} // namespace replication
} // namespace dsn
3 changes: 0 additions & 3 deletions src/replica/mutation_log_utils.h
Original file line number Diff line number Diff line change
@@ -77,9 +77,6 @@ inline error_s check_log_files_continuity(const std::string &dir)
return check_log_files_continuity(log_file_map) << "check_log_files_continuity(dir)";
}

//
extern std::string list_files_to_string(const std::map<int, log_file_ptr> &logs);

} // namespace log_utils
} // namespace replication
} // namespace dsn