1+ import socket
2+ import pickle
3+ import sys
4+ sys .path .insert (1 , '../utils/' )
5+
6+ from transfer import _send_msg , _recv_msg , _wait_recv_msg
7+ from info import RECV_PRIMARY_UPDATE_PORT , MSG_SIZE
8+
9+ hashtable = {}
10+ MDS_flags = {}
11+ cluster_topology = {}
12+
13+ def recv_primary_update ():
14+ recv_primary_update_socket = socket .socket ()
15+ print ("recv primary update socket successfully created" )
16+ recv_primary_update_socket .setsockopt (socket .SOL_SOCKET , socket .SO_REUSEADDR , 1 )
17+
18+ # reserve a port on your computer
19+ port = RECV_PRIMARY_UPDATE_PORT
20+
21+ # Next bind to the port
22+ # we have not entered any ip in the ip field
23+ # instead we have inputted an empty string
24+ # this makes the server listen to requests
25+ # coming from other computers on the network
26+ recv_primary_update_socket .bind (('' , port ))
27+ print ("primary update socket bound to %s" % (port ))
28+
29+ # put the socket into listening mode
30+ recv_primary_update_socket .listen (5 )
31+ print ("primary update socket is listening" )
32+
33+ # a forever loop until we interrupt it or
34+ # an error occurs
35+ while True :
36+
37+ # Establish connection with osd
38+ c , addr = recv_primary_update_socket .accept ()
39+ print ('Got connection from' , addr )
40+
41+ # recv the update
42+ update = _recv_msg (c , 1024 )
43+ print (update )
44+
45+ if update ["update_type" ] == "hash_table" :
46+ for i in range (len (update ["pg_or_osd_ids_list" ])):
47+ hashtable [update ["pg_or_osd_ids_list" ][i ]] = update ["osd_list" ][i ]
48+ else :
49+ for i in range (len (update ["pg_or_osd_ids_list" ])):
50+ cluster_topology [update ["pg_or_osd_ids_list" ][i ]] = update ["osd_list" ][i ]
51+
52+ hashtable_file = open ('hashtable' , 'wb' )
53+ hashtable_dump = pickle .dumps (hashtable )
54+ hashtable_file .write (hashtable_dump )
55+ hashtable_file .close ()
56+
57+ cluster_topology_file = open ('cluster_topology' , 'wb' )
58+ cluster_topology_dump = pickle .dumps (cluster_topology )
59+ cluster_topology_file .write (cluster_topology_dump )
60+ cluster_topology_file .close ()
61+ msg = {"status" :"SUCCESS" }
62+ _send_msg (c , msg )
63+ # send the acknowledgement
64+ c .close ()
65+
66+ recv_primary_update_socket .close ()
67+
68+ def main ():
69+ global hashtable , cluster_topology , MDS_flags
70+
71+ hashtable_file = open ('hashtable' , 'rb' )
72+ hashtable_dump = hashtable_file .read ()
73+ hashtable = pickle .loads (hashtable_dump )
74+
75+ MDS_flags_file = open ('MDS_flags' , 'rb' )
76+ MDS_flags_dump = MDS_flags_file .read ()
77+ MDS_flags = pickle .loads (MDS_flags_dump )
78+
79+ cluster_topology_file = open ('cluster_topology' , 'rb' )
80+ cluster_topology_dump = cluster_topology_file .read ()
81+ cluster_topology = pickle .loads (cluster_topology_dump )
82+
83+ hashtable_file .close ()
84+ MDS_flags_file .close ()
85+ cluster_topology_file .close ()
86+ recv_primary_update ()
87+
88+ if __name__ == '__main__' :
89+ main ()
0 commit comments