From 485978e646b6c4a8c4b46d1658f15aea74d41a64 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 21 Apr 2016 15:51:26 +0200 Subject: [PATCH 1/8] fixed over-/underflow --- lib/Basics/RandomGenerator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Basics/RandomGenerator.cpp b/lib/Basics/RandomGenerator.cpp index 28426a0554..cea1531a5e 100644 --- a/lib/Basics/RandomGenerator.cpp +++ b/lib/Basics/RandomGenerator.cpp @@ -63,7 +63,7 @@ uint32_t RandomDevice::interval(uint32_t left, uint32_t right) { int32_t l = left + INT32_MIN; int32_t r = right + INT32_MIN; - return static_cast(random(l, r) - INT32_MIN); + return static_cast(static_cast(random(l, r)) - INT32_MIN); } int32_t RandomDevice::random(int32_t left, int32_t right) { From d5c2035b4a63fa9da834e3fef734adaca989399a Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 21 Apr 2016 15:51:40 +0200 Subject: [PATCH 2/8] fixed leak --- arangod/Dispatcher/DispatcherFeature.cpp | 4 ++++ arangod/Dispatcher/DispatcherFeature.h | 1 + 2 files changed, 5 insertions(+) diff --git a/arangod/Dispatcher/DispatcherFeature.cpp b/arangod/Dispatcher/DispatcherFeature.cpp index 163cd5589d..ce065100aa 100644 --- a/arangod/Dispatcher/DispatcherFeature.cpp +++ b/arangod/Dispatcher/DispatcherFeature.cpp @@ -54,6 +54,10 @@ DispatcherFeature::DispatcherFeature( startsAfter("WorkMonitor"); } +DispatcherFeature::~DispatcherFeature() { + delete _dispatcher; +} + void DispatcherFeature::collectOptions( std::shared_ptr options) { LOG_TOPIC(TRACE, Logger::STARTUP) << name() << "::collectOptions"; diff --git a/arangod/Dispatcher/DispatcherFeature.h b/arangod/Dispatcher/DispatcherFeature.h index 63ed5b9b15..69a25efe93 100644 --- a/arangod/Dispatcher/DispatcherFeature.h +++ b/arangod/Dispatcher/DispatcherFeature.h @@ -40,6 +40,7 @@ class DispatcherFeature final public: explicit DispatcherFeature(application_features::ApplicationServer* server); + ~DispatcherFeature(); public: void collectOptions(std::shared_ptr) override final; From c5ee12019ab4a856844ad3dd265463e1aa319922 Mon Sep 17 00:00:00 2001 From: hkernbach Date: Thu, 21 Apr 2016 16:44:56 +0200 Subject: [PATCH 3/8] scss --- .../system/_admin/aardvark/APP/frontend/scss/_newDashboard.scss | 1 + js/apps/system/_admin/aardvark/APP/frontend/scss/_resizing.scss | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/js/apps/system/_admin/aardvark/APP/frontend/scss/_newDashboard.scss b/js/apps/system/_admin/aardvark/APP/frontend/scss/_newDashboard.scss index 18e7f8d7bd..52919fe9c3 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/scss/_newDashboard.scss +++ b/js/apps/system/_admin/aardvark/APP/frontend/scss/_newDashboard.scss @@ -365,6 +365,7 @@ .dashboard-bar-chart-chart { @extend %pull-left; + padding-top: 10px; .nv-bar rect { fill-opacity: .8; diff --git a/js/apps/system/_admin/aardvark/APP/frontend/scss/_resizing.scss b/js/apps/system/_admin/aardvark/APP/frontend/scss/_resizing.scss index b7051a7c7a..5319c68146 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/scss/_resizing.scss +++ b/js/apps/system/_admin/aardvark/APP/frontend/scss/_resizing.scss @@ -319,7 +319,7 @@ .absolut { //line-height: ($int-height2 * 2 / 3) - 10px; line-height: 40px; - padding-top: 10px; + padding-top: 15px; width: ($int-width - (($int-width / 2) * 1.4)) - 6px; } } From db7041db1ebf4f726152cd6de255b3dade426def Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Thu, 21 Apr 2016 16:52:36 +0200 Subject: [PATCH 4/8] Fix transaction management in AgencyComm. --- arangod/Cluster/AgencyComm.cpp | 137 ++++++++++++++++++++------------- arangod/Cluster/AgencyComm.h | 64 +++++++++------ 2 files changed, 123 insertions(+), 78 deletions(-) diff --git a/arangod/Cluster/AgencyComm.cpp b/arangod/Cluster/AgencyComm.cpp index 270e583b04..9db466735f 100644 --- a/arangod/Cluster/AgencyComm.cpp +++ b/arangod/Cluster/AgencyComm.cpp @@ -74,55 +74,67 @@ AgencyOperation::AgencyOperation(std::string const& key, AgencyValueOperationTyp } ////////////////////////////////////////////////////////////////////////////// -/// @brief returns to full operation formatted as a vpack slice +/// @brief adds the operation formatted as an attribute in a vpack object ////////////////////////////////////////////////////////////////////////////// -std::shared_ptr AgencyOperation::toVelocyPack() const { - auto builder = std::make_shared(); +void AgencyOperation::toVelocyPack(VPackBuilder& builder) const { + builder.add(VPackValue(_key)); { - VPackArrayBuilder operation(builder.get()); - { - VPackObjectBuilder keyVPack(builder.get()); - builder->add(VPackValue(_key)); - { - VPackObjectBuilder valueOperation(builder.get()); - builder->add("op", VPackValue(_opType.toString())); - if (_opType.type == AgencyOperationType::VALUE) { - if (_opType.value == AgencyValueOperationType::OBSERVE - || _opType.value == AgencyValueOperationType::UNOBSERVE) { - builder->add("url", _value); - } else { - builder->add("new", _value); - } - if (_ttl > 0) { - builder->add("ttl", VPackValue(_ttl)); - } - } + VPackObjectBuilder valueOperation(&builder); + builder.add("op", VPackValue(_opType.toString())); + if (_opType.type == AgencyOperationType::VALUE) { + if (_opType.value == AgencyValueOperationType::OBSERVE + || _opType.value == AgencyValueOperationType::UNOBSERVE) { + builder.add("url", _value); + } else { + builder.add("new", _value); } - } - if (_precondition.type != AgencyOperationPrecondition::NONE) { - VPackObjectBuilder precondition(builder.get()); - builder->add(VPackValue(_key)); - { - VPackObjectBuilder preconditionDefinition(builder.get()); - { - switch(_precondition.type) { - case AgencyOperationPrecondition::EMPTY: - builder->add("oldEmpty", VPackValue(_precondition.empty)); - break; - case AgencyOperationPrecondition::VALUE: - builder->add("old", _precondition.value); - break; - // mop: useless compiler warning :S - case AgencyOperationPrecondition::NONE: - break; - } - } + if (_ttl > 0) { + builder.add("ttl", VPackValue(_ttl)); } } } +} - return builder; +////////////////////////////////////////////////////////////////////////////// +/// @brief constructs a precondition +////////////////////////////////////////////////////////////////////////////// + +AgencyPrecondition::AgencyPrecondition(std::string const& key, Type t, bool e) + : key(AgencyComm::prefix() + key), type(t), empty(e) { +} + +////////////////////////////////////////////////////////////////////////////// +/// @brief constructs a precondition +////////////////////////////////////////////////////////////////////////////// + +AgencyPrecondition::AgencyPrecondition(std::string const& key, Type t, + VPackSlice s) + : key(AgencyComm::prefix() + key), type(t), value(s) { +} + +////////////////////////////////////////////////////////////////////////////// +/// @brief adds the precondition formatted as an attribute in a vpack obj +////////////////////////////////////////////////////////////////////////////// + +void AgencyPrecondition::toVelocyPack(VPackBuilder& builder) const { + if (type != AgencyPrecondition::NONE) { + builder.add(VPackValue(key)); + { + VPackObjectBuilder preconditionDefinition(&builder); + switch(type) { + case AgencyPrecondition::EMPTY: + builder.add("oldEmpty", VPackValue(empty)); + break; + case AgencyPrecondition::VALUE: + builder.add("old", value); + break; + // mop: useless compiler warning :S + case AgencyPrecondition::NONE: + break; + } + } + } } ////////////////////////////////////////////////////////////////////////////// @@ -132,17 +144,32 @@ std::shared_ptr AgencyOperation::toVelocyPack() const { std::string AgencyTransaction::toJson() const { VPackBuilder builder; { - VPackArrayBuilder transaction(&builder); - { - for (AgencyOperation const& operation: operations) { - auto opBuilder = operation.toVelocyPack(); - builder.add(opBuilder->slice()); - } - } + VPackArrayBuilder guard(&builder); + toVelocyPack(builder); } return builder.toJson(); } +////////////////////////////////////////////////////////////////////////////// +/// @brief converts the transaction to velocypack +////////////////////////////////////////////////////////////////////////////// + +void AgencyTransaction::toVelocyPack(VPackBuilder& builder) const { + VPackArrayBuilder guard(&builder); + { + VPackObjectBuilder guard2(&builder); + for (AgencyOperation const& operation: operations) { + operation.toVelocyPack(builder); + } + } + if (preconditions.size() > 0) { + VPackObjectBuilder guard3(&builder); + for (AgencyPrecondition const& precondition: preconditions) { + precondition.toVelocyPack(builder); + } + } +} + //////////////////////////////////////////////////////////////////////////////// /// @brief creates an agency endpoint //////////////////////////////////////////////////////////////////////////////// @@ -1300,7 +1327,8 @@ AgencyCommResult AgencyComm::removeValues(std::string const& key, bool recursive) { AgencyCommResult result; AgencyTransaction transaction( - AgencyOperation(key, AgencySimpleOperationType::DELETE_OP) + AgencyOperation(key, AgencySimpleOperationType::DELETE_OP), + AgencyPrecondition(key, AgencyPrecondition::EMPTY, false) ); sendTransactionWithFailover(result, transaction); @@ -1323,8 +1351,7 @@ AgencyCommResult AgencyComm::casValue(std::string const& key, newBuilder.add(VPackValue(json.toJson())); AgencyOperation operation(key, AgencyValueOperationType::SET, newBuilder.slice()); - operation._precondition.type = AgencyOperationPrecondition::EMPTY; - operation._precondition.empty = !prevExist; + AgencyPrecondition precondition(key, AgencyPrecondition::EMPTY, !prevExist); if (ttl >= 0.0) { operation._ttl = static_cast(ttl); } @@ -1333,7 +1360,7 @@ AgencyCommResult AgencyComm::casValue(std::string const& key, url += "/write"; - AgencyTransaction transaction(operation); + AgencyTransaction transaction(operation, precondition); sendWithFailover( arangodb::GeneralRequest::RequestType::POST, @@ -1363,8 +1390,8 @@ AgencyCommResult AgencyComm::casValue(std::string const& key, oldBuilder.add(VPackValue(oldJson.toJson())); AgencyOperation operation(key, AgencyValueOperationType::SET, newBuilder.slice()); - operation._precondition.type = AgencyOperationPrecondition::VALUE; - operation._precondition.value = oldBuilder.slice(); + AgencyPrecondition precondition(key, AgencyPrecondition::VALUE, + oldBuilder.slice()); if (ttl >= 0.0) { operation._ttl = static_cast(ttl); } @@ -1373,7 +1400,7 @@ AgencyCommResult AgencyComm::casValue(std::string const& key, url += "/write"; - AgencyTransaction transaction(operation); + AgencyTransaction transaction(operation, precondition); sendWithFailover( arangodb::GeneralRequest::RequestType::POST, diff --git a/arangod/Cluster/AgencyComm.h b/arangod/Cluster/AgencyComm.h index d97581abbe..b51384aba0 100644 --- a/arangod/Cluster/AgencyComm.h +++ b/arangod/Cluster/AgencyComm.h @@ -159,27 +159,20 @@ struct AgencyOperationType { } }; -struct AgencyOperationPrecondition { - AgencyOperationPrecondition() : type(NONE) {} - AgencyOperationPrecondition(AgencyOperationPrecondition const& other) { - type = other.type; - switch(type) { - case NONE: - break; - case EMPTY: - empty = other.empty; - break; - case VALUE: - value = other.value; - break; - } - } +struct AgencyPrecondition { - enum {NONE, EMPTY, VALUE} type; - union { - bool empty; - VPackSlice value; - }; + typedef enum {NONE, EMPTY, VALUE} Type; + + AgencyPrecondition(std::string const& key, Type t, bool e); + + AgencyPrecondition(std::string const& key, Type t, VPackSlice s); + + void toVelocyPack(arangodb::velocypack::Builder& builder) const; + + std::string key; + Type type; + bool empty; + VPackSlice value; }; struct AgencyOperation { @@ -201,13 +194,14 @@ struct AgencyOperation { ); ////////////////////////////////////////////////////////////////////////////// - /// @brief returns to full operation formatted as a vpack slice + /// @brief returns to full operation formatted as a vpack slice and put + /// it into the argument builder ////////////////////////////////////////////////////////////////////////////// - std::shared_ptr toVelocyPack() const; + void toVelocyPack(arangodb::velocypack::Builder& builder) const; + uint32_t _ttl = 0; VPackSlice _oldValue; - AgencyOperationPrecondition _precondition; private: std::string const _key; @@ -217,12 +211,24 @@ private: struct AgencyTransaction { + ////////////////////////////////////////////////////////////////////////////// + /// @brief vector of preconditions + ////////////////////////////////////////////////////////////////////////////// + + std::vector preconditions; + ////////////////////////////////////////////////////////////////////////////// /// @brief vector of operations ////////////////////////////////////////////////////////////////////////////// std::vector operations; + ////////////////////////////////////////////////////////////////////////////// + /// @brief converts the transaction to velocypack + ////////////////////////////////////////////////////////////////////////////// + + void toVelocyPack(arangodb::velocypack::Builder& builder) const; + ////////////////////////////////////////////////////////////////////////////// /// @brief converts the transaction to json ////////////////////////////////////////////////////////////////////////////// @@ -232,10 +238,22 @@ struct AgencyTransaction { ////////////////////////////////////////////////////////////////////////////// /// @brief shortcut to create a transaction with one operation ////////////////////////////////////////////////////////////////////////////// + explicit AgencyTransaction(AgencyOperation const& operation) { operations.push_back(operation); } + ////////////////////////////////////////////////////////////////////////////// + /// @brief shortcut to create a transaction with one operation and a + /// precondition + ////////////////////////////////////////////////////////////////////////////// + + explicit AgencyTransaction(AgencyOperation const& operation, + AgencyPrecondition const& precondition) { + operations.push_back(operation); + preconditions.push_back(precondition); + } + explicit AgencyTransaction() { } }; From 4aa0764ff5ebc17f30e437e46d39b5d3d68c362b Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Thu, 21 Apr 2016 16:52:50 +0200 Subject: [PATCH 5/8] Fix dropCollectionCoordinator. --- arangod/Cluster/ClusterInfo.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arangod/Cluster/ClusterInfo.cpp b/arangod/Cluster/ClusterInfo.cpp index d18c3f0eda..c1bcbd5070 100644 --- a/arangod/Cluster/ClusterInfo.cpp +++ b/arangod/Cluster/ClusterInfo.cpp @@ -1368,6 +1368,11 @@ int ClusterInfo::dropCollectionCoordinator(std::string const& databaseName, while (TRI_microtime() <= endTime) { res.clear(); res = ac.getValues(where, true); + if (!res.successful()) { + // It seems the collection is already gone, do not wait further + errorMsg = "Collection already gone."; + return setErrormsg(TRI_ERROR_NO_ERROR, errorMsg); + } if (res.successful() && res.parse(where + "/", false)) { // if there are no more active shards for the collection... if (res._values.size() == 0) { From 3363e9bc279f056d6264dcf3d074a12785c86dcd Mon Sep 17 00:00:00 2001 From: Max Neunhoeffer Date: Thu, 21 Apr 2016 16:53:08 +0200 Subject: [PATCH 6/8] Fix startLocalCluster script. --- scripts/startLocalCluster.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/startLocalCluster.sh b/scripts/startLocalCluster.sh index e0b38ed71b..3ec746676d 100755 --- a/scripts/startLocalCluster.sh +++ b/scripts/startLocalCluster.sh @@ -37,7 +37,7 @@ fi rm -rf cluster mkdir cluster echo Starting agency... -build/bin/arangod -c etc/relative/arangod.conf \ +build/bin/arangod \ -c none \ --agency.endpoint tcp://127.0.0.1:4001 \ --agency.id 0 \ @@ -67,7 +67,7 @@ start() { PORT=$2 mkdir cluster/data$PORT echo Starting $TYPE on port $PORT - build/bin/arangod -c etc/relative/arangod.conf \ + build/bin/arangod -c none \ --database.directory cluster/data$PORT \ --cluster.agency-endpoint tcp://127.0.0.1:4001 \ --cluster.my-address tcp://127.0.0.1:$PORT \ @@ -93,7 +93,7 @@ startTerminal() { PORT=$2 mkdir cluster/data$PORT echo Starting $TYPE on port $PORT - xterm $XTERMOPTIONS -e build/bin/arangod -c etc/relative/arangod.conf \ + xterm $XTERMOPTIONS -e build/bin/arangod -c none \ --database.directory cluster/data$PORT \ --cluster.agency-endpoint tcp://127.0.0.1:4001 \ --cluster.my-address tcp://127.0.0.1:$PORT \ @@ -118,7 +118,7 @@ startDebugger() { PORT=$2 mkdir cluster/data$PORT echo Starting $TYPE on port $PORT with debugger - build/bin/arangod -c etc/relative/arangod.conf \ + build/bin/arangod -c none \ --database.directory cluster/data$PORT \ --cluster.agency-endpoint tcp://127.0.0.1:4001 \ --cluster.my-address tcp://127.0.0.1:$PORT \ @@ -144,7 +144,7 @@ startRR() { mkdir cluster/data$PORT echo Starting $TYPE on port $PORT with rr tracer xterm $XTERMOPTIONS -title "$TYPE $PORT" -e rr build/bin/arangod \ - -c etc/relative/arangod.conf \ + -c none \ --database.directory cluster/data$PORT \ --cluster.agency-endpoint tcp://127.0.0.1:4001 \ --cluster.my-address tcp://127.0.0.1:$PORT \ @@ -221,7 +221,7 @@ if [ -n "$SECONDARIES" ]; then echo Registering secondary $CLUSTER_ID for "DBServer$index" curl -f -X PUT --data "{\"primary\": \"DBServer$index\", \"oldSecondary\": \"none\", \"newSecondary\": \"$CLUSTER_ID\"}" -H "Content-Type: application/json" localhost:8530/_admin/cluster/replaceSecondary echo Starting Secondary $CLUSTER_ID on port $PORT - build/bin/arangod -c etc/relative/arangod.conf \ + build/bin/arangod -c none \ --database.directory cluster/data$PORT \ --cluster.agency-endpoint tcp://127.0.0.1:4001 \ --cluster.my-address tcp://127.0.0.1:$PORT \ From 9aa8a3dcad453ef6539c95205250684a5314357a Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Thu, 21 Apr 2016 17:02:02 +0200 Subject: [PATCH 7/8] Store no longer inherits from Node --- arangod/Agency/Node.cpp | 46 +++++++++++++++++++++-------------- arangod/Agency/Node.h | 16 +++++++------ arangod/Agency/Store.cpp | 52 +++++++++++++++++++++++++++++++++++++++- arangod/Agency/Store.h | 38 ++++++++++++++++++++++++++++- 4 files changed, 125 insertions(+), 27 deletions(-) diff --git a/arangod/Agency/Node.cpp b/arangod/Agency/Node.cpp index b38c554240..40c8343615 100644 --- a/arangod/Agency/Node.cpp +++ b/arangod/Agency/Node.cpp @@ -22,6 +22,7 @@ //////////////////////////////////////////////////////////////////////////////// #include "Node.h" +#include "Store.h" #include "Basics/StringUtils.h" @@ -58,13 +59,20 @@ inline std::vector split(const std::string& value, char separator) } // Construct with node name -Node::Node (std::string const& name) : _node_name(name), _parent(nullptr) { +Node::Node (std::string const& name) : _node_name(name), _parent(nullptr), + _store(nullptr) { _value.clear(); } // Construct with node name in tree structure Node::Node (std::string const& name, Node* parent) : - _node_name(name), _parent(parent) { + _node_name(name), _parent(parent), _store(nullptr) { + _value.clear(); +} + +// Construct for store +Node::Node (std::string const& name, Store* store) : + _node_name(name), _parent(nullptr), _store(store) { _value.clear(); } @@ -215,6 +223,14 @@ Node& Node::root() { return *tmp; } +Store& Node::store() { + return *(root()._store); +} + +Store const& Node::store() const { + return *(root()._store); +} + // velocypack value type of this node ValueType Node::valueType() const { return slice().type(); @@ -224,7 +240,7 @@ ValueType Node::valueType() const { bool Node::addTimeToLive (long millis) { auto tkey = std::chrono::system_clock::now() + std::chrono::milliseconds(millis); - root()._timeTable.insert( + store().timeTable().insert( std::pair>( tkey, _parent->_children[_node_name])); _ttl = tkey; @@ -234,10 +250,10 @@ bool Node::addTimeToLive (long millis) { // remove time to live entry for this node bool Node::removeTimeToLive () { if (_ttl != std::chrono::system_clock::time_point()) { - auto ret = root()._timeTable.equal_range(_ttl); + auto ret = store().timeTable().equal_range(_ttl); for (auto it = ret.first; it!=ret.second;) { if (it->second == _parent->_children[_node_name]) { - root()._timeTable.erase(it); + store().timeTable().erase(it); break; } ++it; @@ -247,7 +263,7 @@ bool Node::removeTimeToLive () { } inline bool Node::observedBy (std::string const& url) const { - auto ret = root()._observerTable.equal_range(url); + auto ret = store().observerTable().equal_range(url); for (auto it = ret.first; it!=ret.second; ++it) { if (it->second == uri()) { return true; @@ -406,8 +422,8 @@ template<> bool Node::handle (VPackSlice const& slice) { // check if such entry exists if (!observedBy(url)) { - root()._observerTable.emplace(std::pair(url,uri)); - root()._observedTable.emplace(std::pair(uri,url)); + store().observerTable().emplace(std::pair(url,uri)); + store().observedTable().emplace(std::pair(uri,url)); return true; } @@ -426,17 +442,17 @@ template<> bool Node::handle (VPackSlice const& slice) { // delete in both cases a single entry (ensured above) // breaking the iterators is fine then - auto ret = root()._observerTable.equal_range(url); + auto ret = store().observerTable().equal_range(url); for (auto it = ret.first; it!=ret.second; ++it) { if (it->second == uri) { - root()._observerTable.erase(it); + store().observerTable().erase(it); break; } } - ret = root()._observedTable.equal_range(uri); + ret = store().observedTable().equal_range(uri); for (auto it = ret.first; it!=ret.second; ++it) { if (it->second == url) { - root()._observedTable.erase(it); + store().observedTable().erase(it); return true; } } @@ -555,12 +571,6 @@ std::ostream& Node::print (std::ostream& o) const { o << std::endl; } - if (!_timeTable.empty()) { - for (auto const& i : _timeTable) { - o << i.second.get() << std::endl; - } - } - return o; } diff --git a/arangod/Agency/Node.h b/arangod/Agency/Node.h index ca5b0a3fe8..fc13ebd4f4 100644 --- a/arangod/Agency/Node.h +++ b/arangod/Agency/Node.h @@ -64,6 +64,8 @@ class Node; typedef std::chrono::system_clock::time_point TimePoint; typedef std::multimap> TimeTable; +class Store; + /// @brief Simple tree implementation class Node { @@ -80,6 +82,9 @@ public: /// @brief Construct with name and introduce to tree under parent Node (std::string const& name, Node* parent); + /// @brief Construct with name and introduce to tree under parent + Node (std::string const& name, Store* store); + /// @brief Default dtor virtual ~Node (); @@ -157,6 +162,9 @@ public: /// @brief Is this node being observed by url bool observedBy (std::string const& url) const; + Store& store(); + Store const& store() const; + protected: /// @brief Add time to live entry @@ -168,17 +176,11 @@ protected: std::string _node_name; /**< @brief my name */ Node* _parent; /**< @brief parent */ + Store* _store; /**< @brief Store */ Children _children; /**< @brief child nodes */ TimePoint _ttl; /**< @brief my expiry */ Buffer _value; /**< @brief my value */ - /// @brief Table of expiries in tree (only used in root node) - std::multimap> _timeTable; - - /// @brief Table of observers in tree (only used in root node) - std::multimap _observerTable; - std::multimap _observedTable; - }; inline std::ostream& operator<< (std::ostream& o, Node const& n) { diff --git a/arangod/Agency/Store.cpp b/arangod/Agency/Store.cpp index b09bcab32f..58badd55e7 100644 --- a/arangod/Agency/Store.cpp +++ b/arangod/Agency/Store.cpp @@ -99,7 +99,7 @@ inline static bool endpointPathFromUrl ( } // Create with name -Store::Store (std::string const& name) : Node(name), Thread(name) {} +Store::Store (std::string const& name) : Thread(name), _node(name) {} // Default ctor Store::~Store () {} @@ -459,3 +459,53 @@ void Store::run() { } + +bool Store::applies (arangodb::velocypack::Slice const& slice) { + return _node.applies(slice); +} + + +void Store::toBuilder (Builder& b) const { + _node.toBuilder(b); +} + +Node Store::operator ()(std::vector const& pv) { + return _node(pv); +} + +Node const Store::operator ()(std::vector const& pv) const { + return _node(pv); +} + + +Node Store::operator ()(std::string const& path) { + return _node(path); +} + +Node const Store::operator ()(std::string const& path) const { + return _node(path); +} + + +std::multimap>& Store::timeTable () { + return _timeTable; +} + +const std::multimap>& Store::timeTable () const { + return _timeTable; +} + +std::multimap & Store::observerTable() { + return _observerTable; +} +std::multimap const& Store::observerTable() const { + return _observerTable; +} + +std::multimap & Store::observedTable() { + return _observedTable; +} + +std::multimap const& Store::observedTable() const { + return _observedTable; +} diff --git a/arangod/Agency/Store.h b/arangod/Agency/Store.h index 6fb4f9bcdf..9040ae332d 100644 --- a/arangod/Agency/Store.h +++ b/arangod/Agency/Store.h @@ -36,7 +36,7 @@ namespace consensus { class Agent; /// @brief Key value tree -class Store : public Node, public arangodb::Thread { +class Store : public arangodb::Thread { public: @@ -76,7 +76,33 @@ public: /// @brief See how far the path matches anything in store size_t matchPath (std::vector const& pv) const; + /// @brief Get node specified by path vector + Node operator ()(std::vector const& pv); + /// @brief Get node specified by path vector + Node const operator ()(std::vector const& pv) const; + + /// @brief Get node specified by path string + Node operator ()(std::string const& path); + /// @brief Get node specified by path string + Node const operator ()(std::string const& path) const; + + /// @brief Apply single slice + bool applies (arangodb::velocypack::Slice const&); + + /// @brief Create Builder representing this store + void toBuilder (Builder&) const; + + friend class Node; + private: + + std::multimap>& timeTable (); + std::multimap> const& timeTable () const; + std::multimap & observerTable(); + std::multimap const& observerTable() const; + std::multimap & observedTable(); + std::multimap const& observedTable() const; + /// @brief Read individual entry specified in slice into builder bool read (arangodb::velocypack::Slice const&, arangodb::velocypack::Builder&) const; @@ -99,6 +125,16 @@ private: /// @brief My own agent Agent* _agent; + /// @brief Table of expiries in tree (only used in root node) + std::multimap> _timeTable; + + /// @brief Table of observers in tree (only used in root node) + std::multimap _observerTable; + std::multimap _observedTable; + + /// @brief Root node + Node _node; + }; }} From e980c74548556b0b26b2d60363b5ea21dd8d2d41 Mon Sep 17 00:00:00 2001 From: Kaveh Vahedipour Date: Thu, 21 Apr 2016 17:11:44 +0200 Subject: [PATCH 8/8] class Node out of Store.{h,cpp} --- arangod/Agency/Store.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arangod/Agency/Store.cpp b/arangod/Agency/Store.cpp index 58badd55e7..118c2f0178 100644 --- a/arangod/Agency/Store.cpp +++ b/arangod/Agency/Store.cpp @@ -99,7 +99,7 @@ inline static bool endpointPathFromUrl ( } // Create with name -Store::Store (std::string const& name) : Thread(name), _node(name) {} +Store::Store (std::string const& name) : Thread(name), _node(name,this) {} // Default ctor Store::~Store () {}