From 73ac2e729cfc37c1ce863d25a43405dd01839489 Mon Sep 17 00:00:00 2001 From: Willi Goesgens Date: Wed, 29 Oct 2014 19:11:24 +0100 Subject: [PATCH 1/4] another place to ensure that the pointer to TRI_json_t is free'd --- arangod/Cluster/ClusterMethods.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arangod/Cluster/ClusterMethods.cpp b/arangod/Cluster/ClusterMethods.cpp index 9a45442a3d..5fd6a45141 100644 --- a/arangod/Cluster/ClusterMethods.cpp +++ b/arangod/Cluster/ClusterMethods.cpp @@ -563,9 +563,9 @@ int createDocumentOnCoordinator ( // The user did not specify a key, let's create one: uint64_t uid = ci->uniqid(); _key = triagens::basics::StringUtils::itoa(uid); - TRI_InsertArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "_key", - TRI_CreateStringReference2Json(TRI_UNKNOWN_MEM_ZONE, - _key.c_str(), _key.size())); + TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "_key", + TRI_CreateStringReference2Json(TRI_UNKNOWN_MEM_ZONE, + _key.c_str(), _key.size())); } else { userSpecifiedKey = true; @@ -1248,9 +1248,9 @@ int createEdgeOnCoordinator ( // The user did not specify a key, let's create one: uint64_t uid = ci->uniqid(); _key = triagens::basics::StringUtils::itoa(uid); - TRI_InsertArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "_key", - TRI_CreateStringReference2Json(TRI_UNKNOWN_MEM_ZONE, - _key.c_str(), _key.size())); + TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, json, "_key", + TRI_CreateStringReference2Json(TRI_UNKNOWN_MEM_ZONE, + _key.c_str(), _key.size())); } else { userSpecifiedKey = true; From 26a0ce441cc7c4a07f923002c6e95f076021ca60 Mon Sep 17 00:00:00 2001 From: Willi Goesgens Date: Wed, 29 Oct 2014 19:11:48 +0100 Subject: [PATCH 2/4] nullptr --- arangod/Cluster/AgencyComm.cpp | 38 +++++++++++++++++----------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/arangod/Cluster/AgencyComm.cpp b/arangod/Cluster/AgencyComm.cpp index 04968c6bf2..b464b104e0 100644 --- a/arangod/Cluster/AgencyComm.cpp +++ b/arangod/Cluster/AgencyComm.cpp @@ -69,10 +69,10 @@ AgencyEndpoint::AgencyEndpoint (triagens::rest::Endpoint* endpoint, //////////////////////////////////////////////////////////////////////////////// AgencyEndpoint::~AgencyEndpoint () { - if (_connection != 0) { + if (_connection != nullptr) { delete _connection; } - if (_endpoint != 0) { + if (_endpoint != nullptr) { delete _endpoint; } } @@ -108,7 +108,7 @@ AgencyCommResult::~AgencyCommResult () { std::map::iterator it = _values.begin(); while (it != _values.end()) { - if ((*it).second._json != 0) { + if ((*it).second._json != nullptr) { TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, (*it).second._json); } ++it; @@ -145,7 +145,7 @@ int AgencyCommResult::errorCode () const { TRI_json_t* json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, _body.c_str()); if (! TRI_IsArrayJson(json)) { - if (json != 0) { + if (json != nullptr) { TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); } return result; @@ -227,7 +227,7 @@ void AgencyCommResult::clear () { std::map::iterator it = _values.begin(); while (it != _values.end()) { - if ((*it).second._json != 0) { + if ((*it).second._json != nullptr) { TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, (*it).second._json); } ++it; @@ -343,7 +343,7 @@ bool AgencyCommResult::parse (std::string const& stripKeyPrefix, TRI_json_t* json = TRI_JsonString(TRI_UNKNOWN_MEM_ZONE, _body.c_str()); if (! TRI_IsArrayJson(json)) { - if (json != 0) { + if (json != nullptr) { TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, json); } return false; @@ -418,7 +418,7 @@ AgencyCommLocker::AgencyCommLocker (std::string const& key, double ttl) : _key(key), _type(type), - _json(0), + _json(nullptr), _version(0), _isLocked(false) { @@ -426,7 +426,7 @@ AgencyCommLocker::AgencyCommLocker (std::string const& key, _json = TRI_CreateString2CopyJson(TRI_UNKNOWN_MEM_ZONE, type.c_str(), type.size()); - if (_json == 0) { + if (_json == nullptr) { return; } @@ -443,7 +443,7 @@ AgencyCommLocker::AgencyCommLocker (std::string const& key, AgencyCommLocker::~AgencyCommLocker () { unlock(); - if (_json != 0) { + if (_json != nullptr) { TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, _json); } } @@ -512,7 +512,7 @@ bool AgencyCommLocker::updateVersion (AgencyComm& comm) { if (_version == 0) { TRI_json_t* json = triagens::basics::JsonHelper::uint64String(TRI_UNKNOWN_MEM_ZONE, 1); - if (json == 0) { + if (json == nullptr) { return false; } @@ -531,13 +531,13 @@ bool AgencyCommLocker::updateVersion (AgencyComm& comm) { // Version key found, now update it TRI_json_t* oldJson = triagens::basics::JsonHelper::uint64String(TRI_UNKNOWN_MEM_ZONE, _version); - if (oldJson == 0) { + if (oldJson == nullptr) { return false; } TRI_json_t* newJson = triagens::basics::JsonHelper::uint64String(TRI_UNKNOWN_MEM_ZONE, _version + 1); - if (newJson == 0) { + if (newJson == nullptr) { TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, oldJson); return false; } @@ -597,7 +597,7 @@ void AgencyComm::cleanup () { while (it != _globalEndpoints.end()) { AgencyEndpoint* agencyEndpoint = (*it); - TRI_ASSERT(agencyEndpoint != 0); + TRI_ASSERT(agencyEndpoint != nullptr); delete agencyEndpoint; ++it; @@ -624,9 +624,9 @@ bool AgencyComm::tryConnect () { while (it != _globalEndpoints.end()) { AgencyEndpoint* agencyEndpoint = (*it); - TRI_ASSERT(agencyEndpoint != 0); - TRI_ASSERT(agencyEndpoint->_endpoint != 0); - TRI_ASSERT(agencyEndpoint->_connection != 0); + TRI_ASSERT(agencyEndpoint != nullptr); + TRI_ASSERT(agencyEndpoint->_endpoint != nullptr); + TRI_ASSERT(agencyEndpoint->_connection != nullptr); if (agencyEndpoint->_endpoint->isConnected()) { return true; @@ -659,9 +659,9 @@ void AgencyComm::disconnect () { while (it != _globalEndpoints.end()) { AgencyEndpoint* agencyEndpoint = (*it); - TRI_ASSERT(agencyEndpoint != 0); - TRI_ASSERT(agencyEndpoint->_connection != 0); - TRI_ASSERT(agencyEndpoint->_endpoint != 0); + TRI_ASSERT(agencyEndpoint != nullptr); + TRI_ASSERT(agencyEndpoint->_connection != nullptr); + TRI_ASSERT(agencyEndpoint->_endpoint != nullptr); agencyEndpoint->_connection->disconnect(); agencyEndpoint->_endpoint->disconnect(); From 1376d44110ff6859d9c64dff8a3ab8a85b62fefc Mon Sep 17 00:00:00 2001 From: Willi Goesgens Date: Wed, 29 Oct 2014 19:16:34 +0100 Subject: [PATCH 3/4] Clear the ClusterCommResult objects before re-assigning them; else we loose memory. --- arangod/Cluster/ClusterInfo.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/arangod/Cluster/ClusterInfo.cpp b/arangod/Cluster/ClusterInfo.cpp index 047a856a27..008607b340 100644 --- a/arangod/Cluster/ClusterInfo.cpp +++ b/arangod/Cluster/ClusterInfo.cpp @@ -952,6 +952,7 @@ int ClusterInfo::createDatabaseCoordinator (string const& name, } // Now wait for it to appear and be complete: + res.clear(); res = ac.getValues("Current/Version", false); if (! res.successful()) { return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION, @@ -964,6 +965,7 @@ int ClusterInfo::createDatabaseCoordinator (string const& name, string where = "Current/Databases/" + name; while (TRI_microtime() <= endTime) { + res.clear(); res = ac.getValues(where, true); if (res.successful() && res.parse(where+"/", false)) { if (res._values.size() == DBServers.size()) { @@ -999,6 +1001,7 @@ int ClusterInfo::createDatabaseCoordinator (string const& name, } } + res.clear(); res = ac.watchValue("Current/Version", index, getReloadServerListTimeout() / interval, false); index = res._index; if (++count >= static_cast(getReloadServerListTimeout() / interval)) { @@ -1050,6 +1053,7 @@ int ClusterInfo::dropDatabaseCoordinator (string const& name, string& errorMsg, errorMsg); } + res.clear(); res = ac.removeValues("Plan/Collections/" + name, true); if (! res.successful() && res.httpCode() != (int) rest::HttpResponse::NOT_FOUND) { @@ -1061,6 +1065,7 @@ int ClusterInfo::dropDatabaseCoordinator (string const& name, string& errorMsg, _collectionsValid = false; // Now wait for it to appear and be complete: + res.clear(); res = ac.getValues("Current/Version", false); if (!res.successful()) { return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION, @@ -1070,11 +1075,13 @@ int ClusterInfo::dropDatabaseCoordinator (string const& name, string& errorMsg, string where = "Current/Databases/" + name; while (TRI_microtime() <= endTime) { + res.clear(); res = ac.getValues(where, true); if (res.successful() && res.parse(where+"/", false)) { if (res._values.size() == 0) { AgencyCommLocker locker("Current", "WRITE"); if (locker.successful()) { + res.clear(); res = ac.removeValues(where, true); if (res.successful()) { return setErrormsg(TRI_ERROR_NO_ERROR, errorMsg); @@ -1085,7 +1092,7 @@ int ClusterInfo::dropDatabaseCoordinator (string const& name, string& errorMsg, return setErrormsg(TRI_ERROR_NO_ERROR, errorMsg); } } - + res.clear(); res = ac.watchValue("Current/Version", index, interval, false); index = res._index; } @@ -1162,6 +1169,7 @@ int ClusterInfo::createCollectionCoordinator (string const& databaseName, string where = "Current/Collections/" + databaseName + "/" + collectionID; while (TRI_microtime() <= endTime) { + res.clear(); res = ac.getValues(where, true); if (res.successful() && res.parse(where+"/", false)) { if (res._values.size() == (size_t) numberOfShards) { @@ -1197,6 +1205,7 @@ int ClusterInfo::createCollectionCoordinator (string const& databaseName, } } + res.clear(); res = ac.watchValue("Current/Version", index, interval, false); index = res._index; } @@ -1245,6 +1254,7 @@ int ClusterInfo::dropCollectionCoordinator (string const& databaseName, flush(); // Now wait for it to appear and be complete: + res.clear(); res = ac.getValues("Current/Version", false); if (!res.successful()) { return setErrormsg(TRI_ERROR_CLUSTER_COULD_NOT_READ_CURRENT_VERSION, @@ -1255,6 +1265,7 @@ int ClusterInfo::dropCollectionCoordinator (string const& databaseName, // monitor the entry for the collection const string where = "Current/Collections/" + databaseName + "/" + collectionID; while (TRI_microtime() <= endTime) { + res.clear(); res = ac.getValues(where, true); if (res.successful() && res.parse(where+"/", false)) { // if there are no more active shards for the collection... @@ -1262,6 +1273,7 @@ int ClusterInfo::dropCollectionCoordinator (string const& databaseName, // ...remove the entire directory for the collection AgencyCommLocker locker("Current", "WRITE"); if (locker.successful()) { + res.clear(); res = ac.removeValues("Current/Collections/"+databaseName+"/"+ collectionID, true); if (res.successful()) { @@ -1274,6 +1286,7 @@ int ClusterInfo::dropCollectionCoordinator (string const& databaseName, } } + res.clear(); res = ac.watchValue("Current/Version", index, interval, false); index = res._index; } @@ -1331,6 +1344,7 @@ int ClusterInfo::setCollectionPropertiesCoordinator (string const& databaseName, TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, copy, "journalSize", TRI_CreateNumberJson(TRI_UNKNOWN_MEM_ZONE, info->_maximalSize)); TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, copy, "waitForSync", TRI_CreateBooleanJson(TRI_UNKNOWN_MEM_ZONE, info->_waitForSync)); + res.clear(); res = ac.setValue("Plan/Collections/" + databaseName + "/" + collectionID, copy, 0.0); TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, copy); @@ -1396,6 +1410,7 @@ int ClusterInfo::setCollectionStatusCoordinator (string const& databaseName, TRI_DeleteArrayJson(TRI_UNKNOWN_MEM_ZONE, copy, "status"); TRI_Insert3ArrayJson(TRI_UNKNOWN_MEM_ZONE, copy, "status", TRI_CreateNumberJson(TRI_UNKNOWN_MEM_ZONE, status)); + res.clear(); res = ac.setValue("Plan/Collections/" + databaseName + "/" + collectionID, copy, 0.0); TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, copy); @@ -1576,6 +1591,7 @@ int ClusterInfo::ensureIndexCoordinator (string const& databaseName, string where = "Current/Collections/" + databaseName + "/" + collectionID; while (TRI_microtime() <= endTime) { + res.clear(); res = ac.getValues(where, true); if (res.successful() && res.parse(where + "/", false)) { if (res._values.size() == (size_t) numberOfShards) { @@ -1631,7 +1647,7 @@ int ClusterInfo::ensureIndexCoordinator (string const& databaseName, } } } - + res.clear(); res = ac.watchValue("Current/Version", index, interval, false); index = res._index; } @@ -1772,6 +1788,7 @@ int ClusterInfo::dropIndexCoordinator (string const& databaseName, string where = "Current/Collections/" + databaseName + "/" + collectionID; while (TRI_microtime() <= endTime) { + res.clear(); res = ac.getValues(where, true); if (res.successful() && res.parse(where + "/", false)) { if (res._values.size() == (size_t) numberOfShards) { @@ -1807,6 +1824,7 @@ int ClusterInfo::dropIndexCoordinator (string const& databaseName, } } + res.clear(); res = ac.watchValue("Current/Version", index, interval, false); index = res._index; } @@ -1845,7 +1863,7 @@ void ClusterInfo::loadServers () { = triagens::basics::JsonHelper::getArrayElement((*it).second._json, "endpoint"); if (nullptr != sub) { - const std::string server = triagens::basics::JsonHelper::getStringValue(sub, ""); + std::string server = triagens::basics::JsonHelper::getStringValue(sub, ""); _servers.emplace(std::make_pair((*it).first, server)); } From 8db1e18568285190d298861df9fddffc69e77244 Mon Sep 17 00:00:00 2001 From: Willi Goesgens Date: Wed, 29 Oct 2014 21:10:57 +0100 Subject: [PATCH 4/4] Adjust the result returned to be the old format again. --- js/common/modules/jsunity.js | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/js/common/modules/jsunity.js b/js/common/modules/jsunity.js index b54ff71340..535390b203 100644 --- a/js/common/modules/jsunity.js +++ b/js/common/modules/jsunity.js @@ -28,25 +28,17 @@ //////////////////////////////////////////////////////////////////////////////// -var _ = require("underscore"); var internal = require("internal"); var print = internal.print; var fs = require("fs"); var console = require("console"); -var COMPLETE={ - "TOTAL": 0, - "PASSED": 0, - "FAILED": 0, - "DURATION": 0, - "RESULTS": {} -}; - var TOTAL = 0; var PASSED = 0; var FAILED = 0; var DURATION = 0; var RESULTS = {}; +var COMPLETE = {}; var jsUnity = require("./jsunity/jsunity").jsUnity; var STARTTEST = 0.0; @@ -148,11 +140,7 @@ function Run (testsuite) { FAILED += result.failed; DURATION += result.duration; - COMPLETE.TOTAL += result.total; - COMPLETE.PASSED += result.passed; - COMPLETE.FAILED += result.failed; - COMPLETE.DURATION += result.duration; - _.defaults(COMPLETE.RESULTS, RESULTS); + for (var attrname in RESULTS) { COMPLETE[attrname] = RESULTS[attrname]; } return result; } @@ -168,18 +156,18 @@ function Done (suiteName) { var ok = FAILED === 0; - RESULTS.duration = DURATION; - RESULTS.status = ok; - RESULTS.failed = FAILED; - RESULTS.total = TOTAL; - RESULTS.suiteName = suiteName; + COMPLETE.duration = DURATION; + COMPLETE.status = ok; + COMPLETE.failed = FAILED; + COMPLETE.total = TOTAL; + COMPLETE.suiteName = suiteName; TOTAL = 0; PASSED = 0; FAILED = 0; DURATION = 0; - return COMPLETE.RESULTS; + return COMPLETE; } ////////////////////////////////////////////////////////////////////////////////