Fix bug -db_accessor passed along as &

Summary: Db_accessor is tied to one transaction, and as such each query should work on seperate db_accessor.

Reviewers: florijan, buda

Reviewed By: buda

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D96
This commit is contained in:
Dominik Gleich 2017-03-07 14:14:56 +01:00
parent 8e1a897b7a
commit 57740bcf95
3 changed files with 15 additions and 13 deletions

View File

@ -35,8 +35,7 @@ int main(int argc, char *argv[]) {
// IMPORTANT: PrintRecordStream can be replaces with a smarter
// object that can test the results
auto db_accessor = dbms.active();
WarmUpEngine(log, query_engine, db_accessor, stream);
WarmUpEngine(log, query_engine, dbms, stream);
return 0;
}

View File

@ -4,6 +4,7 @@
#include <set>
namespace fs = std::experimental::filesystem;
#include "database/graph_db_accessor.hpp"
#include "dbms/dbms.hpp"
#include "logging/default.hpp"
#include "logging/streams/stdout.cpp"
#include "query/engine.hpp"
@ -120,15 +121,14 @@ auto LoadQueryPlans(Logger &log, QueryEngineT &engine,
*
* @param log external logger reference
* @param engine query engine
* @param db_accessor a database accessor on which the query plans are executed
* @param dbms a database to execute queries on
* @param path path a queries file
* @param stream used by query plans to output the results
*
* @return void
*/
auto ExecuteQueryPlans(Logger &log, QueryEngineT &engine,
GraphDbAccessor &db_accessor, const fs::path &path,
StreamT &stream) {
auto ExecuteQueryPlans(Logger &log, QueryEngineT &engine, Dbms &dbms,
const fs::path &path, StreamT &stream) {
log.info("*** Execute the queries from the queries_file ***");
// execute all queries from queries_file
auto queries = utils::read_lines(path);
@ -136,6 +136,9 @@ auto ExecuteQueryPlans(Logger &log, QueryEngineT &engine,
if (query.empty()) continue;
permanent_assert(engine.Loaded(trim(query)),
"Implementation wasn't loaded");
// Create new db_accessor since one query is associated with one
// transaction.
auto db_accessor = dbms.active();
engine.Run(query, db_accessor, stream);
}
}
@ -148,17 +151,17 @@ auto ExecuteQueryPlans(Logger &log, QueryEngineT &engine,
*
* @param log external logger reference
* @param engine query engine
* @param db_accessor a database accessor on which the query plans are executed
* @param dbms a database to execute queries on
* @param stream used by query plans to output the results
*
* @return void
*/
auto WarmUpEngine(Logger &log, QueryEngineT &engine,
GraphDbAccessor &db_accessor, StreamT &stream) {
auto WarmUpEngine(Logger &log, QueryEngineT &engine, Dbms &dbms,
StreamT &stream) {
// path to a file with queries
auto queries_file = fs::path(
GET_ARG("-q", "../data/queries/core/mg_basic_002.txt").get_string());
// forlder with query implementations
// folder with query implementations
auto implementations_folder =
fs::path(GET_ARG("-i", "../integration/hardcoded_query").get_string());
@ -169,7 +172,7 @@ auto WarmUpEngine(Logger &log, QueryEngineT &engine,
LoadQueryPlans(log, engine, query_hashes, implementations_folder);
// execute all loaded query plasn
ExecuteQueryPlans(log, engine, db_accessor, queries_file, stream);
ExecuteQueryPlans(log, engine, dbms, queries_file, stream);
}
}
}

View File

@ -18,13 +18,12 @@ int main(int argc, char* argv[]) {
// init engine
auto log = init_logging("ManualQueryEngine");
Dbms dbms;
auto db_accessor = dbms.active();
StreamT stream(std::cout); // inject path to data queries
QueryEngineT query_engine;
// IMPORTANT: PrintRecordStream can be replaces with a smarter
// object that can test the results
WarmUpEngine(log, query_engine, db_accessor, stream);
WarmUpEngine(log, query_engine, dbms, stream);
// init watcher
FSWatcher watcher;
@ -61,6 +60,7 @@ int main(int argc, char* argv[]) {
query_engine.Unload(query);
try {
query_engine.ReloadCustom(query, event.path);
auto db_accessor = dbms.active();
query_engine.Run(query, db_accessor, stream);
} catch (PlanCompilationException& e) {
log.info("Query compilation failed: {}", e.what());