'Checks the given path for a container database, determines if syncing
is turned on for that database and, if so, sends any updates to the
other container.
:param path: the path to a container db'

def container_sync(self, path):

    broker = None
    try:
        broker = ContainerBroker(path)
        try:
            info = broker.get_info()
        except DatabaseConnectionError as db_err:
            if str(db_err).endswith("DB    doesn't    exist"):
                self.sync_store.remove_synced_container(broker)
            raise
        (x, nodes) = self.container_ring.get_nodes(info['account'], info['container'])
        for (ordinal, node) in enumerate(nodes):
            if is_local_device(self._myips, self._myport, node['ip'], node['port']):
                break
        else:
            return
        if (not broker.is_deleted()):
            sync_to = None
            user_key = None
            sync_point1 = info['x_container_sync_point1']
            sync_point2 = info['x_container_sync_point2']
            for (key, (value, timestamp)) in broker.metadata.items():
                if (key.lower() == 'x-container-sync-to'):
                    sync_to = value
                elif (key.lower() == 'x-container-sync-key'):
                    user_key = value
            if ((not sync_to) or (not user_key)):
                self.container_skips += 1
                self.logger.increment('skips')
                return
            (err, sync_to, realm, realm_key) = validate_sync_to(sync_to, self.allowed_sync_hosts, self.realms_conf)
            if err:
                self.logger.info(_('ERROR    %(db_file)s:    %(validate_sync_to_err)s'), {'db_file': str(broker), 'validate_sync_to_err': err})
                self.container_failures += 1
                self.logger.increment('failures')
                return
            start_at = time()
            stop_at = (start_at + self.container_time)
            next_sync_point = None
            sync_stage_time = start_at
            try:
                while ((time() < stop_at) and (sync_point2 < sync_point1)):
                    rows = broker.get_items_since(sync_point2, 1)
                    if (not rows):
                        break
                    row = rows[0]
                    if (row['ROWID'] > sync_point1):
                        break
                    if (not self.container_sync_row(row, sync_to, user_key, broker, info, realm, realm_key)):
                        if (not next_sync_point):
                            next_sync_point = sync_point2
                    sync_point2 = row['ROWID']
                    broker.set_x_container_sync_points(None, sync_point2)
                if next_sync_point:
                    broker.set_x_container_sync_points(None, next_sync_point)
                else:
                    next_sync_point = sync_point2
                sync_stage_time = time()
                while (sync_stage_time < stop_at):
                    rows = broker.get_items_since(sync_point1, 1)
                    if (not rows):
                        break
                    row = rows[0]
                    key = hash_path(info['account'], info['container'], row['name'], raw_digest=True)
                    if ((unpack_from('>I', key)[0] % len(nodes)) == ordinal):
                        self.container_sync_row(row, sync_to, user_key, broker, info, realm, realm_key)
                    sync_point1 = row['ROWID']
                    broker.set_x_container_sync_points(sync_point1, None)
                    sync_stage_time = time()
                self.container_syncs += 1
                self.logger.increment('syncs')
            finally:
                self.container_report(start_at, sync_stage_time, sync_point1, next_sync_point, info, broker.get_max_row())
    except (Exception, Timeout):
        self.container_failures += 1
        self.logger.increment('failures')
        self.logger.exception(_('ERROR    Syncing    %s'), (broker if broker else path))
