Start from committed plus 1

This commit is contained in:
alesapin 2021-03-02 18:58:02 +03:00
parent 346d2b1d27
commit ee185bc536
2 changed files with 13 additions and 2 deletions

View File

@ -174,6 +174,7 @@ public:
readIntBinary(record.header.term, read_buf);
readIntBinary(record.header.value_type, read_buf);
readIntBinary(record.header.blob_size, read_buf);
std::cerr << "RECORD INDEX:" << record.header.index << std::endl;
if (record.header.version > CURRENT_CHANGELOG_VERSION)
throw Exception(ErrorCodes::UNKNOWN_FORMAT_VERSION, "Unsupported changelog version {} on path {}", record.header.version, filepath);
@ -192,7 +193,6 @@ public:
throw Exception(ErrorCodes::CORRUPTED_DATA, "Previous log entry {}, next log entry {}, seems like some entries skipped", previous_index, record.header.index);
previous_index = record.header.index;
std::cerr << "PREVIOUS INDEX:" << previous_index << std::endl;
Checksum checksum = computeRecordChecksum(record);
if (checksum != record_checksum)
@ -207,8 +207,12 @@ public:
result.entries_read += 1;
std::cerr << "START:" << start_log_index << " RECORD: " << record.header.index << std::endl;
if (record.header.index < start_log_index)
{
std::cerr << "SKIPPING:" << record.header.index << std::endl;
continue;
}
auto log_entry = nuraft::cs_new<nuraft::log_entry>(record.header.term, record.blob, record.header.value_type);
@ -296,6 +300,12 @@ void Changelog::readChangelogAndInitWriter(size_t from_log_index)
throw Exception(ErrorCodes::CORRUPTED_DATA, "Required to read data from {}, but we don't have any active changelogs", from_log_index);
std::cerr << "START INDEX:" << start_index << std::endl;
std::cerr << "LOGS SIZE:" << logs.size() << std::endl;
for (const auto & [key, value] : logs)
{
std::cerr << "KEY:" << key << std::endl;
}
std::cerr << "NEXT" << getNextEntryIndex() << std::endl;
if (incomplete_log_index != 0)
{
/// All subsequent logs shouldn't exist. But they may exist if we crashed after writeAt started. Remove them.
@ -458,6 +468,7 @@ LogEntryPtr Changelog::getLastEntry() const
size_t next_index = getNextEntryIndex() - 1;
std::cerr << "NEXT INDEX:" << next_index << std::endl;
std::cerr << "START INDEX:" << start_index << std::endl;
std::cerr << "LOGS SIZE:" << logs.size() << std::endl;
auto entry = logs.find(next_index);
if (entry == logs.end())
return fake_entry;

View File

@ -36,7 +36,7 @@ void NuKeeperServer::startup()
state_machine->init();
state_manager->loadLogStore(state_machine->last_commit_index());
state_manager->loadLogStore(state_machine->last_commit_index() + 1);
bool single_server = state_manager->getTotalServers() == 1;
nuraft::raft_params params;