Skip to content
Snippets Groups Projects
Commit db0e8964 authored by Hang's avatar Hang
Browse files

fast push

parent 09764cfe
No related branches found
No related tags found
1 merge request!10MP3 Log Version Ready
......@@ -9,6 +9,8 @@ import socket
PORT = 8888
CURRNT_SERVER = socket.gethostbyname(socket.gethostname())
ADDR = (CURRNT_SERVER, PORT)
SERVER_ID_TO_IP_MAPPING = {}
IP_TO_SERVER_ID_MAPPING = {}
def parse_config(config_path: str) -> dict:
......@@ -30,10 +32,11 @@ def pick_coordinator(servers: dict):
def connect(coordinator_info: tuple):
coordinator_address = coordinator_info[1][SERVER_ADDRESS]
coordinator_ip_address = SERVER_ID_TO_IP_MAPPING[coordinator_info[SERVER_IDENTIFIER]]
# coordinator_address = coordinator_info[1][SERVER_ADDRESS]
coordinator_port_number = coordinator_info[1][SERVER_PORT]
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
address = (coordinator_address, coordinator_port_number)
address = (coordinator_ip_address, coordinator_port_number)
pprint(f'[connect] - client connect to address {address}')
client.connect(address)
return client
......@@ -58,10 +61,18 @@ def send_operation(operation_str, socket):
socket.sendall(msg)
def map_hostname_to_ip(servers):
for server_id, server in servers.items():
SERVER_ID_TO_IP_MAPPING[server_id] = socket.gethostbyname(server[SERVER_ADDRESS])
IP_TO_SERVER_ID_MAPPING[SERVER_ID_TO_IP_MAPPING[server_id]] = server_id
if __name__ == '__main__':
client_name = sys.argv[1]
config_path = sys.argv[2]
servers = parse_config(config_path)
map_hostname_to_ip(servers)
coordinator_info = pick_coordinator(servers)
client_to_coordinator_socket = connect(coordinator_info)
pprint('[client_to_coordinator_socket] CONNECT SUCCESS!')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment