Example #1
0
    def remove(self, description, local=True):
        if local:
            predicate = _create_predicate(description)
            return self.tuple_store.remove(predicate)
        else:
            if _has_variable(description):
                # If there is a variable in the description
                # We simply have to broadcast the query
                addresses = self.nets_store.get_addresses()
                for address in addresses:
                    if address == self.nets_store.local:
                        predicate = _create_predicate(description)
                        t = self.tuple_store.remove(predicate)
                    else:
                        t = self._remove_remote(description, address)

                    if t is not None:
                        return t

                return None

            else:
                # Else, we have to hash the tuple and
                # Query the appropriate address
                query_tuple = tuple([x['value'] for x in description])
                slot = hash_tuple(query_tuple)
                address = self.nets_store.table[slot]

                if address == self.nets_store.local:
                    return self.tuple_store.remove(lambda t: t == query_tuple)
                else:
                    return self._remove_remote(description, address)
Example #2
0
    def _resolve_change_set(self, change_set):
        print('Resolving Change Set')
        receive_set, remove_set = change_set

        print('Handling Receive Set')
        print(receive_set)
        # Handle receive set
        for recipient, slots in receive_set.items():
            print('Handling recipient: {0}'.format(recipient))
            owned_slots = self.nets_store.get_owned_slots()

            outgoing_slots = set(slots) & set(owned_slots)
            self.send_tuples_many(outgoing_slots, recipient)

            remote_slots = set(slots) - set(owned_slots)
            for slot in remote_slots:
                print('Slot is found remotely')
                address = self.nets_store.table[slot]
                print('Sending the send command to recipient')
                self._send_send_command(address, recipient, slot)

        # Handle remove set
        for address, slots in remove_set.items():
            if address == self.nets_store.local:
                self.tuple_store.remove_all(lambda t: hash_tuple(t) in slots)
            else:
                self._send_delete_command(address, slots)
Example #3
0
    def send_tuples_many(self, slots, address):
        for slot in slots:
            print('Sending #{0} tuples to {1}'.format(slot, address))

        tuples = self.tuple_store.read_all(lambda t: hash_tuple(t) in slots)
        print('Tuples: {0}'.format(tuples))
        for t in tuples:
            self._insert_remote(t, address)
Example #4
0
    def insert(self, t, local=True):
        if local:
            # If this is a local insert, just insert
            return self.tuple_store.insert(t)
        else:
            slot = hash_tuple(t)
            address = self.nets_store.table[slot]
            if address == self.nets_store.local:
                # Insert in backup
                backup = self.nets_store.get_backup(slot)
                backup_address = self.nets_store.table[backup]
                self._insert_remote(t, backup_address)

                return self.tuple_store.insert(t)
            else:
                return self._insert_remote(t, address)
Example #5
0
 def remove_slot(self, slot):
     tuples = self.tuple_store.remove_all(lambda t: hash_tuple(t) == slot)
     return tuples