Исходный код СУБД 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
#ifndef DGRIDD_NODE_ARBITER_H
#define DGRIDD_NODE_ARBITER_H
 
#include <map>
#include <set>
#include <queue>
#include <string>
#include <mutex>
#include "dgrid_thread.h"
 
namespace DGrid {
 
class DGridNodeClient;
 
class DGriddNodeArbiter: public DGriddThread
{
public:
    DGriddNodeArbiter();
    ~DGriddNodeArbiter();
    bool start();
    void stop();
 
    // stats
    void showStats();
    uint16_t activeNodesCount();
    uint16_t knownNodesCount();
 
    // data requests
    DGridResult get_theme_simple(const std::string& session, const std::string& theme_name, SimpleValueMap& data, const NodeID& old_source);
    DGridResult append_theme_simple(const std::string& session, const std::string& theme_name, const SimpleValueMap& data, const NodeID& old_source);
    DGridResult sync_theme_simple(const std::string& session, const std::string& theme_name, SimpleValueMap& data);
 
    DGridResult table__get_master_node(const TableFullID& full_id, TableID& table_id, NodeID& node_id);
    DGridResult table__choose_fallback_nodes(std::vector<NodeID>& nodes);
    DGridResult table__request_passthru(const NodeID& node_id, const RequestType type, const RequestSubType subtype, const std::vector<char>& payload, std::vector<char>& response);
 
protected:
    virtual void run();
    void checkConnections();
 
    void processEvents();
    void eventHandler(std::shared_ptr<DGridEvent> e);
    DGridNodeClient* getNode(const NodeID& id);
    DGridResult notify_old_source(const std::string& session, const std::string& theme_name, const SimpleValueMap& data, const NodeID& old_source);
 
private:
    void pushEvent(std::shared_ptr<DGridEvent> e);
    std::shared_ptr<DGridEvent> popEvent();
    std::mutex equeue_mutex;
    std::queue<std::shared_ptr<DGridEvent> > equeue;
 
    uint16_t redundancy_level;
    uint32_t reconnect_interval;
    std::set<DGridNodeClient*> node_clients;
    std::map<NodeID, DGridNodeClient*> nodes_active;
    std::map<DGridNodeClient*, NodeID> nodes_lost;
    std::set<NodeID> nodes_dead;
};
 
} // namespace DGrid
 
#endif // DGRIDD_NODE_ARBITER_H