1
0
Fork 0

Sort out shardId for ScatterBlock and HTTP API.

This commit is contained in:
Max Neunhoeffer 2014-10-02 10:24:47 +02:00
parent a59d1e4448
commit d021bcf720
1 changed files with 66 additions and 23 deletions

View File

@ -488,6 +488,13 @@ void RestAqlHandler::getInfoQuery (std::string const& operation,
std::string const& idString) {
// the GET verb
bool found;
std::string shardId;
char const* shardIdCharP = _request->header("shard-id", found);
if (found && shardIdCharP != nullptr) {
shardId = shardIdCharP;
}
QueryId qId;
Query* query = nullptr;
if (findQuery(idString, qId, query)) {
@ -498,6 +505,7 @@ void RestAqlHandler::getInfoQuery (std::string const& operation,
TRI_ASSERT(query->engine() != nullptr);
try {
int64_t number;
if (operation == "count") {
number = query->engine()->count();
@ -509,6 +517,8 @@ void RestAqlHandler::getInfoQuery (std::string const& operation,
}
}
else if (operation == "remaining") {
// FIXME:
// Do the !shardId.empty() case once the ScatterBlock has remainingForShard
number = query->engine()->remaining();
if (number == -1) {
answerBody("remaining", Json("unknown"));
@ -518,7 +528,18 @@ void RestAqlHandler::getInfoQuery (std::string const& operation,
}
}
else if (operation == "hasMore") {
bool hasMore = query->engine()->hasMore();
bool hasMore;
if (shardId.empty()) {
hasMore = query->engine()->hasMore();
}
else {
auto scatter = static_cast<ScatterBlock*>(query->engine()->root());
if (scatter->getPlanNode()->getType() != ExecutionNode::SCATTER) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_INTERNAL);
}
hasMore = scatter->hasMoreForShard(shardId);
}
answerBody("hasMore", Json(hasMore));
}
else {
@ -526,6 +547,28 @@ void RestAqlHandler::getInfoQuery (std::string const& operation,
generateError(HttpResponse::NOT_FOUND, TRI_ERROR_HTTP_NOT_FOUND);
return;
}
}
catch (triagens::arango::Exception const& ex) {
_queryRegistry->close(_vocbase, qId);
generateError(HttpResponse::SERVER_ERROR,
ex.code(),
ex.message());
}
catch (std::exception const& ex) {
_queryRegistry->close(_vocbase, qId);
generateError(HttpResponse::SERVER_ERROR,
TRI_ERROR_HTTP_SERVER_ERROR,
ex.what());
}
catch (...) {
_queryRegistry->close(_vocbase, qId);
generateError(HttpResponse::SERVER_ERROR,
TRI_ERROR_HTTP_SERVER_ERROR,
"an unknown exception occurred");
}
_queryRegistry->close(_vocbase, qId);
@ -661,7 +704,7 @@ void RestAqlHandler::handleUseQuery (std::string const& operation,
bool found;
std::string shardId;
char const* shardIdCharP = _request->header("shard-id", found);
if (shardIdCharP != nullptr) {
if (found && shardIdCharP != nullptr) {
shardId = shardIdCharP;
}