Add creation of unique database transaction

This commit is contained in:
Josip Mrden 2024-03-22 12:14:39 +01:00
parent 1e7dad000f
commit 15e7f1fa02
2 changed files with 10 additions and 5 deletions

View File

@ -736,6 +736,8 @@ class DbAccessor final {
const std::set<storage::PropertyId> &properties) {
return accessor_->DropUniqueConstraint(label, properties);
}
void DropGraph() { return accessor_->DropGraph(); }
};
class SubgraphDbAccessor final {

View File

@ -3321,15 +3321,14 @@ Callback SwitchMemoryDevice(storage::StorageMode current_mode, storage::StorageM
return callback;
}
Callback DropGraph(memgraph::dbms::DatabaseAccess &db) {
Callback DropGraph(memgraph::dbms::DatabaseAccess &db, DbAccessor *dba) {
Callback callback;
callback.fn = [&db]() mutable {
auto storage = db->UniqueAccess();
callback.fn = [&db, dba]() mutable {
auto storage_mode = db->GetStorageMode();
if (storage_mode != storage::StorageMode::IN_MEMORY_ANALYTICAL) {
throw utils::BasicException("Drop graph can not be used without IN_MEMORY_ANALYTICAL storage mode!");
}
storage->DropGraph();
dba->DropGraph();
auto *trigger_store = db->trigger_store();
trigger_store->DropAll();
@ -3399,10 +3398,13 @@ PreparedQuery PrepareDropGraphQuery(ParsedQuery parsed_query, CurrentDB &current
MG_ASSERT(current_db.db_acc_, "Drop graph query expects a current DB");
memgraph::dbms::DatabaseAccess &db_acc = *current_db.db_acc_;
MG_ASSERT(current_db.db_transactional_accessor_, "Index query expects a current DB transaction");
auto *dba = &*current_db.execution_db_accessor_;
auto *drop_graph_query = utils::Downcast<DropGraphQuery>(parsed_query.query);
MG_ASSERT(drop_graph_query);
std::function<void()> callback = DropGraph(db_acc).fn;
std::function<void()> callback = DropGraph(db_acc, dba).fn;
return PreparedQuery{{},
std::move(parsed_query.required_privileges),
@ -4470,6 +4472,7 @@ Interpreter::PrepareResult Interpreter::Prepare(const std::string &query_string,
bool unique = utils::Downcast<IndexQuery>(parsed_query.query) != nullptr ||
utils::Downcast<EdgeIndexQuery>(parsed_query.query) != nullptr ||
utils::Downcast<ConstraintQuery>(parsed_query.query) != nullptr ||
utils::Downcast<DropGraphQuery>(parsed_query.query) != nullptr ||
upper_case_query.find(kSchemaAssert) != std::string::npos;
SetupDatabaseTransaction(could_commit, unique);
}