Esempio n. 1
0
 def perform_put(self, *data):
     dict = data[0]
     key = dict.key
     preference_list = self.hash_ring.get_node(key, self.failed_nodes)
     if (self not in preference_list):
         coordinator = preference_list[0].id
         dict = Request("FORWARD-PUT", dict.key, dict.value,
                        generate_random_number(), dict.client)
         Messaging.send_message(self, coordinator, dict)
         time.sleep(3)
         if REQUESTS.get(dict.request, False) != True:
             #print("Timedout PUT")
             dict.action = "PUT"
             dict.request = generate_random_number()
             self.socket.settimeout(None)
             self.failed_nodes.append(coordinator)
             self.perform_put(dict)
     else:
         self.vector_clock.update(self.id, self.get_sequence_no())
         metadata = deepcopy(self.vector_clock)
         if dict.value[1] > metadata:
             metadata = dict.value[1]
         dict.value = (dict.value[0], metadata)
         dict.request = generate_random_number()
         Messaging.broadcast_put(self, preference_list, dict)
Esempio n. 2
0
 def broadcast_get(from_node, node_list, msg):
     if (len(node_list) == 0):
         if len(HISTORY.get(msg.request, set())) < from_node.W:
             from_node.socket.sendto(pickle.dumps("FAILURE"),
                                     ('localhost', msg.client))
         return
     msg = Request("FETCH", msg.key, msg.value, generate_random_number(),
                   msg.client)
     nodes = []
     for node in node_list:
         nodes.append(node.id)
         #print("Preference list="+node.id+msg.action)
         Messaging.send_message(from_node, node.id, msg)
     cur_time = time.time()
     while int(time.time() - cur_time) < 3:
         if not REQUESTS.get(msg.request, False) and len(
                 HISTORY.get(msg.request, set())) >= from_node.R:
             result = list()
             for id, val in HISTORY[msg.request]:
                 if val != None:
                     result += val
             #print([(number,vector.clock) for number,vector in result])
             result = from_node.perform_syntactic_reconcilation(result)
             from_node.socket.sendto(pickle.dumps(result),
                                     ('localhost', msg.client))
             #for num,clocks in result:
             #   print(str(msg.key)+" "+str(num)+" "+str(clocks.clock))
             REQUESTS[msg.request] = True
     readers = set([id for id, val in HISTORY[msg.request]])
     failed_nodes = set(nodes) - readers
     from_node.failed_nodes += list(failed_nodes)
     Messaging.retry_get_request(from_node, failed_nodes, msg, readers)
Esempio n. 3
0
    def broadcast_put(from_node, node_list, msg):
        if (len(node_list) == 0):
            if len(HISTORY.get(msg.request, set())) < from_node.W:
                from_node.socket.sendto(pickle.dumps("FAILURE"),
                                        ('localhost', msg.client))
            elif REQUESTS.get(msg.request, False) == True:
                from_node.socket.sendto(pickle.dumps("SUCCESS"),
                                        ('localhost', msg.client))
            return

        msg = Request("STORE", msg.key, msg.value, generate_random_number(),
                      msg.client)
        nodes = []
        for node in node_list:
            nodes.append(node.id)
            #print("Preference list="+node.id+msg.action + "from "+from_node.id +" "+str(msg.key)+":"+str(msg.value[0]))
            Messaging.send_message(from_node, node.id, msg)
        cur_time = time.time()
        while int(time.time() - cur_time) < 3:
            if not REQUESTS.get(msg.request, False) and len(
                    HISTORY.get(msg.request, set())) >= from_node.W:
                #send client success message
                from_node.socket.sendto(pickle.dumps("SUCCESS"),
                                        ('localhost', msg.client))
                REQUESTS[msg.request] = True
        HISTORY.get(msg.request, set()).add(from_node.id)
        failed_nodes = set(nodes) - HISTORY[msg.request]
        from_node.failed_nodes = from_node.failed_nodes + list(failed_nodes)
        #print("FAILED NODES "+str(from_node.failed_nodes))
        Messaging.retry_put_request(from_node, failed_nodes, msg,
                                    HISTORY[msg.request])
Esempio n. 4
0
 def handoff(self):
     for node in self.check_for_sync:
         keys = list(self.sync_kv[node].keys())
         values = list(self.sync_kv[node].values())
         synchronize = Request("SYNC", keys, values,
                               generate_random_number())
         Messaging.send_message(self, node, synchronize)
Esempio n. 5
0
 def perform_get(self, dict):
     key = dict.key
     preference_list = self.hash_ring.get_node(key, self.failed_nodes)
     if (self not in preference_list):
         coordinator = preference_list[0].id
         dict = Request("FORWARD-GET", dict.key, dict.value,
                        generate_random_number(), dict.client)
         Messaging.send_message(self, coordinator, dict)
         time.sleep(3)
         if REQUESTS.get(dict.request, False) != True:
             #print("Timedout GET")
             dict.action = "GET"
             dict.request = generate_random_number()
             self.failed_nodes.append(coordinator)
             self.perform_get(dict)
     else:
         dict.request = generate_random_number()
         Messaging.broadcast_get(self, preference_list, dict)