Пример #1
0
 def insert_item_to_node(
     self,
     key,
     value,
     node_id,
 ):
     cmd = "INSERT"
     data = serializer.decode_command(cmd, key, value)
     self.nodes[node_id].send(data)
Пример #2
0
 def insert_item_to_node(
     self,
     cmd,
     key,
     value,
     node_id,
 ):
     data = serializer.decode_command(cmd, key, value)
     self.nodes[node_id].send(data)
     self.nodes_keys_set[node_id].add(key)
Пример #3
0
 def get_item_from_node(self, cmd, key, node_id):
     data = serializer.decode_command(cmd=cmd, key=key)
     self.nodes[node_id].send(data)
     answ = self.nodes[node_id].recv(serializer.ANSWER_SIZE)
     if answ == None:
         return None
     if answ == b'0':
         return None
     s = serializer.encode_answer(answ)
     return s
Пример #4
0
 def get_all_items(self):
     cmd = "SELECT"
     #TODO
     items = {}
     for i, node in enumerate(self.nodes):
         data = serializer.decode_command(cmd)
         node.send(data)
         while True:
             answ = node.recv(serializer.ANSWER_SIZE)
             if answ == b'0':
                 break
             s = serializer.encode_answer(answ)
             items[s[0]] = s[1]
     return "\n".join(
         map(lambda x: "{} {}".format(x[0], x[1]), items.items()))
Пример #5
0
 def get_all_items_queue(self, cmd):
     decoded_cmd = serializer.decode_command(cmd)
     for node in self.nodes:
         node.send(decoded_cmd)
     items = {}
     recv_queue = queue.Queue()
     for node in self.nodes:
         recv_queue.put(node)
     while not recv_queue.empty():
         node = recv_queue.get()
         data = node.recv(serializer.ANSWER_SIZE)
         if data == b'0':
             continue
         key, value = serializer.encode_answer(data)
         assert key not in items.keys(), RuntimeError(
             "Key dublicate. {}".format(key))
         items[key] = value
         print("select *: {} {}".format(key, value), file=sys.stderr)
         recv_queue.put(node)
     return items