Skip to content

Instantly share code, notes, and snippets.

@tejus-gupta

tejus-gupta/read.py

Created Apr 19, 2019
Embed
What would you like to do?
if message_type == 'user_read':
key,_ = data.split('|')
highest_version = -1
highest_version_value = ''
#nodes = random.sample([(hash(key)+i)%N for i in range(R)], Q_r)
#nodes = random.sample(get_next_live_inc(hash(key), R), Q_r)
nodes = get_next_live_inc(hash(key), R)
nodes_replied = 0
for node in nodes:
try:
if node == server_idx:
value, version = database[key], database_version[key]
else:
tmp_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tmp_sock.connect(server_addresses[node])
tmp_sock.sendall(key+'|coordinator_read')
data = tmp_sock.recv(1000)
value, version, _ = data.split('|')
tmp_sock.close()
nodes_replied += 1
version = int(version)
if version > highest_version:
highest_version = version
highest_version_value = value
except socket.error:
continue ,
assert nodes_replied >= Q_r, "Didn't get reply from read quorum, most likely due to multiple failures"
connection.sendall(highest_version_value+'|user_read_reply')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.