~ubuntu-branches/ubuntu/trusty/swift/trusty-updates

« back to all changes in this revision

Viewing changes to swift/common/db_replicator.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Soren Hansen, Chuck Short
  • Date: 2012-09-07 19:02:36 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20120907190236-fqrmbzm7v6zivs8d
Tags: 1.7.0-0ubuntu1
[ Soren Hansen ]
* Update debian/watch to account for symbolically named tarballs and
  use newer URL.
* Run unit tests at build time.
* Fix Launchpad URLs in debian/watch.

[ Chuck Short ]
* New upstream release
* debian/control: Add pubthon-moc as a build dep
* debian/rules: Dont fail if testsuite fails.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import shutil
22
22
import uuid
23
23
import errno
 
24
import re
24
25
 
25
26
from eventlet import GreenPool, sleep, Timeout
26
27
from eventlet.green import subprocess
130
131
        self.recon_replicator = '%s.recon' % self.server_type
131
132
        self.rcache = os.path.join(self.recon_cache_path,
132
133
                                   self.recon_replicator)
 
134
        self.extract_device_re = re.compile('%s%s([^%s]+)' % (
 
135
            self.root, os.path.sep, os.path.sep))
133
136
 
134
137
    def _zero_stats(self):
135
138
        """Zero out the stats."""
388
391
                delete_timestamp > put_timestamp and \
389
392
                info['count'] in (None, '', 0, '0'):
390
393
            if self.report_up_to_date(full_info):
391
 
                with lock_parent_directory(object_file):
392
 
                    shutil.rmtree(os.path.dirname(object_file), True)
393
 
                    self.stats['remove'] += 1
394
 
                    self.logger.increment('removes')
 
394
                self.delete_db(object_file)
395
395
            self.logger.timing_since('timing', start_time)
396
396
            return
397
397
        responses = []
419
419
        if not shouldbehere and all(responses):
420
420
            # If the db shouldn't be on this node and has been successfully
421
421
            # synced to all of its peers, it can be removed.
422
 
            with lock_parent_directory(object_file):
423
 
                shutil.rmtree(os.path.dirname(object_file), True)
424
 
                self.stats['remove'] += 1
425
 
                self.logger.increment('removes')
 
422
            self.delete_db(object_file)
426
423
        self.logger.timing_since('timing', start_time)
427
424
 
 
425
    def delete_db(self, object_file):
 
426
        with lock_parent_directory(object_file):
 
427
            shutil.rmtree(os.path.dirname(object_file), True)
 
428
        self.stats['remove'] += 1
 
429
        device_name = self.extract_device(object_file)
 
430
        self.logger.increment('removes.' + device_name)
 
431
 
 
432
    def extract_device(self, object_file):
 
433
        """
 
434
        Extract the device name from an object path.  Returns "UNKNOWN" if the
 
435
        path could not be extracted successfully for some reason.
 
436
 
 
437
        :param object_file: the path to a database file.
 
438
        """
 
439
        match = self.extract_device_re.match(object_file)
 
440
        if match:
 
441
            return match.groups()[0]
 
442
        return "UNKNOWN"
 
443
 
428
444
    def report_up_to_date(self, full_info):
429
445
        return True
430
446