-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.py
27 lines (22 loc) · 894 Bytes
/
data.py
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
"""
data.py
Description:
This file contains the defnition of the PendingElement class.
The PendingElement contains a key-value pair along with
the message id, list of nodes who acknowledged it and the client address.
It is used to store writes in the acknowledgement buffer until all
nodes in the system have acknoledged it.
"""
class PendingElement:
def __init__(self, keys, values, msg_id, client_addr):
self.keys = keys
self.values = values
self.msg_id = msg_id
self.acknowledged = set()
self.client_addr = client_addr
# Adds node_port to set of nodes who acknowledged the write
def acknowledge(self, node_port):
self.acknowledged.add(node_port)
# Checks whether all nodes have acknowledged the write
def is_complete(self, number_of_nodes):
return len(self.acknowledged) == number_of_nodes