1
0
Fork 0

Implement passing of query statistics through cluster.

This commit is contained in:
Willi Goesgens 2014-10-22 17:36:23 +02:00
parent 20383dd4e2
commit 9558f5aa0a
6 changed files with 57 additions and 5 deletions

View File

@ -4527,6 +4527,9 @@ AqlItemBlock* RemoteBlock::getSome (size_t atLeast,
}
auto items = new triagens::aql::AqlItemBlock(responseBodyJson);
_engine->_stats.add(ExecutionStats(responseBodyJson.get("stats")));
return items;
}

View File

@ -28,9 +28,10 @@
////////////////////////////////////////////////////////////////////////////////
#include "Aql/ExecutionStats.h"
#include "Utils/Exception.h"
using namespace triagens::aql;
using Json = triagens::basics::Json;
using JsonHelper = triagens::basics::JsonHelper;
// -----------------------------------------------------------------------------
// --SECTION-- public methods
@ -50,6 +51,24 @@ Json ExecutionStats::toJson () const {
return json;
}
ExecutionStats::ExecutionStats()
:writesExecuted(0),
writesIgnored(0),
scannedFull(0),
scannedIndex(0) {
}
ExecutionStats::ExecutionStats (triagens::basics::Json const& jsonStats) {
if (!jsonStats.isArray()) {
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, "stats is not an Array");
}
std::cout << jsonStats.toString() << "\n";
writesExecuted = JsonHelper::checkAndGetNumericValue<int>(jsonStats.json(), "writesExecuted");
writesIgnored = JsonHelper::checkAndGetNumericValue<int>(jsonStats.json(), "writesIgnored");
scannedFull = JsonHelper::checkAndGetNumericValue<int>(jsonStats.json(), "scannedFull");
scannedIndex = JsonHelper::checkAndGetNumericValue<int>(jsonStats.json(), "scannedIndex");
}
// -----------------------------------------------------------------------------
// --SECTION-- END-OF-FILE
// -----------------------------------------------------------------------------

View File

@ -38,35 +38,50 @@ namespace triagens {
struct ExecutionStats {
ExecutionStats ();
////////////////////////////////////////////////////////////////////////////////
/// @brief instanciate the statistics from JSON
////////////////////////////////////////////////////////////////////////////////
ExecutionStats (triagens::basics::Json const& jsonStats);
////////////////////////////////////////////////////////////////////////////////
/// @brief convert the statistics to JSON
////////////////////////////////////////////////////////////////////////////////
triagens::basics::Json toJson () const;
void add (ExecutionStats const& summand) {
writesExecuted += summand.writesExecuted;
writesIgnored += summand.writesIgnored;
scannedFull += summand.scannedFull;
scannedIndex += summand.scannedIndex;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief number of successfully executed write operations
////////////////////////////////////////////////////////////////////////////////
int64_t writesExecuted = 0;
int64_t writesExecuted;
////////////////////////////////////////////////////////////////////////////////
/// @brief number of ignored write operations (ignored due to errors)
////////////////////////////////////////////////////////////////////////////////
int64_t writesIgnored = 0;
int64_t writesIgnored;
////////////////////////////////////////////////////////////////////////////////
/// @brief number of documents scanned (full-collection scan)
////////////////////////////////////////////////////////////////////////////////
int64_t scannedFull = 0;
int64_t scannedFull;
////////////////////////////////////////////////////////////////////////////////
/// @brief number of documents scanned (using indexes scan)
////////////////////////////////////////////////////////////////////////////////
int64_t scannedIndex = 0;
int64_t scannedIndex;
};

View File

@ -840,6 +840,14 @@ void Query::exitContext () {
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief returns statistics for current query.
////////////////////////////////////////////////////////////////////////////////
triagens::basics::Json Query::getStats() {
return _engine->_stats.toJson();
}
////////////////////////////////////////////////////////////////////////////////
/// @brief fetch a boolean value from the options
////////////////////////////////////////////////////////////////////////////////

View File

@ -379,6 +379,12 @@ namespace triagens {
void exitContext ();
////////////////////////////////////////////////////////////////////////////////
/// @brief returns statistics for current query.
////////////////////////////////////////////////////////////////////////////////
triagens::basics::Json getStats();
// -----------------------------------------------------------------------------
// --SECTION-- private methods
// -----------------------------------------------------------------------------

View File

@ -747,6 +747,7 @@ void RestAqlHandler::handleUseQuery (std::string const& operation,
else {
try {
answerBody = items->toJson(query->trx());
answerBody.set("stats", query->getStats());
// std::cout << "ANSWERBODY: " << JsonHelper::toString(answerBody.json()) << "\n\n";
}
catch (...) {