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
Next Next commit
State fixes holes in RAFT index range
  • Loading branch information
kvahed committed Oct 13, 2017
commit e251d6687bffddfb22f956a39e4e08937aa56140
19 changes: 19 additions & 0 deletions arangod/Agency/State.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ bool State::loadRemaining() {

TRI_ASSERT(_log.empty()); // was cleared in loadCompacted
std::string clientId;
index_t lastIndex = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lastIndex should probably be initialized with _cur, which has been set to the index of the latest snapshot in loadCompacted just before loadRemaining was called. I think 0 is wrong if there is a persisted snapshot.

for (auto const& i : VPackArrayIterator(result)) {

buffer_t tmp = std::make_shared<arangodb::velocypack::Buffer<uint8_t>>();
Expand All @@ -876,6 +877,21 @@ bool State::loadRemaining() {
clientId = req.hasKey("clientId") ?
req.get("clientId").copyString() : std::string();

// Dummy fill missing entries (Not good at all.)
index_t index(basics::StringUtils::uint64(
ii.get(StaticStrings::KeyString).copyString()));
term_t term(ii.get("term").getNumber<uint64_t>());
if (lastIndex > 0 && index-lastIndex > 1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not very robust. Why lastIndex > 0? How do we know that index >= lastIndex and there is no overflow? If index < lastIndex, we must not append at all. If index == lastIndex, we must append if and only if _log is still empty. If index == lastIndex+1 we must append normally and move lastIndex one up. If index > lastindex+1, then we must insert empty entries until index == lastIndex+1.
Note that in all the formulae I typed here there can never be an overflow.

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()));
}
}

try {
_log.push_back(
log_t(
Expand All @@ -889,6 +905,9 @@ bool State::loadRemaining() {
" to integer."
<< e.what();
}

lastIndex = index;

}
}
if (_log.empty()) {
Expand Down
0