Skip to content

Instantly share code, notes, and snippets.

@tejus-gupta
Created April 19, 2019 04:48
Show Gist options
  • Save tejus-gupta/11c8b76f56d277ee6196aaa8977f6d29 to your computer and use it in GitHub Desktop.
Save tejus-gupta/11c8b76f56d277ee6196aaa8977f6d29 to your computer and use it in GitHub Desktop.
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