8000 State has to keep log for removeConflicts and acoording log all the w… · MohammedDeveloper/arangodb@3700f75 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3700f75

Browse files
kvahedfceller
authored andcommitted
State has to keep log for removeConflicts and acoording log all the way (arangodb#3249)
1 parent 111c826 commit 3700f75

File tree

3 files changed

+29
-39
lines changed

3 files changed

+29
-39
lines changed

arangod/Agency/Agent.cpp

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -397,30 +397,18 @@ bool Agent::recvAppendEntriesRPC(
397397

398398
_liLock.assertNotLockedByCurrentThread();
399399
MUTEX_LOCKER(ioLocker, _ioLock);
400-
401-
size_t ndups = _state.removeConflicts(queries, gotSnapshot);
402-
403-
if (nqs > ndups) {
404-
LOG_TOPIC(DEBUG, Logger::AGENCY)
405-
<< "Appending " << nqs - ndups << " entries to state machine. ("
406-
<< nqs << ", " << ndups << "): " << payload.toJson() ;
407-
408-
try {
409400

410-
MUTEX_LOCKER(ioLocker, _liLock);
411-
_lastApplied = _state.log(queries, ndups);
412-
if (_lastApplied < payload[nqs-1].get("index").getNumber<index_t>()) {
413-
// We could not log all the entries in this query, we need to report
414-
// this to the leader!
415-
ok = false;
416-
}
417-
418-
} catch (std::exception const& e) {
419-
LOG_TOPIC(DEBUG, Logger::AGENCY)
420-
<< "Exception during log append: " << __FILE__ << __LINE__
421-
<< " " << e.what();
401+
try {
402+
_lastApplied = _state.log(queries, gotSnapshot);
403+
if (_lastApplied < payload[nqs-1].get("index").getNumber<index_t>()) {
404+
// We could not log all the entries in this query, we need to report
405+
// this to the leader!
406+
ok = false;
422407
}
423-
408+
} catch (std::exception const& e) {
409+
LOG_TOPIC(DEBUG, Logger::AGENCY)
410+
<< "Exception during log append: " << __FILE__ << __LINE__
411+
<< " " << e.what();
424412
}
425413
}
426414

arangod/Agency/State.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -232,29 +232,32 @@ index_t State::logNonBlocking(
232232
}
233233

234234
/// Log transactions (follower)
235-
index_t State::log(query_t const& transactions, size_t ndups) {
236-
VPackSlice slices = transactions->slice();
237-
238-
TRI_ASSERT(slices.isArray());
235+
index_t State::log(query_t const& transactions, bool gotSnapshot) {
239236

237+
VPackSlice slices = transactions->slice();
240238
size_t nqs = slices.length();
241239

242-
TRI_ASSERT(nqs > ndups);
243-
std::string clientId;
240+
MUTEX_LOCKER(logLock, _logLock);
244241

245-
MUTEX_LOCKER(mutexLocker, _logLock); // log entries must stay in order
242+
size_t ndups = removeConflicts(transactions, gotSnapshot);
246243

247-
for (size_t i = ndups; i < nqs; ++i) {
248-
VPackSlice const& slice = slices[i];
244+
if (nqs > ndups) {
245+
VPackSlice slices = transactions->slice();
246+
TRI_ASSERT(slices.isArray());
247+
size_t nqs = slices.length();
248+
std::string clientId;
249249

250-
// first to disk
251-
if (logNonBlocking(
252-
slice.get("index").getUInt(), slice.get("query"),
253-
slice.get("term").getUInt(), slice.get("clientId").copyString())==0) {
254-
break;
250+
for (size_t i = ndups; i < nqs; ++i) {
251+
252+
VPackSlice const& slice = slices[i];
253+
// first to disk
254+
if (logNonBlocking(
255+
slice.get("index").getUInt(), slice.get("query"),
256+
slice.get("term").getUInt(), slice.get("clientId").copyString())==0) {
257+
break;
258+
}
255259
}
256260
}
257-
258261
return _log.empty() ? 0 : _log.back().index;
259262
}
260263

@@ -274,7 +277,6 @@ size_t State::removeConflicts(query_t const& transactions, bool gotSnapshot) {
274277

275278
LOG_TOPIC(TRACE, Logger::AGENCY) << "removeConflicts " << slices.toJson();
276279
try {
277-
MUTEX_LOCKER(logLock, _logLock);
278280

279281
index_t lastIndex = (!_log.empty()) ? _log.back().index : 0;
280282

arangod/Agency/State.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class State {
7171
std::string const& clientId = std::string());
7272

7373
/// @brief Log entries (followers)
74-
arangodb::consensus::index_t log(query_t const& queries, size_t ndups = 0);
74+
arangodb::consensus::index_t log(query_t const&, bool);
7575

7676
/// @brief Find entry at index with term
7777
bool find(index_t index, term_t term);

0 commit comments

Comments
 (0)
0