Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#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