1
0
Fork 0

Fix AQL in cluster bugs.

This commit is contained in:
Max Neunhoeffer 2016-03-21 23:30:13 +01:00
parent 7f9ae321a0
commit 5bfdca8d69
4 changed files with 187 additions and 174 deletions

View File

@ -96,7 +96,7 @@ AqlItemBlock::AqlItemBlock(VPackSlice const slice) {
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL, THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
"data must contain only numbers"); "data must contain only numbers");
} }
int64_t n = data.getNumericValue<int64_t>(); int64_t n = dataEntry.getNumericValue<int64_t>();
if (n == 0) { if (n == 0) {
// empty, do nothing here // empty, do nothing here
} else if (n == -1) { } else if (n == -1) {
@ -542,12 +542,10 @@ void AqlItemBlock::toVelocyPack(arangodb::AqlTransaction* trx,
raw.close(); raw.close();
data.close(); data.close();
result.openObject();
result.add("nrItems", VPackValue(_nrItems)); result.add("nrItems", VPackValue(_nrItems));
result.add("nrRegs", VPackValue(_nrRegs)); result.add("nrRegs", VPackValue(_nrRegs));
result.add("data", data.slice()); result.add("data", data.slice());
result.add("raw", raw.slice()); result.add("raw", raw.slice());
result.add("error", VPackValue(false)); result.add("error", VPackValue(false));
result.add("exhausted", VPackValue(false)); result.add("exhausted", VPackValue(false));
result.close();
} }

View File

@ -1143,8 +1143,9 @@ void Query::getStats(VPackBuilder& builder) {
if (_engine) { if (_engine) {
_engine->_stats.setExecutionTime(TRI_microtime() - _startTime); _engine->_stats.setExecutionTime(TRI_microtime() - _startTime);
_engine->_stats.toVelocyPack(builder); _engine->_stats.toVelocyPack(builder);
} } else {
ExecutionStats::toVelocyPackStatic(builder); ExecutionStats::toVelocyPackStatic(builder);
}
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -142,7 +142,8 @@ void RestAqlHandler::createQueryFromVelocyPack() {
return; return;
} }
sendResponse(arangodb::rest::HttpResponse::ACCEPTED, answerBody.slice()); sendResponse(arangodb::rest::HttpResponse::ACCEPTED, answerBody.slice(),
query->trx()->transactionContext().get());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -182,7 +183,9 @@ void RestAqlHandler::parseQuery() {
// Now prepare the answer: // Now prepare the answer:
VPackBuilder answerBuilder; VPackBuilder answerBuilder;
auto transactionContext = query->trx()->transactionContext();
try { try {
{
VPackObjectBuilder guard(&answerBuilder); VPackObjectBuilder guard(&answerBuilder);
answerBuilder.add("parsed", VPackValue(true)); answerBuilder.add("parsed", VPackValue(true));
answerBuilder.add(VPackValue("collections")); answerBuilder.add(VPackValue("collections"));
@ -203,11 +206,13 @@ void RestAqlHandler::parseQuery() {
answerBuilder.add(VPackValue("ast")); answerBuilder.add(VPackValue("ast"));
answerBuilder.add(res.result->slice()); answerBuilder.add(res.result->slice());
res.result = nullptr; res.result = nullptr;
}
sendResponse(arangodb::rest::HttpResponse::OK, answerBuilder.slice(),
transactionContext.get());
} catch (...) { } catch (...) {
generateError(HttpResponse::BAD, TRI_ERROR_OUT_OF_MEMORY, generateError(HttpResponse::BAD, TRI_ERROR_OUT_OF_MEMORY,
"out of memory"); "out of memory");
} }
sendResponse(arangodb::rest::HttpResponse::OK, answerBuilder.slice());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -251,6 +256,7 @@ void RestAqlHandler::explainQuery() {
// Now prepare the answer: // Now prepare the answer:
VPackBuilder answerBuilder; VPackBuilder answerBuilder;
try { try {
{
VPackObjectBuilder guard(&answerBuilder); VPackObjectBuilder guard(&answerBuilder);
if (res.result != nullptr) { if (res.result != nullptr) {
if (query->allPlans()) { if (query->allPlans()) {
@ -261,11 +267,13 @@ void RestAqlHandler::explainQuery() {
answerBuilder.add(res.result->slice()); answerBuilder.add(res.result->slice());
res.result = nullptr; res.result = nullptr;
} }
}
sendResponse(arangodb::rest::HttpResponse::OK, answerBuilder.slice(),
query->trx()->transactionContext().get());
} catch (...) { } catch (...) {
generateError(HttpResponse::BAD, TRI_ERROR_OUT_OF_MEMORY, generateError(HttpResponse::BAD, TRI_ERROR_OUT_OF_MEMORY,
"out of memory"); "out of memory");
} }
sendResponse(arangodb::rest::HttpResponse::OK, answerBuilder.slice());
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -683,7 +691,9 @@ void RestAqlHandler::handleUseQuery(std::string const& operation, Query* query,
} }
VPackBuilder answerBuilder; VPackBuilder answerBuilder;
auto transactionContext = query->trx()->transactionContext();
try { try {
{
VPackObjectBuilder guard(&answerBuilder); VPackObjectBuilder guard(&answerBuilder);
if (operation == "lock") { if (operation == "lock") {
// Mark current thread as potentially blocking: // Mark current thread as potentially blocking:
@ -847,7 +857,9 @@ void RestAqlHandler::handleUseQuery(std::string const& operation, Query* query,
generateError(HttpResponse::NOT_FOUND, TRI_ERROR_HTTP_NOT_FOUND); generateError(HttpResponse::NOT_FOUND, TRI_ERROR_HTTP_NOT_FOUND);
return; return;
} }
sendResponse(arangodb::rest::HttpResponse::OK, answerBuilder.slice()); }
sendResponse(arangodb::rest::HttpResponse::OK, answerBuilder.slice(),
transactionContext.get());
} catch (...) { } catch (...) {
LOG(ERR) << "OUT OF MEMORY when handling query."; LOG(ERR) << "OUT OF MEMORY when handling query.";
generateError(HttpResponse::BAD, TRI_ERROR_OUT_OF_MEMORY); generateError(HttpResponse::BAD, TRI_ERROR_OUT_OF_MEMORY);
@ -890,12 +902,13 @@ std::shared_ptr<VPackBuilder> RestAqlHandler::parseVelocyPackBody() {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
void RestAqlHandler::sendResponse(arangodb::rest::HttpResponse::HttpResponseCode const code, void RestAqlHandler::sendResponse(arangodb::rest::HttpResponse::HttpResponseCode const code,
VPackSlice const slice) { VPackSlice const slice,
TransactionContext* transactionContext) {
createResponse(code); createResponse(code);
_response->setContentType("application/json; charset=utf-8"); _response->setContentType("application/json; charset=utf-8");
arangodb::basics::VPackStringBufferAdapter buffer( arangodb::basics::VPackStringBufferAdapter buffer(
_response->body().stringBuffer()); _response->body().stringBuffer());
VPackDumper dumper(&buffer); VPackDumper dumper(&buffer, transactionContext->getVPackOptions());
try { try {
dumper.dump(slice); dumper.dump(slice);
} catch (...) { } catch (...) {

View File

@ -134,7 +134,8 @@ class RestAqlHandler : public RestVocbaseBaseHandler {
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
void sendResponse(arangodb::rest::HttpResponse::HttpResponseCode const, void sendResponse(arangodb::rest::HttpResponse::HttpResponseCode const,
arangodb::velocypack::Slice const); arangodb::velocypack::Slice const,
TransactionContext*);
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
/// @brief handle for useQuery /// @brief handle for useQuery