~ubuntu-branches/ubuntu/vivid/swift/vivid-updates

« back to all changes in this revision

Viewing changes to swift/obj/updater.py

  • Committer: Package Import Robot
  • Author(s): James Page, Chuck Short, James Page
  • Date: 2014-10-06 10:06:11 UTC
  • mfrom: (1.2.31)
  • Revision ID: package-import@ubuntu.com-20141006100611-wdzkkuoru7ubtlml
Tags: 2.1.0-0ubuntu1
[ Chuck Short ]
* debian/patches/fix-doc-no-network.patch: Refreshed.
* debian/control: Add python-oslosphinx as a build dependency.

[ James Page ]
* New upstream release for OpenStack Juno.
* d/copyright: Add linebreaks to fixup file-without-copyright-
  information warning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
from swift import gettext_ as _
22
22
from random import random
23
23
 
24
 
from eventlet import patcher, Timeout
 
24
from eventlet import spawn, patcher, Timeout
25
25
 
26
26
from swift.common.bufferedhttp import http_connect
27
27
from swift.common.exceptions import ConnectionTimeout
28
28
from swift.common.ring import Ring
29
 
from swift.common.storage_policy import POLICY_INDEX
30
29
from swift.common.utils import get_logger, renamer, write_pickle, \
31
30
    dump_recon_cache, config_true_value, ismount
32
31
from swift.common.daemon import Daemon
217
216
            update['account'], update['container'])
218
217
        obj = '/%s/%s/%s' % \
219
218
              (update['account'], update['container'], update['obj'])
 
219
        headers_out = update['headers'].copy()
 
220
        headers_out['user-agent'] = 'object-updater %s' % os.getpid()
 
221
        headers_out.setdefault('X-Backend-Storage-Policy-Index',
 
222
                               str(policy_idx))
 
223
        events = [spawn(self.object_update,
 
224
                        node, part, update['op'], obj, headers_out)
 
225
                  for node in nodes if node['id'] not in successes]
220
226
        success = True
221
227
        new_successes = False
222
 
        for node in nodes:
223
 
            if node['id'] not in successes:
224
 
                headers = update['headers'].copy()
225
 
                headers.setdefault(POLICY_INDEX, str(policy_idx))
226
 
                status = self.object_update(node, part, update['op'], obj,
227
 
                                            headers)
228
 
                if not is_success(status) and status != HTTP_NOT_FOUND:
229
 
                    success = False
230
 
                else:
231
 
                    successes.append(node['id'])
232
 
                    new_successes = True
 
228
        for event in events:
 
229
            event_success, node_id = event.wait()
 
230
            if event_success is True:
 
231
                successes.append(node_id)
 
232
                new_successes = True
 
233
            else:
 
234
                success = False
233
235
        if success:
234
236
            self.successes += 1
235
237
            self.logger.increment('successes')
247
249
                write_pickle(update, update_path, os.path.join(
248
250
                    device, get_tmp_dir(policy_idx)))
249
251
 
250
 
    def object_update(self, node, part, op, obj, headers):
 
252
    def object_update(self, node, part, op, obj, headers_out):
251
253
        """
252
254
        Perform the object update to the container
253
255
 
255
257
        :param part: partition that holds the container
256
258
        :param op: operation performed (ex: 'POST' or 'DELETE')
257
259
        :param obj: object name being updated
258
 
        :param headers: headers to send with the update
 
260
        :param headers_out: headers to send with the update
259
261
        """
260
 
        headers_out = headers.copy()
261
 
        headers_out['user-agent'] = 'obj-updater %s' % os.getpid()
262
262
        try:
263
263
            with ConnectionTimeout(self.conn_timeout):
264
264
                conn = http_connect(node['ip'], node['port'], node['device'],
266
266
            with Timeout(self.node_timeout):
267
267
                resp = conn.getresponse()
268
268
                resp.read()
269
 
                return resp.status
 
269
                success = (is_success(resp.status) or
 
270
                           resp.status == HTTP_NOT_FOUND)
 
271
                return (success, node['id'])
270
272
        except (Exception, Timeout):
271
273
            self.logger.exception(_('ERROR with remote server '
272
274
                                    '%(ip)s:%(port)s/%(device)s'), node)
273
 
        return HTTP_INTERNAL_SERVER_ERROR
 
275
        return HTTP_INTERNAL_SERVER_ERROR, node['id']