-
Notifications
You must be signed in to change notification settings - Fork 0
/
MP2Node.h
executable file
·98 lines (82 loc) · 2.35 KB
/
MP2Node.h
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/**********************************
* FILE NAME: MP2Node.h
*
* DESCRIPTION: MP2Node class header file
**********************************/
#ifndef MP2NODE_H_
#define MP2NODE_H_
/**
* Header files
*/
#include "stdincludes.h"
#include "EmulNet.h"
#include "Node.h"
#include "HashTable.h"
#include "Log.h"
#include "Params.h"
#include "Message.h"
#include "Queue.h"
const int StabilizationTid = -1;
/**
* CLASS NAME: MP2Node
*
* DESCRIPTION: This class encapsulates all the key-value store functionality
* including:
* 1) Ring
* 2) Stabilization Protocol
* 3) Server side CRUD APIs
* 4) Client side CRUD APIs
*/
class MP2Node {
private:
// Vector holding the next two neighbors in the ring who have my replicas
vector<Node> hasMyReplicas;
// Vector holding the previous two neighbors in the ring whose replicas I have
vector<Node> haveReplicasOf;
// Ring
vector<Node> ring;
// Hash Table
HashTable * ht;
// Member representing this member
Member *memberNode;
// Params object
Params *par;
// Object of EmulNet
EmulNet * emulNet;
// Object of Log
Log * log;
public:
MP2Node(Member *memberNode, Params *par, EmulNet *emulNet, Log *log, Address *addressOfMember);
Member * getMemberNode() {
return this->memberNode;
}
// ring functionalities
void updateRing();
vector<Node> getMembershipList();
size_t hashFunction(string key);
void findNeighbors();
// client side CRUD APIs
void clientCreate(string key, string value);
void clientRead(string key);
void clientUpdate(string key, string value);
void clientDelete(string key);
// receive messages from Emulnet
bool recvLoop();
static int enqueueWrapper(void *env, char *buff, int size);
// handle messages from receiving queue
void checkMessages();
// coordinator dispatches messages to corresponding nodes
void dispatchMessages(Message message);
// find the addresses of nodes that are responsible for a key
vector<Node> findNodes(string key);
// server
bool createKeyValue(string key, string value, ReplicaType replica);
string readKey(string key);
bool updateKeyValue(string key, string value, ReplicaType replica);
bool deletekey(string key);
// stabilization protocol - handle multiple failures
void stabilizationProtocol();
Message constructMsg(MessageType mType, string key, string value = "", bool success = false);
~MP2Node();
};
#endif /* MP2NODE_H_ */