def _poll_rdir(self, avoid=None, known=None, min_dist=None, **kwargs): """ Call the special rdir service pool (created if missing). :param min_dist: minimum distance to ensure between the known service and the selected rdir service. """ if not known or len(known) > 1: raise ValueError('There should be exactly one "known" service') options = dict() if min_dist is not None: options['min_dist'] = min_dist if options != self._pool_options: # Options have changed, overwrite the pool. self._pool_options = options self._create_special_pool(self._pool_options, force=True, **kwargs) try: svcs = self.cs.poll('__rawx_rdir', avoid=avoid, known=known, **kwargs) except ClientException as exc: if exc.status != 400: raise self._create_special_pool(self._pool_options, **kwargs) svcs = self.cs.poll('__rawx_rdir', avoid=avoid, known=known, **kwargs) for svc in svcs: # FIXME: we should include the service type in a dedicated field if 'rdir' in svc['id']: return svc raise ServerException("LB returned incoherent result: %s" % svcs)
def chunk_push(self, volume_id, container_id, content_id, chunk_id, **data): key = "%s|%s|%s" % (container_id, content_id, chunk_id) value = self._get_db_chunk(volume_id).get(key.encode('utf8')) if value is not None: value = json.loads(value) else: value = dict() for k, v in data.iteritems(): value[k] = v if 'mtime' not in value: # not consistent if 'rtime' in value: # In functionnal test, we can encounter the case where rebuild # update (rtime) arrives before creation update (first mtime) value['mtime'] = value['rtime'] else: raise ServerException("mtime is mandatory") value = json.dumps(value) self._get_db_chunk(volume_id).put(key.encode('utf8'), value.encode('utf8'))
def _poll_rdir(self, avoid=None, known=None): """Call the special rdir service pool (created if missing)""" try: svcs = self.cs.poll('__rawx_rdir', avoid=avoid, known=known) except ClientException as exc: if exc.status != 400: raise self.cs.lb.create_pool('__rawx_rdir', ((1, 'rawx'), (1, 'rdir'))) svcs = self.cs.poll('__rawx_rdir', avoid=avoid, known=known) for svc in svcs: # FIXME: we should include the service type in a dedicated field if 'rdir' in svc['id']: return svc raise ServerException("LB returned incoherent result: %s" % svcs)