Exemplo n.º 1
0
    def update(self, transaction_id, release, rollback, key, *columns):
        data = list(columns)
        mask = Bits("")
        mask.build_from_list(data)
        base_rid = self.table.index.select_index(self.table.key, key)[0]

        #Commit/Abort
        if release:
            #Abort
            if rollback:
                #find previous version in log and update it
                send_query = [transaction_id, ["Update"], (base_rid, data)]
                datafromLOG = self.logger.find_aborted(send_query)
                #append the very first, oldest value to the update.
                next_rid = self.table.db.get_next_rid()
                data = datafromLOG
                #self.table.rollback(key)

            #release all the locks
            self.table.db.lock_manager.release_write(base_rid, transaction_id)
            return
        else:
            # Try to acquire write_lock
            LOCK_ACQUIRED = self.table.db.lock_manager.acquire_write(
                base_rid, transaction_id)
            if not LOCK_ACQUIRED:
                #abort this transaction
                print("Acquire lock fail")
                return False, False

            next_rid = self.table.db.get_next_rid()
            old_value = self.table.get(base_rid, mask)

            all_old_values = self.table.get(base_rid,
                                            Bits('1' * self.table.num_columns))
            print("Update", base_rid, key, all_old_values, data)
            #traceback.print_stack()
            if transaction_id is not None:
                send_query = [
                    transaction_id, ["update", key, data],
                    (all_old_values, data)
                ]
                self.logger.first_add(send_query)

            self.table.put(next_rid, base_rid, key, mask, data)
            mask = Bits("")
            mask.build_from_list(columns)
            _columns = [i for i in columns if not i is None]
            #print(old_value, _columns, mask.bits, base_rid)
            count = 0
            for i in mask:
                if i == 1:
                    self.table.index.update_index(i, base_rid,
                                                  old_value[count],
                                                  _columns[count])
                    count += 1
            # TODO: Release lock? or release after transcation done
            if transaction_id is not None:
                self.logger.finished_add(send_query)
            return True, True
Exemplo n.º 2
0
    def create_index(self, table, column_number):
        zeros = [None] * table.num_columns
        mask = Bits("")
        mask.build_from_list(zeros[:column_number] + [1] +
                             zeros[column_number:])

        self.tree = OOBTreePy()

        ks = {}
        for rid in table.page_directory:
            r = table.get(rid, mask)
            ks[rid] = r.columns[0]

        self.tree.update(ks)
Exemplo n.º 3
0
 def create_index(self, column_number):
     if column_number in self.col_btree:
         return
     print("Create index", column_number)
     zeros = [None] * self.table.num_columns
     mask = Bits("")
     mask.build_from_list(zeros[:column_number] + [1] +
                          zeros[column_number:])
     tree = OOBTreePy()
     ks = {}
     for rid in self.table.page_directory:
         _m = self.table.page_directory[rid]
         if _m.indirection == 0 or _m.indirection > rid:
             #print("ADDING INDEX:",rid)
             r = self.table.get(rid, mask)
             #ks[rid] = r.columns[0]
             ks[r[0]] = [rid]
     tree.update(ks)
     self.col_btree[column_number] = tree
     return True
Exemplo n.º 4
0
 def update(self, key, *columns):
     data = list(columns)
     mask = Bits("")
     mask.build_from_list(columns)
     base_rid = self.table.key_to_baseRid(key)
     self.table.put(self.table.get_next_rid(), base_rid, key, mask, data)