diff --git a/arangod/Agency/Store.cpp b/arangod/Agency/Store.cpp index 8251a52d03..5ae4398df9 100644 --- a/arangod/Agency/Store.cpp +++ b/arangod/Agency/Store.cpp @@ -145,14 +145,6 @@ Node& Node::operator= (VPackSlice const& slice) { _children.clear(); _value.reset(); _value.append(reinterpret_cast(slice.begin()), slice.byteSize()); -/* - notifyObservers(uri()); - Node *par = _parent; - while (par != 0) { - _parent->notifyObservers(uri()); - par = par->_parent; - } -*/ return *this; } @@ -167,14 +159,6 @@ Node& Node::operator= (Node const& rhs) { _node_name = rhs._node_name; _value = rhs._value; _children = rhs._children; - /* - notifyObservers(uri()); - Node *par = _parent; - while (par != 0) { - _parent->notifyObservers(uri()); - par = par->_parent; - } - */ return *this; } @@ -300,61 +284,6 @@ bool Node::removeTimeToLive () { return true; } -// Add observing url for this node -/*bool Node::addObserver (std::string const& uri) { - auto it = std::find(_observers.begin(), _observers.end(), uri); - if (it==_observers.end()) { - _observers.emplace(uri); - return true; - } - return false; - }*/ - -/*void Node::notifyObservers (std::string const& origin) const { - - for (auto const& i : _observers) { - - Builder body; - body.openObject(); - body.add(uri(), VPackValue(VPackValueType::Object)); - body.add("op",VPackValue("modified")); - body.close(); - body.close(); - - std::stringstream endpoint; - std::string path = "/"; - size_t pos = 7; - if (i.find("http://")==0) { - endpoint << "tcp://"; - } else if (i.find("https://")==0) { - endpoint << "ssl://"; - ++pos; - } else { - LOG_TOPIC(WARN,Logger::AGENCY) << "Malformed notification URL " << i; - return; - } - - size_t slash_p = i.find("/",pos); - if ((slash_p==std::string::npos)) { - endpoint << i.substr(pos); - } else { - endpoint << i.substr(pos,slash_p-pos); - path = i.substr(slash_p); - } - - std::unique_ptr> headerFields = - std::make_unique >(); - - ClusterCommResult res = - arangodb::ClusterComm::instance()->asyncRequest( - "1", 1, endpoint.str(), GeneralRequest::RequestType::POST, path, - std::make_shared(body.toString()), headerFields, nullptr, - 0.0, true); - - } - - }*/ - inline bool Node::observedBy (std::string const& url) const { auto ret = root()._observer_table.equal_range(url); for (auto it = ret.first; it!=ret.second; ++it) { @@ -504,10 +433,9 @@ template<> bool Node::handle (VPackSlice const& slice) { if (!observedBy(url)) { root()._observer_table.emplace(std::pair(url,uri)); root()._observed_table.emplace(std::pair(uri,url)); -// _observers.emplace(url); return true; } - + return false; } @@ -520,7 +448,9 @@ template<> bool Node::handle (VPackSlice const& slice) { return false; std::string url (slice.get("url").copyString()), uri (this->uri()); - + + // delete in both cases a single entry (ensured above) + // breaking the iterators is fine then auto ret = root()._observer_table.equal_range(url); for (auto it = ret.first; it!=ret.second; ++it) { if (it->second == uri) { @@ -750,12 +680,17 @@ std::vector Store::apply ( for (auto it = ret.first; it!=ret.second; ++it) { body.add(it->second->key,VPackValue(VPackValueType::Object)); + body.add(it->second->modified,VPackValue(VPackValueType::Object)); body.add("op",VPackValue(it->second->oper)); body.close(); + body.close(); } body.close(); + std::cout << url << body.toString() << std::endl; + + std::string endpoint, path; if (endpointPathFromUrl (url,endpoint,path)) { diff --git a/arangod/Agency/Store.h b/arangod/Agency/Store.h index 8fd7c2e95f..8a7d887a0c 100644 --- a/arangod/Agency/Store.h +++ b/arangod/Agency/Store.h @@ -174,8 +174,6 @@ protected: TimePoint _ttl; /**< @brief my expiry */ Buffer _value; /**< @brief my value */ -// std::unordered_set _observers; /**< @brief my observers */ - /// @brief Table of expiries in tree (only used in root node) std::multimap> _time_table; diff --git a/arangod/RestHandler/RestAgencyHandler.cpp b/arangod/RestHandler/RestAgencyHandler.cpp index d2483d2fec..4b48bda5bc 100644 --- a/arangod/RestHandler/RestAgencyHandler.cpp +++ b/arangod/RestHandler/RestAgencyHandler.cpp @@ -155,7 +155,8 @@ HttpHandler::status_t RestAgencyHandler::handleWrite () { body.close(); if (errors > 0) { // Some/all requests failed - generateResult(GeneralResponse::ResponseCode::PRECONDITION_FAILED, body.slice()); + generateResult(GeneralResponse::ResponseCode::PRECONDITION_FAILED, + body.slice()); } else { // All good generateResult(GeneralResponse::ResponseCode::OK, body.slice()); }