Пример #1
0
    def put_container(self, name, put_timestamp, delete_timestamp,
                      object_count, bytes_used, storage_policy_index):
        """
        Create a container with the given attributes.

        :param name: name of the container to create
        :param put_timestamp: put_timestamp of the container to create
        :param delete_timestamp: delete_timestamp of the container to create
        :param object_count: number of objects in the container
        :param bytes_used: number of bytes used by the container
        :param storage_policy_index:  the storage policy for this container
        """
        if Timestamp(delete_timestamp) > Timestamp(put_timestamp) and \
                zero_like(object_count):
            deleted = 1
        else:
            deleted = 0
        record = {
            'name': name,
            'put_timestamp': put_timestamp,
            'delete_timestamp': delete_timestamp,
            'object_count': object_count,
            'bytes_used': bytes_used,
            'deleted': deleted,
            'storage_policy_index': storage_policy_index
        }
        self.put_record(record)
Пример #2
0
    def _is_deleted_info(self, status, container_count, delete_timestamp,
                         put_timestamp):
        """
        Apply delete logic to database info.

        :returns: True if the DB is considered to be deleted, False otherwise
        """
        return status == 'DELETED' or zero_like(container_count) and (
            Timestamp(delete_timestamp) > Timestamp(put_timestamp))
Пример #3
0
    def _is_deleted_info(self, status, container_count, delete_timestamp,
                         put_timestamp):
        """
        Apply delete logic to database info.

        :returns: True if the DB is considered to be deleted, False otherwise
        """
        return status == 'DELETED' or zero_like(container_count) and (
            Timestamp(delete_timestamp) > Timestamp(put_timestamp))
Пример #4
0
    def empty(self):
        """
        Check if the account DB is empty.

        :returns: True if the database has no active containers.
        """
        self._commit_puts_stale_ok()
        with self.get() as conn:
            row = conn.execute(
                'SELECT container_count from account_stat').fetchone()
            return zero_like(row[0])
Пример #5
0
    def empty(self):
        """
        Check if the account DB is empty.

        :returns: True if the database has no active containers.
        """
        self._commit_puts_stale_ok()
        with self.get() as conn:
            row = conn.execute(
                'SELECT container_count from account_stat').fetchone()
            return zero_like(row[0])
Пример #6
0
    def put_container(self, name, put_timestamp, delete_timestamp,
                      object_count, bytes_used, storage_policy_index):
        """
        Create a container with the given attributes.

        :param name: name of the container to create (a native string)
        :param put_timestamp: put_timestamp of the container to create
        :param delete_timestamp: delete_timestamp of the container to create
        :param object_count: number of objects in the container
        :param bytes_used: number of bytes used by the container
        :param storage_policy_index:  the storage policy for this container
        """
        if Timestamp(delete_timestamp) > Timestamp(put_timestamp) and \
                zero_like(object_count):
            deleted = 1
        else:
            deleted = 0
        record = {'name': name, 'put_timestamp': put_timestamp,
                  'delete_timestamp': delete_timestamp,
                  'object_count': object_count,
                  'bytes_used': bytes_used,
                  'deleted': deleted,
                  'storage_policy_index': storage_policy_index}
        self.put_record(record)
Пример #7
0
 def _really_merge_items(conn):
     max_rowid = -1
     curs = conn.cursor()
     for rec in item_list:
         rec.setdefault('storage_policy_index', 0)  # legacy
         record = [
             rec['name'], rec['put_timestamp'], rec['delete_timestamp'],
             rec['object_count'], rec['bytes_used'], rec['deleted'],
             rec['storage_policy_index']
         ]
         query = '''
             SELECT name, put_timestamp, delete_timestamp,
                    object_count, bytes_used, deleted,
                    storage_policy_index
             FROM container WHERE name = ?
         '''
         if self.get_db_version(conn) >= 1:
             query += ' AND deleted IN (0, 1)'
         curs_row = curs.execute(query, (rec['name'], ))
         curs_row.row_factory = None
         row = curs_row.fetchone()
         if row:
             row = list(row)
             for i in range(5):
                 if record[i] is None and row[i] is not None:
                     record[i] = row[i]
             if Timestamp(row[1]) > \
                Timestamp(record[1]):  # Keep newest put_timestamp
                 record[1] = row[1]
             if Timestamp(row[2]) > \
                Timestamp(record[2]):  # Keep newest delete_timestamp
                 record[2] = row[2]
             # If deleted, mark as such
             if Timestamp(record[2]) > Timestamp(record[1]) and \
                     zero_like(record[3]):
                 record[5] = 1
             else:
                 record[5] = 0
         curs.execute(
             '''
             DELETE FROM container WHERE name = ? AND
                                         deleted IN (0, 1)
         ''', (record[0], ))
         curs.execute(
             '''
             INSERT INTO container (name, put_timestamp,
                 delete_timestamp, object_count, bytes_used,
                 deleted, storage_policy_index)
             VALUES (?, ?, ?, ?, ?, ?, ?)
         ''', record)
         if source:
             max_rowid = max(max_rowid, rec['ROWID'])
     if source:
         try:
             curs.execute(
                 '''
                 INSERT INTO incoming_sync (sync_point, remote_id)
                 VALUES (?, ?)
             ''', (max_rowid, source))
         except sqlite3.IntegrityError:
             curs.execute(
                 '''
                 UPDATE incoming_sync
                 SET sync_point=max(?, sync_point)
                 WHERE remote_id=?
             ''', (max_rowid, source))
     conn.commit()
Пример #8
0
 def _really_merge_items(conn):
     max_rowid = -1
     curs = conn.cursor()
     for rec in item_list:
         rec.setdefault('storage_policy_index', 0)  # legacy
         record = [rec['name'], rec['put_timestamp'],
                   rec['delete_timestamp'], rec['object_count'],
                   rec['bytes_used'], rec['deleted'],
                   rec['storage_policy_index']]
         query = '''
             SELECT name, put_timestamp, delete_timestamp,
                    object_count, bytes_used, deleted,
                    storage_policy_index
             FROM container WHERE name = ?
         '''
         if self.get_db_version(conn) >= 1:
             query += ' AND deleted IN (0, 1)'
         curs_row = curs.execute(query, (rec['name'],))
         curs_row.row_factory = None
         row = curs_row.fetchone()
         if row:
             row = list(row)
             for i in range(5):
                 if record[i] is None and row[i] is not None:
                     record[i] = row[i]
             if Timestamp(row[1]) > \
                Timestamp(record[1]):  # Keep newest put_timestamp
                 record[1] = row[1]
             if Timestamp(row[2]) > \
                Timestamp(record[2]):  # Keep newest delete_timestamp
                 record[2] = row[2]
             # If deleted, mark as such
             if Timestamp(record[2]) > Timestamp(record[1]) and \
                     zero_like(record[3]):
                 record[5] = 1
             else:
                 record[5] = 0
         curs.execute('''
             DELETE FROM container WHERE name = ? AND
                                         deleted IN (0, 1)
         ''', (record[0],))
         curs.execute('''
             INSERT INTO container (name, put_timestamp,
                 delete_timestamp, object_count, bytes_used,
                 deleted, storage_policy_index)
             VALUES (?, ?, ?, ?, ?, ?, ?)
         ''', record)
         if source:
             max_rowid = max(max_rowid, rec['ROWID'])
     if source:
         try:
             curs.execute('''
                 INSERT INTO incoming_sync (sync_point, remote_id)
                 VALUES (?, ?)
             ''', (max_rowid, source))
         except sqlite3.IntegrityError:
             curs.execute('''
                 UPDATE incoming_sync
                 SET sync_point=max(?, sync_point)
                 WHERE remote_id=?
             ''', (max_rowid, source))
     conn.commit()