#ifndef DGRIDD_DATASTORE_H
|
#define DGRIDD_DATASTORE_H
|
|
#include <map>
|
#include <memory>
|
#include <mutex>
|
#include "dgrid.h"
|
#include "dgrid_req_structs.h"
|
|
namespace DGrid {
|
|
class DGriddNodeArbiter;
|
class DGriddDataStoreSimple;
|
class DGriddDataStoreTable;
|
class TableDescription;
|
|
struct TableIDhasher
|
{
|
uint64_t operator()(const TableID& k) const;
|
};
|
|
class DGriddDataStore
|
{
|
private:
|
DGriddDataStore();
|
~DGriddDataStore();
|
static DGriddDataStore* _instance;
|
DGriddNodeArbiter* _node_arbiter;
|
|
public:
|
static DGriddDataStore* instance();
|
static void destroy();
|
void setNodeArbiter(DGriddNodeArbiter*);
|
DGriddNodeArbiter* getNodeArbiter();
|
void showStats(const uint8_t detail_level);
|
void clearSession(std::string session);
|
void list_sessions_simple(std::vector<std::string>& list);
|
void list_sessions_table(std::vector<std::string>& list);
|
void list_tablespaces(const std::string& session, std::vector<std::string>& list);
|
|
std::shared_ptr<DGriddDataStoreSimple> simple(const std::string& session = "");
|
std::shared_ptr<DGriddDataStoreTable> table(const std::string& session = "", const std::string& space = "");
|
std::shared_ptr<DGriddDataStoreTable> table(const TableID& table_id, std::string& tname);
|
bool hasTable(const TableID& table_id);
|
|
void registerTable(const NodeID& master_node, TableFullID& id_table);
|
void setMasterNode(const TableID& id_table, const NodeID& id_node);
|
NodeID getMasterNode(const TableID& id_table);
|
void setFallbackNodes(const TableID& id_table, const std::vector<NodeID>& nodes);
|
std::vector<NodeID> getFallbackNodes(const TableID& id_table);
|
const TableID getTableID(const std::string& session, const std::string& space, const std::string& tname);
|
bool deregisterTable(const std::string& session, const std::string& space, const std::string& tname);
|
bool deregisterTable(const TableID& id);
|
const TableID createTableID();
|
|
private:
|
std::shared_ptr<TableDescription> getTableDescription(const TableID& id);
|
void deregisterSessionTables_int(const std::string& session);
|
const TableID getTableID_int(const std::string& session, const std::string& space, const std::string& tname);
|
|
// глобальное хранилище
|
std::shared_ptr<DGriddDataStoreSimple> _simple_default;
|
std::shared_ptr<DGriddDataStoreTable> _table_default;
|
|
// сессионные хранилища
|
std::mutex simple_session_mutex;
|
std::mutex table_session_mutex;
|
std::unordered_map<std::string, std::shared_ptr<DGriddDataStoreSimple> > _simple_session;
|
std::unordered_map<std::string, std::unordered_map<std::string, std::shared_ptr<DGriddDataStoreTable> > > _table_session;
|
|
// идентификаторы таблиц
|
std::mutex table_reg_mutex;
|
std::unordered_map<TableID, std::shared_ptr<TableDescription>, TableIDhasher> registered_tables;
|
};
|
|
} // namespace DGrid
|
|
#endif // DGRIDD_DATASTORE_H
|