Remove type method from GraphDb

Reviewers: msantl, vkasljevic, mferencevic

Reviewed By: msantl

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1577
This commit is contained in:
Teon Banek 2018-08-29 16:09:07 +02:00
parent 146c35ec4a
commit 2c732f3ea1
3 changed files with 24 additions and 33 deletions

View File

@ -437,10 +437,10 @@ class WorkerAccessor final : public DistributedAccessor {
// RecoveryTransactions implementations
//////////////////////////////////////////////////////////////////////
class DistributedRecoveryTransanctions
class DistributedRecoveryTransactions
: public durability::RecoveryTransactions {
public:
explicit DistributedRecoveryTransanctions(DistributedGraphDb *db) : db_(db) {}
explicit DistributedRecoveryTransactions(DistributedGraphDb *db) : db_(db) {}
void Begin(const tx::TransactionId &tx_id) override {
CHECK(accessors_.find(tx_id) == accessors_.end())
@ -463,30 +463,34 @@ class DistributedRecoveryTransanctions
}
protected:
virtual GraphDbAccessor *GetAccessor(const tx::TransactionId &tx_id) {
auto found = accessors_.find(tx_id);
// Currently accessors are created on transaction_begin, but since workers
// don't have a transaction begin, the accessors are not created.
if (db_->type() == database::GraphDb::Type::DISTRIBUTED_WORKER &&
found == accessors_.end()) {
std::tie(found, std::ignore) = accessors_.emplace(tx_id, db_->Access());
}
CHECK(found != accessors_.end())
<< "Accessor does not exist for transaction: " << tx_id;
return found->second.get();
}
virtual GraphDbAccessor *GetAccessor(const tx::TransactionId &tx_id) = 0;
DistributedGraphDb *db_;
std::unordered_map<tx::TransactionId, std::unique_ptr<GraphDbAccessor>>
accessors_;
};
class MasterRecoveryTransactions final
: public DistributedRecoveryTransactions {
public:
explicit MasterRecoveryTransactions(Master *db)
: DistributedRecoveryTransactions(db) {}
protected:
virtual GraphDbAccessor *GetAccessor(
const tx::TransactionId &tx_id) override {
auto found = accessors_.find(tx_id);
CHECK(found != accessors_.end())
<< "Accessor does not exist for transaction: " << tx_id;
return found->second.get();
}
};
class WorkerRecoveryTransactions final
: public DistributedRecoveryTransanctions {
: public DistributedRecoveryTransactions {
public:
explicit WorkerRecoveryTransactions(Worker *db)
: DistributedRecoveryTransanctions(db) {}
: DistributedRecoveryTransactions(db) {}
void Begin(const tx::TransactionId &tx_id) override {
LOG(FATAL) << "Unexpected transaction begin on worker recovery.";
@ -628,7 +632,7 @@ Master::Master(Config config)
// workers and on master
recovery_data.wal_tx_to_recover =
impl_->coordination_.CommonWalTransactions(*recovery_info);
DistributedRecoveryTransanctions recovery_transactions(this);
MasterRecoveryTransactions recovery_transactions(this);
durability::RecoverWalAndIndexes(impl_->config_.durability_directory,
this, &recovery_data,
&recovery_transactions);

View File

@ -45,10 +45,6 @@ class Master final : public DistributedGraphDb {
explicit Master(Config config = Config());
~Master();
GraphDb::Type type() const override {
return GraphDb::Type::DISTRIBUTED_MASTER;
}
std::unique_ptr<GraphDbAccessor> Access() override;
std::unique_ptr<GraphDbAccessor> Access(tx::TransactionId) override;
@ -93,10 +89,6 @@ class Worker final : public DistributedGraphDb {
explicit Worker(Config config = Config());
~Worker();
GraphDb::Type type() const override {
return GraphDb::Type::DISTRIBUTED_WORKER;
}
std::unique_ptr<GraphDbAccessor> Access() override;
std::unique_ptr<GraphDbAccessor> Access(tx::TransactionId) override;

View File

@ -1,3 +1,4 @@
/// @file
#pragma once
#include <atomic>
@ -48,7 +49,7 @@ struct Config {
class GraphDbAccessor;
/// An abstract base class for a SingleNode/Master/Worker graph db.
/// An abstract base class providing the interface for a graph database.
///
/// Always be sure that GraphDb object is destructed before main exits, i. e.
/// GraphDb object shouldn't be part of global/static variable, except if its
@ -71,8 +72,6 @@ class GraphDbAccessor;
/// -> CRASH
class GraphDb {
public:
enum class Type { SINGLE_NODE, DISTRIBUTED_MASTER, DISTRIBUTED_WORKER };
GraphDb() {}
GraphDb(const GraphDb &) = delete;
GraphDb(GraphDb &&) = delete;
@ -81,8 +80,6 @@ class GraphDb {
virtual ~GraphDb() {}
virtual Type type() const = 0;
/// Create a new accessor by starting a new transaction.
virtual std::unique_ptr<GraphDbAccessor> Access() = 0;
/// Create an accessor for a running transaction.
@ -123,8 +120,6 @@ class SingleNode final : public GraphDb {
explicit SingleNode(Config config = Config());
~SingleNode();
Type type() const override { return GraphDb::Type::SINGLE_NODE; }
std::unique_ptr<GraphDbAccessor> Access() override;
std::unique_ptr<GraphDbAccessor> Access(tx::TransactionId) override;