Skip to content
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

Agency Node Refactor #19312

Merged
merged 76 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
c662b38
Remove ttl and observe support.
May 26, 2023
4cd4a1d
Fixing tests.
May 30, 2023
38b6503
Rename operator= to loadFromVelocyPack. Fixing assertion.
May 30, 2023
918c66b
Remove unused code.
May 30, 2023
aea3559
Update CHANGELOG.
May 30, 2023
ea11e65
Merge remote-tracking branch 'origin/devel' into feature/remove-ttl-a…
May 30, 2023
0943319
Merge remote-tracking branch 'origin/devel' into feature/remove-ttl-a…
May 30, 2023
e1946bc
Remove agent* from Store.
May 30, 2023
79a8fbc
Fixing more tests.
May 30, 2023
cd1fffc
Fixing unit tests.
May 30, 2023
310ab16
Fixing windows compile.
May 30, 2023
ccd68eb
Merge remote-tracking branch 'origin/devel' into feature/remove-ttl-a…
May 30, 2023
fb4481a
Merge remote-tracking branch 'origin/devel' into feature/remove-ttl-a…
Jun 14, 2023
6a38fdc
Code cleanup.
Jun 16, 2023
e3e0454
Remove callback bin.
Jun 17, 2023
5c8fb4b
Make Node.h less widely included.
Jun 17, 2023
d8d00a9
Initial refactoring. still broken.
Jun 17, 2023
c4b53df
Fixing nodes.
Jun 19, 2023
2ad3571
Make constructors private.
Jun 19, 2023
7d54a07
Fixing some node tests.
Jun 20, 2023
d1e631e
More fixed tests.
Jun 21, 2023
9826729
Fixing even more tests.
Jun 21, 2023
663c73b
More tests.
Jun 21, 2023
60a55af
And even more test fixes.
Jun 21, 2023
9f2c614
More tests fixed.
Jun 23, 2023
2578fb3
Fixed yet another test.
Jun 23, 2023
5d79f49
More tests.
Jun 23, 2023
25d3489
More fixed tests.
Jun 23, 2023
a07a6e5
Second to last test fixed.
Jun 23, 2023
213a089
Fix final test.
Jun 23, 2023
88c3420
Merge remote-tracking branch 'origin/devel' into feature/agency-node-…
Jun 23, 2023
40a2c43
Supervision cleanup.
Jun 26, 2023
58655d7
Merge remote-tracking branch 'origin/devel' into feature/agency-node-…
Jun 26, 2023
c6e7930
Merge remote-tracking branch 'origin/devel' into feature/remove-ttl-a…
Jun 26, 2023
178d03c
Merge remote-tracking branch 'origin/feature/remove-ttl-and-observe' …
Jun 26, 2023
c7cc644
Make explicit copy in store.
Jun 26, 2023
7e819be
Merge remote-tracking branch 'origin/feature/remove-ttl-and-observe' …
Jun 26, 2023
3361011
Fix compilation.
Jun 26, 2023
6175d59
Fixing ResultT constructor.
Jun 26, 2023
8e5fb8f
Fixing push-queue.
Jun 26, 2023
6ec4e06
Reuse nodes for readDB.
Jun 27, 2023
a48f99c
Fixing more jobs.
Jun 27, 2023
54b1c3f
Optimize operations.
Jun 27, 2023
18d2f7f
Revert "Reuse nodes for readDB."
Jun 27, 2023
2e65eaf
Fixing msvc warnings.
Jun 27, 2023
bebadf6
Merge remote-tracking branch 'origin/devel' into feature/remove-ttl-a…
Jun 27, 2023
285ef97
Remove unnecessary include.
Jun 27, 2023
d46f300
Fixing another test.
Jun 28, 2023
e2a94ac
Merge remote-tracking branch 'origin/feature/remove-ttl-and-observe' …
Jun 28, 2023
72aafc3
Revert change.
Jun 28, 2023
40d7faf
Fixing more bugs.
Jun 28, 2023
ae08423
Update velocypack.
Jun 28, 2023
f44a146
Fixing asan issue.
Jun 29, 2023
a34b38a
Merge remote-tracking branch 'origin/devel' into feature/remove-ttl-a…
Jul 5, 2023
05b61f3
Merge branch 'feature/remove-ttl-and-observe' into feature/agency-nod…
Jul 5, 2023
8fac4bf
Remove hasAsNode.
Jul 11, 2023
c82bb5a
Remove hasAsSlice and slice().
Jul 11, 2023
f598f16
Code cleanup.
Jul 11, 2023
48aab14
Adding nullNode.
Jul 11, 2023
6cec768
Merge remote-tracking branch 'origin/devel' into feature/remove-ttl-a…
Jul 11, 2023
5a45db3
Merge remote-tracking branch 'origin/feature/remove-ttl-and-observe' …
Jul 11, 2023
4cb5684
Merge remote-tracking branch 'origin/devel' into feature/agency-node-…
Jul 11, 2023
1230885
Remove support for slahes in keys.
Jul 11, 2023
5592cc7
Remove unused var.
Jul 11, 2023
951d1de
Merge remote-tracking branch 'origin/devel' into feature/remove-ttl-a…
Jul 11, 2023
7cf9b85
Merge branch 'feature/remove-ttl-and-observe' into feature/agency-nod…
Jul 11, 2023
9ffeb71
Clean up.
Jul 11, 2023
9e81543
Fixing more tests.
Jul 12, 2023
4b5de4f
Fix triggers in value-only special case.
Jul 13, 2023
5391ac1
Update arangod/Agency/NodeLoadInspector.h
Jul 13, 2023
48652d1
Fixing tests again.
Jul 13, 2023
9a70b84
Merge remote-tracking branch 'origin/devel' into feature/remove-ttl-a…
Jul 17, 2023
3c346b2
Merge remote-tracking branch 'origin/feature/remove-ttl-and-observe' …
Jul 17, 2023
6b6c769
Merge remote-tracking branch 'origin/devel' into feature/remove-ttl-a…
Jul 17, 2023
358cc93
Merge remote-tracking branch 'origin/feature/remove-ttl-and-observe' …
Jul 17, 2023
6c2d376
Update velocypack.
Jul 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Reuse nodes for readDB."
This reverts commit 6ec4e06.
  • Loading branch information
Lars Maier committed Jun 27, 2023
commit 18d2f7f07adb03c52f2d13c7a3241643c37f29ac
43 changes: 13 additions & 30 deletions arangod/Agency/Agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#include "Agency/AgencyFeature.h"
#include "Agency/AgentCallback.h"
#include "Agency/Node.h"
#include "Agency/Supervision.h"
#include "ApplicationFeatures/ApplicationServer.h"
#include "Basics/ReadLocker.h"
Expand Down Expand Up @@ -949,6 +948,8 @@ void Agent::advanceCommitIndex() {
std::sort(temp.begin(), temp.end());
index_t index = temp[temp.size() - quorum];

term_t t = _constituent.term();

auto ci = _commitIndex.load(std::memory_order_relaxed);
auto slices = _state.slices(ci + 1, index);
{
Expand All @@ -960,11 +961,8 @@ void Agent::advanceCommitIndex() {
<< "Critical mass for commiting " << ci + 1 << " through " << index
<< " to read db";

auto node = _inflightNodes.find(index);
ADB_PROD_ASSERT(node != _inflightNodes.end())
<< "inflight did not contain index " << index;
_readDB.setRootNode(node->second);
_inflightNodes.erase(_inflightNodes.begin(), ++node);
// Change _readDB and _commitIndex atomically together:
_readDB.applyLogEntries(slices, ci, t);

LOG_TOPIC("e24aa", DEBUG, Logger::AGENCY)
<< "Critical mass for commiting " << ci + 1 << " through " << index
Expand Down Expand Up @@ -1124,15 +1122,17 @@ void Agent::load() {
_supervision->start(this);
}

if (size() > 1) { // resilient agency only
TRI_ASSERT(_inception != nullptr);
if (_inception != nullptr) { // resilient agency only
_inception->start();
_loaded = true;
} else {
std::lock_guard guard{_ioLock}; // need this for callback to set _spearhead
READ_LOCKER(guard2, _outputLock);
_spearhead = _readDB;
activateAgency();
_loaded = true;
}

_loaded = true;
if (size() == 1) {
endPrepareLeadership();
}
}
Expand Down Expand Up @@ -1293,9 +1293,6 @@ trans_ret_t Agent::transact(velocypack::Slice qs) {
? _state.logLeaderSingle(query[0], currentTerm,
query[2].copyString())
: _state.logLeaderSingle(query[0], currentTerm);
ADB_PROD_ASSERT(_inflightNodes.empty() ||
_inflightNodes.rbegin()->first < maxind);
_inflightNodes.emplace(maxind, _spearhead.nodePtr());
ret->add(VPackValue(maxind));
} else {
_spearhead.read(res.failed->slice(), *ret);
Expand Down Expand Up @@ -1487,23 +1484,9 @@ write_ret_t Agent::write(velocypack::Slice query, WriteMode const& wmode) {

std::lock_guard ioLocker{_ioLock};

std::vector<std::shared_ptr<Node const>> states;
applied = _spearhead.applyTransactions(chunk.slice(), wmode, &states);
auto indexes = _state.logLeaderMulti(chunk.slice(), applied, currentTerm);
ADB_PROD_ASSERT(states.size() == indexes.size())
<< "produced " << states.size() << " states, but got "
<< indices.size() << " indexes.";
for (std::size_t k = 0; k < states.size(); k++) {
if (indexes[k] == 0) {
continue;
}
ADB_PROD_ASSERT(_inflightNodes.empty() ||
_inflightNodes.rbegin()->first < indexes[k]);
auto [iter, inserted] =
_inflightNodes.emplace(indexes[k], std::move(states[k]));
ADB_PROD_ASSERT(inserted) << "duplicated log index " << indexes[k];
}
indices.insert(indices.end(), indexes.begin(), indexes.end());
applied = _spearhead.applyTransactions(chunk.slice(), wmode);
auto tmp = _state.logLeaderMulti(chunk.slice(), applied, currentTerm);
indices.insert(indices.end(), tmp.begin(), tmp.end());
}
_write_hist_msec.count(
duration<float, std::milli>(high_resolution_clock::now() - start)
Expand Down
3 changes: 0 additions & 3 deletions arangod/Agency/Agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,6 @@ class Agent final : public arangodb::ServerThread<ArangodServer>,
/// @brief Committed (read) kv-store
Store _readDB;

// TODO use a deque instead?
std::map<index_t, std::shared_ptr<Node const>> _inflightNodes;

/// @brief Committed (read) kv-store for transient data. This is
/// protected by the _transientLock mutex.
Store _transient;
Expand Down
2 changes: 1 addition & 1 deletion arangod/Agency/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ Node::Children const& Node::children() const {

Builder Node::toBuilder() const {
Builder builder;
toBuilder(builder, true);
toBuilder(builder);
return builder;
}

Expand Down
28 changes: 4 additions & 24 deletions arangod/Agency/Store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,10 @@ index_t Store::applyTransactions(std::vector<log_t> const& queries) {
/// Apply array of transactions multiple queries to store
/// Return vector of according success
std::vector<apply_ret_t> Store::applyTransactions(
VPackSlice query, Agent::WriteMode const& wmode,
std::vector<std::shared_ptr<Node const>>* states) {
VPackSlice query, Agent::WriteMode const& wmode) {
std::vector<apply_ret_t> success;

if (query.isArray()) {
if (states) {
states->reserve(query.length());
}
try {
for (auto const& i : VPackArrayIterator(query)) {
if (!wmode.privileged()) {
Expand All @@ -111,27 +107,16 @@ std::vector<apply_ret_t> Store::applyTransactions(
continue;
}
}
bool ok;

std::lock_guard storeLocker{_storeLock};
if (states) {
states->emplace_back(nullptr);
}
switch (i.length()) {
case 1: // No precondition
ok = applies(i[0]);
success.push_back(ok ? APPLIED : UNKNOWN_ERROR);
if (states) {
states->back() = _node;
}
success.push_back(applies(i[0]) ? APPLIED : UNKNOWN_ERROR);
break;
case 2: // precondition + uuid
case 3:
if (check(i[1]).successful()) {
ok = applies(i[0]);
success.push_back(ok ? APPLIED : UNKNOWN_ERROR);
if (states) {
states->back() = _node;
}
success.push_back(applies(i[0]) ? APPLIED : UNKNOWN_ERROR);
} else { // precondition failed
LOG_TOPIC("f6873", TRACE, Logger::AGENCY)
<< "Precondition failed!";
Expand Down Expand Up @@ -778,8 +763,3 @@ void Store::registerPrefixTrigger(std::string const& prefix,
std::vector<std::string> Store::split(std::string_view str) {
return Node::split(str);
}

void Store::setRootNode(std::shared_ptr<const Node> root) noexcept {
std::lock_guard storeLocker{_storeLock};
_node = std::move(root);
}
5 changes: 1 addition & 4 deletions arangod/Agency/Store.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ class Store {
/// in the next method.
std::vector<apply_ret_t> applyTransactions(
arangodb::velocypack::Slice query,
AgentInterface::WriteMode const& wmode = AgentInterface::WriteMode(),
std::vector<std::shared_ptr<Node const>>* states = nullptr);
AgentInterface::WriteMode const& wmode = AgentInterface::WriteMode());

index_t applyTransactions(std::vector<log_t> const& queries);

Expand Down Expand Up @@ -167,8 +166,6 @@ class Store {

void registerPrefixTrigger(std::string const& prefix, AgencyTriggerCallback);

void setRootNode(std::shared_ptr<Node const>) noexcept;

private:
/// @brief Apply single slice
bool applies(arangodb::velocypack::Slice const&);
Expand Down