8000 Bug fix/agency restart after compaction and holes in log by kvahed · Pull Request #3413 · arangodb/arangodb · GitHub
[go: up one dir, main page]

Skip to content

Bug fix/agency restart after compaction and holes in log #3413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Prev Previous commit
Fix loadRemaining.
  • Loading branch information
neunhoef committed Oct 13, 2017
commit 52d990b755508b7b1b38e33fa3528f22f1a97b8d
47 changes: 26 additions & 21 deletions arangod/Agency/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,8 @@ bool State::loadRemaining() {

TRI_ASSERT(_log.empty()); // was cleared in loadCompacted
std::string clientId;
// We know that _cur has been set in loadCompacted to the index of the
// snapshot that was loaded or to 0 if there is no snapshot.
index_t lastIndex = _cur;
for (auto const& i : VPackArrayIterator(result)) {

Expand All @@ -882,39 +884,42 @@ bool State::loadRemaining() {
ii.get(StaticStrings::KeyString).copyString()));
term_t term(ii.get("term").getNumber<uint64_t>());

// Ignore log entries, which are older than compaction index _cur
if (index > _cur) {
// Ignore log entries, which are older than lastIndex:
if (index >= lastIndex) {

// Empty pacthes :
// 1 LastIndex initially 0 so that we know this is the first iteration
// 2 index > lastIndex always so that index-lastIndex does not overflow!
if (lastIndex > 0 && index > lastIndex && index-lastIndex > 1) {
// Empty patches :
if (index > lastIndex + 1) {
std::shared_ptr<Buffer<uint8_t>> buf =
std::make_shared<Buffer<uint8_t>>();
VPackSlice value = arangodb::basics::VelocyPackHelper::EmptyObjectValue();
buf->append(value.startAs<char const>(), value.byteSize());
for (index_t i = lastIndex+1; i < index; ++i) {
LOG_TOPIC(WARN, Logger::AGENCY) << "Missing index " << i << " in RAFT log.";
_log.push_back(log_t(i, term, buf, std::string()));
lastIndex = i;
}
// After this loop, index will be lastIndex + 1
}

// Real entries
try {
_log.push_back(
log_t(
basics::StringUtils::uint64(
ii.get(StaticStrings::KeyString).copyString()),
ii.get("term").getNumber<uint64_t>(), tmp, clientId));
} catch (std::exception const& e) {
LOG_TOPIC(ERR, Logger::AGENCY)
<< "Failed to convert " +
ii.get(StaticStrings::KeyString).copyString() +
" to integer."
<< e.what();
}
if (index == lastIndex + 1 ||
(index == lastIndex && _log.empty())) {
// Real entries
try {
_log.push_back(
log_t(
basics::StringUtils::uint64(
ii.get(StaticStrings::KeyString).copyString()),
ii.get("term").getNumber<uint64_t>(), tmp, clientId));
} catch (std::exception const& e) {
LOG_TOPIC(ERR, Logger::AGENCY)
<< "Failed to convert " +
ii.get(StaticStrings::KeyString).copyString() +
" to integer."
<< e.what();
}

lastIndex = index;
lastIndex = index;
}
}

}
Expand Down
0