Skip to content

Instantly share code, notes, and snippets.

@chelseatroy
Last active July 26, 2020 03:38
Show Gist options
  • Save chelseatroy/b12cc1632faf1dd991db695a046a2f41 to your computer and use it in GitHub Desktop.
Save chelseatroy/b12cc1632faf1dd991db695a046a2f41 to your computer and use it in GitHub Desktop.
Conditional Statement—Responding to append_entries Requests
...
if string_operation.split(" ")[0] == "append_entries":
# followers do this to update their logs.
stringified_logs_to_append = string_operation.replace("append_entries ", "")
print("Preparing to append: " + stringified_logs_to_append)
logs_to_append = ast.literal_eval(stringified_logs_to_append)
[key_value_store.write_to_log(log, term_absent=True) for log in logs_to_append]
print("State machine after appending: " + str(key_value_store.data))
response = "Append entries call successful!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment