1
0
Fork 0

Merge branch 'devel' of https://github.com/triAGENS/ArangoDB into devel

This commit is contained in:
Jan Steemann 2014-10-01 15:35:26 +02:00
commit d381031972
6 changed files with 45 additions and 64 deletions

View File

@ -118,7 +118,7 @@ size_t const ExecutionBlock::DefaultBatchSize = 1000;
ExecutionBlock::ExecutionBlock (ExecutionEngine* engine, ExecutionBlock::ExecutionBlock (ExecutionEngine* engine,
ExecutionNode const* ep) ExecutionNode const* ep)
: _engine(engine), : _engine(engine),
_trx(engine->getTransaction()), _trx(engine->getQuery()->trx()),
_exeNode(ep), _exeNode(ep),
_done(false) { _done(false) {
} }
@ -3829,7 +3829,7 @@ std::cout << "SENDING REQUEST TO " << _server << ", URLPART: " << urlPart << ",
_server, _server,
type, type,
std::string("/_db/") std::string("/_db/")
+ triagens::basics::StringUtils::urlEncode(_engine->getTransaction()->vocbase()->_name) + triagens::basics::StringUtils::urlEncode(_engine->getQuery()->trx()->vocbase()->_name)
+ urlPart + _queryId, + urlPart + _queryId,
body, body,
headers, headers,
@ -3865,7 +3865,7 @@ int RemoteBlock::initializeCursor (AqlItemBlock* items, size_t pos) {
} }
else { else {
body("pos", Json(static_cast<double>(pos))) body("pos", Json(static_cast<double>(pos)))
("items", items->toJson(_engine->getTransaction())); ("items", items->toJson(_engine->getQuery()->trx()));
} }
std::string bodyString(body.toString()); std::string bodyString(body.toString());

View File

@ -148,12 +148,10 @@ static ExecutionBlock* createBlock (ExecutionEngine* engine,
/// @brief create the engine /// @brief create the engine
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ExecutionEngine::ExecutionEngine (AQL_TRANSACTION_V8* trx, ExecutionEngine::ExecutionEngine (Query* query)
Query* query)
: _stats(), : _stats(),
_blocks(), _blocks(),
_root(nullptr), _root(nullptr),
_trx(trx),
_query(query) { _query(query) {
_blocks.reserve(8); _blocks.reserve(8);
@ -270,7 +268,7 @@ struct CoordinatorInstanciator : public WalkerWorker<ExecutionNode> {
std::vector<ExecutionNode*> nodes; std::vector<ExecutionNode*> nodes;
}; };
AQL_TRANSACTION_V8* trx; std::shared_ptr<AQL_TRANSACTION_V8> trx;
Query* query; Query* query;
QueryRegistry* queryRegistry; QueryRegistry* queryRegistry;
ExecutionBlock* root; ExecutionBlock* root;
@ -280,10 +278,9 @@ struct CoordinatorInstanciator : public WalkerWorker<ExecutionNode> {
std::vector<size_t> engineIds; // stack of engine ids, used for subqueries std::vector<size_t> engineIds; // stack of engine ids, used for subqueries
CoordinatorInstanciator (AQL_TRANSACTION_V8* trx, CoordinatorInstanciator (Query* query,
Query* query,
QueryRegistry* queryRegistry) QueryRegistry* queryRegistry)
: trx(trx), : trx(query->getTrxPtr()),
query(query), query(query),
queryRegistry(queryRegistry), queryRegistry(queryRegistry),
root(nullptr), root(nullptr),
@ -316,7 +313,6 @@ struct CoordinatorInstanciator : public WalkerWorker<ExecutionNode> {
if ((*it).id > 0) { if ((*it).id > 0) {
Query *otherQuery = query->clone(PART_DEPENDENT); Query *otherQuery = query->clone(PART_DEPENDENT);
otherQuery->trx(trx);
otherQuery->engine(engine); otherQuery->engine(engine);
auto *newPlan = new ExecutionPlan(otherQuery->ast()); auto *newPlan = new ExecutionPlan(otherQuery->ast());
@ -550,7 +546,7 @@ std::cout << "REGISTERING QUERY ON COORDINATOR WITH ID: " << id << "\n";
ExecutionEngine* buildEngineCoordinator (EngineInfo& info, ExecutionEngine* buildEngineCoordinator (EngineInfo& info,
std::unordered_map<std::string, std::string> const& queryIds) { std::unordered_map<std::string, std::string> const& queryIds) {
std::unique_ptr<ExecutionEngine> engine(new ExecutionEngine(trx, query)); std::unique_ptr<ExecutionEngine> engine(new ExecutionEngine(query));
std::unordered_map<ExecutionNode*, ExecutionBlock*> cache; std::unordered_map<ExecutionNode*, ExecutionBlock*> cache;
RemoteNode* remoteNode = nullptr; RemoteNode* remoteNode = nullptr;
@ -689,7 +685,6 @@ void ExecutionEngine::addBlock (ExecutionBlock* block) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ExecutionEngine* ExecutionEngine::instanciateFromPlan (QueryRegistry* queryRegistry, ExecutionEngine* ExecutionEngine::instanciateFromPlan (QueryRegistry* queryRegistry,
AQL_TRANSACTION_V8* trx,
Query* query, Query* query,
ExecutionPlan* plan) { ExecutionPlan* plan) {
ExecutionEngine* engine = nullptr; ExecutionEngine* engine = nullptr;
@ -704,8 +699,7 @@ ExecutionEngine* ExecutionEngine::instanciateFromPlan (QueryRegistry* queryRegis
if (isCoordinator()) { if (isCoordinator()) {
// instanciate the engine on the coordinator // instanciate the engine on the coordinator
query->trx(trx); std::unique_ptr<CoordinatorInstanciator> inst(new CoordinatorInstanciator(query, queryRegistry));
std::unique_ptr<CoordinatorInstanciator> inst(new CoordinatorInstanciator(trx, query, queryRegistry));
plan->root()->walk(inst.get()); plan->root()->walk(inst.get());
engine = inst.get()->buildEngines(); engine = inst.get()->buildEngines();
@ -713,7 +707,7 @@ ExecutionEngine* ExecutionEngine::instanciateFromPlan (QueryRegistry* queryRegis
} }
else { else {
// instanciate the engine on a local server // instanciate the engine on a local server
engine = new ExecutionEngine(trx, query); engine = new ExecutionEngine(query);
std::unique_ptr<Instanciator> inst(new Instanciator(engine)); std::unique_ptr<Instanciator> inst(new Instanciator(engine));
plan->root()->walk(inst.get()); plan->root()->walk(inst.get());
root = inst.get()->root; root = inst.get()->root;

View File

@ -58,8 +58,7 @@ namespace triagens {
/// @brief create the engine /// @brief create the engine
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
ExecutionEngine (AQL_TRANSACTION_V8* trx, ExecutionEngine (Query* query);
Query* query);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief destroy the engine, frees all assigned blocks /// @brief destroy the engine, frees all assigned blocks
@ -84,7 +83,6 @@ namespace triagens {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static ExecutionEngine* instanciateFromPlan (QueryRegistry*, static ExecutionEngine* instanciateFromPlan (QueryRegistry*,
AQL_TRANSACTION_V8*,
Query*, Query*,
ExecutionPlan*); ExecutionPlan*);
@ -106,14 +104,6 @@ namespace triagens {
_root = root; _root = root;
} }
////////////////////////////////////////////////////////////////////////////////
/// @brief get the transaction
////////////////////////////////////////////////////////////////////////////////
AQL_TRANSACTION_V8* getTransaction () const {
return _trx;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief get the query /// @brief get the query
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -231,12 +221,6 @@ namespace triagens {
ExecutionBlock* _root; ExecutionBlock* _root;
////////////////////////////////////////////////////////////////////////////////
/// @brief a pointer to the transaction for this query
////////////////////////////////////////////////////////////////////////////////
AQL_TRANSACTION_V8* _trx;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief a pointer to the query /// @brief a pointer to the query
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -517,12 +517,14 @@ triagens::basics::Json ExecutionNode::toJsonHelperGeneric (triagens::basics::Jso
json("regsToClear", jsonRegsToClearList); json("regsToClear", jsonRegsToClearList);
} }
else { else {
Json emptyList(Json::List); Json emptyList1(Json::List);
json("varInfoList", emptyList); json("varInfoList", emptyList1);
json("nrRegs", emptyList); Json emptyList2(Json::List);
json("nrRegs", emptyList2);
json("regsToClear", emptyList); Json emptyList3(Json::List);
json("regsToClear", emptyList3);
} }
return json; return json;
} }

View File

@ -244,6 +244,7 @@ Query* Query::clone (QueryPart part) {
theClone->_plan = _plan->clone(*theClone); theClone->_plan = _plan->clone(*theClone);
} }
theClone->_trx = _trx;
return theClone; return theClone;
} }
@ -361,15 +362,18 @@ QueryResult Query::prepare (QueryRegistry* registry) {
// std::cout << "AST: " << triagens::basics::JsonHelper::toString(parser->ast()->toJson(TRI_UNKNOWN_MEM_ZONE, false)) << "\n"; // std::cout << "AST: " << triagens::basics::JsonHelper::toString(parser->ast()->toJson(TRI_UNKNOWN_MEM_ZONE, false)) << "\n";
} }
std::shared_ptr<AQL_TRANSACTION_V8> trx(new AQL_TRANSACTION_V8(_vocbase, _collections.collections()));
_trx = trx;
// create the transaction object, but do not start it yet // create the transaction object, but do not start it yet
std::unique_ptr<AQL_TRANSACTION_V8> trx(new AQL_TRANSACTION_V8(_vocbase, _collections.collections())); // _trx = new std::shared_ptr<AQL_TRANSACTION_V8>(_vocbase, _collections.collections());
if (_queryString != nullptr) { if (_queryString != nullptr) {
// we have an AST // we have an AST
int res = trx->begin(); int res = _trx->begin();
if (res != TRI_ERROR_NO_ERROR) { if (res != TRI_ERROR_NO_ERROR) {
return transactionError(res, *trx); return transactionError(res);
} }
enterState(PLAN_INSTANCIATION); enterState(PLAN_INSTANCIATION);
@ -385,14 +389,14 @@ QueryResult Query::prepare (QueryRegistry* registry) {
// creating the plan may have produced some collections // creating the plan may have produced some collections
// we need to add them to the transaction now (otherwise the query will fail) // we need to add them to the transaction now (otherwise the query will fail)
int res = trx->addCollectionList(_collections.collections()); int res = _trx->addCollectionList(_collections.collections());
if (res == TRI_ERROR_NO_ERROR) { if (res == TRI_ERROR_NO_ERROR) {
res = trx->begin(); res = _trx->begin();
} }
if (res != TRI_ERROR_NO_ERROR) { if (res != TRI_ERROR_NO_ERROR) {
return transactionError(res, *trx); return transactionError(res);
} }
// we have an execution plan in JSON format // we have an execution plan in JSON format
@ -426,13 +430,12 @@ QueryResult Query::prepare (QueryRegistry* registry) {
TRI_ASSERT(otherJsonString == JsonString); */ TRI_ASSERT(otherJsonString == JsonString); */
enterState(EXECUTION); enterState(EXECUTION);
ExecutionEngine* engine(ExecutionEngine::instanciateFromPlan(registry, trx.get(), this, plan.get())); ExecutionEngine* engine(ExecutionEngine::instanciateFromPlan(registry, this, plan.get()));
// If all went well so far, then we keep _plan, _parser and _trx and // If all went well so far, then we keep _plan, _parser and _trx and
// return: // return:
_plan = plan.release(); _plan = plan.release();
_parser = parser.release(); _parser = parser.release();
_trx = trx.release();
_engine = engine; _engine = engine;
return QueryResult(); return QueryResult();
} }
@ -481,7 +484,7 @@ QueryResult Query::execute (QueryRegistry* registry) {
AqlValue val = value->getValue(i, 0); AqlValue val = value->getValue(i, 0);
if (! val.isEmpty()) { if (! val.isEmpty()) {
json.add(val.toJson(_trx, doc)); json.add(val.toJson(trx(), doc));
} }
} }
delete value; delete value;
@ -590,13 +593,14 @@ QueryResult Query::explain () {
// std::cout << "AST: " << triagens::basics::JsonHelper::toString(parser.ast()->toJson(TRI_UNKNOWN_MEM_ZONE)) << "\n"; // std::cout << "AST: " << triagens::basics::JsonHelper::toString(parser.ast()->toJson(TRI_UNKNOWN_MEM_ZONE)) << "\n";
// create the transaction object, but do not start it yet // create the transaction object, but do not start it yet
AQL_TRANSACTION_V8 trx(_vocbase, _collections.collections()); std::shared_ptr<AQL_TRANSACTION_V8> trx(new AQL_TRANSACTION_V8(_vocbase, _collections.collections()));
_trx = trx;
// we have an AST // we have an AST
int res = trx.begin(); int res = _trx->begin();
if (res != TRI_ERROR_NO_ERROR) { if (res != TRI_ERROR_NO_ERROR) {
return transactionError(res, trx); return transactionError(res);
} }
enterState(PLAN_INSTANCIATION); enterState(PLAN_INSTANCIATION);
@ -612,7 +616,7 @@ QueryResult Query::explain () {
// get enabled/disabled rules // get enabled/disabled rules
opt.createPlans(plan, getRulesFromOptions()); opt.createPlans(plan, getRulesFromOptions());
trx.commit(); _trx->commit();
enterState(FINALIZATION); enterState(FINALIZATION);
@ -765,11 +769,10 @@ double Query::getNumericOption (char const* option, double defaultValue) const {
/// @brief neatly format transaction error to the user. /// @brief neatly format transaction error to the user.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
QueryResult Query::transactionError (int errorCode, QueryResult Query::transactionError (int errorCode) const {
AQL_TRANSACTION_V8 const& trx) const {
std::string err(TRI_errno_string(errorCode)); std::string err(TRI_errno_string(errorCode));
auto detail = trx.getErrorData(); auto detail = _trx->getErrorData();
if (detail.size() > 0) { if (detail.size() > 0) {
err += std::string(" (") + detail + std::string(")"); err += std::string(" (") + detail + std::string(")");
} }
@ -848,12 +851,7 @@ void Query::cleanupPlanAndEngine () {
_engine = nullptr; _engine = nullptr;
} }
if (_trx != nullptr) { _trx.reset();
if (_part == PART_MAIN) {
delete _trx;
_trx = nullptr;
}
}
if (_parser != nullptr) { if (_parser != nullptr) {
delete _parser; delete _parser;

View File

@ -59,7 +59,7 @@ namespace triagens {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief query part /// @brief equery part
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
enum QueryPart { enum QueryPart {
@ -337,18 +337,21 @@ namespace triagens {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
AQL_TRANSACTION_V8* trx () { AQL_TRANSACTION_V8* trx () {
return _trx; return &*_trx;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief set the transaction for the query /// @brief set the transaction for the query
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void trx (AQL_TRANSACTION_V8* trx) { void setTrxPtr (std::shared_ptr<AQL_TRANSACTION_V8>& trx) {
TRI_ASSERT(_trx == nullptr); TRI_ASSERT(_trx == nullptr);
_trx = trx; _trx = trx;
} }
std::shared_ptr<AQL_TRANSACTION_V8>& getTrxPtr () {
return _trx;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief set the plan for the query /// @brief set the plan for the query
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -383,7 +386,7 @@ namespace triagens {
/// @brief neatly format transaction errors to the user. /// @brief neatly format transaction errors to the user.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
QueryResult transactionError (int errorCode, AQL_TRANSACTION_V8 const& trx) const; QueryResult transactionError (int errorCode) const;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief enter a new state /// @brief enter a new state
@ -518,7 +521,7 @@ namespace triagens {
/// to the HTTP API for queries. /// to the HTTP API for queries.
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
AQL_TRANSACTION_V8* _trx; std::shared_ptr<AQL_TRANSACTION_V8> _trx;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
/// @brief the ExecutionEngine object, if the query is prepared /// @brief the ExecutionEngine object, if the query is prepared