~gholt/swift/postcopy

« back to all changes in this revision

Viewing changes to swift/common/db.py

  • Committer: gholt
  • Date: 2011-06-14 22:20:23 UTC
  • mfrom: (305.1.8 swift)
  • Revision ID: gholt@rackspace.com-20110614222023-2rato80hezcqcxcg
MergedĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
879
879
            return (row['object_count'] in (None, '', 0, '0')) and \
880
880
                (float(row['delete_timestamp']) > float(row['put_timestamp']))
881
881
 
882
 
    def get_info(self):
 
882
    def get_info(self, include_metadata=False):
883
883
        """
884
884
        Get global data for the container.
885
885
 
886
 
        :returns: sqlite.row of (account, container, created_at, put_timestamp,
887
 
                  delete_timestamp, object_count, bytes_used,
 
886
        :returns: dict with keys: account, container, created_at,
 
887
                  put_timestamp, delete_timestamp, object_count, bytes_used,
888
888
                  reported_put_timestamp, reported_delete_timestamp,
889
 
                  reported_object_count, reported_bytes_used, hash, id)
 
889
                  reported_object_count, reported_bytes_used, hash, id
 
890
                  If include_metadata is set, metadata is included as a key
 
891
                  pointing to a dict of tuples of the metadata
890
892
        """
891
893
        try:
892
894
            self._commit_puts()
894
896
            if not self.stale_reads_ok:
895
897
                raise
896
898
        with self.get() as conn:
897
 
            return conn.execute('''
898
 
                SELECT account, container, created_at, put_timestamp,
899
 
                    delete_timestamp, object_count, bytes_used,
900
 
                    reported_put_timestamp, reported_delete_timestamp,
901
 
                    reported_object_count, reported_bytes_used, hash, id
902
 
                FROM container_stat
903
 
            ''').fetchone()
 
899
            metadata = ''
 
900
            if include_metadata:
 
901
                metadata = ', metadata'
 
902
            try:
 
903
                data = conn.execute('''
 
904
                    SELECT account, container, created_at, put_timestamp,
 
905
                        delete_timestamp, object_count, bytes_used,
 
906
                        reported_put_timestamp, reported_delete_timestamp,
 
907
                        reported_object_count, reported_bytes_used, hash, id
 
908
                        %s
 
909
                    FROM container_stat
 
910
                ''' % metadata).fetchone()
 
911
            except sqlite3.OperationalError, err:
 
912
                if 'no such column: metadata' not in str(err):
 
913
                    raise
 
914
                data = conn.execute('''
 
915
                    SELECT account, container, created_at, put_timestamp,
 
916
                        delete_timestamp, object_count, bytes_used,
 
917
                        reported_put_timestamp, reported_delete_timestamp,
 
918
                        reported_object_count, reported_bytes_used, hash, id
 
919
                    FROM container_stat''').fetchone()
 
920
            data = dict(data)
 
921
            if include_metadata:
 
922
                try:
 
923
                    data['metadata'] = json.loads(data.get('metadata', ''))
 
924
                except ValueError:
 
925
                    data['metadata'] = {}
 
926
            return data
904
927
 
905
928
    def reported(self, put_timestamp, delete_timestamp, object_count,
906
929
                 bytes_used):
1394
1417
        """
1395
1418
        Get global data for the account.
1396
1419
 
1397
 
        :returns: sqlite.row of (account, created_at, put_timestamp,
 
1420
        :returns: dict with keys: account, created_at, put_timestamp,
1398
1421
                  delete_timestamp, container_count, object_count,
1399
 
                  bytes_used, hash, id)
 
1422
                  bytes_used, hash, id
1400
1423
        """
1401
1424
        try:
1402
1425
            self._commit_puts()
1404
1427
            if not self.stale_reads_ok:
1405
1428
                raise
1406
1429
        with self.get() as conn:
1407
 
            return conn.execute('''
 
1430
            return dict(conn.execute('''
1408
1431
                SELECT account, created_at,  put_timestamp, delete_timestamp,
1409
1432
                       container_count, object_count, bytes_used, hash, id
1410
1433
                FROM account_stat
1411
 
            ''').fetchone()
 
1434
            ''').fetchone())
1412
1435
 
1413
1436
    def list_containers_iter(self, limit, marker, end_marker, prefix,
1414
1437
                             delimiter):