Пример #1
0
	def put_doc(self, id):
		# identify the shard for this uuid
		shards = self._config.shards(self._db)
		shard_idx = proxy.which_shard(proxy.lounge_hash(id), len(shards))

		# generate upstream tuples for getPageFromAny
		shard_uris = itertools.imap(
			lambda idx, uri: (
				idx,                 # replica identifier
				'/'.join([uri, id]), # shard uri
				[],                  # args
				{ 'method' : 'PUT',  # kwargs
				  'postdata' : self._body
				}),
			itertools.count(),
			self._config.nodes(shards[shard_idx]))

		# set up a callback to unpack
		def succeed(result):
			data, identifier, factory = result
			self._deferred.callback(
				(int(factory.status),
				 prep_backend_headers(factory.response_headers, self._config),
				 data))

		getPageFromAny(shard_uris).addCallbacks(succeed, self._deferred.errback)
Пример #2
0
	def put_doc(self, id):
		# identify the shard for this uui
		shards = self._config.primary_shards(self._db)
		idx = proxy.lounge_hash(id) % len(shards)
		shard = shards[idx]

		def succeed(data):
			self._deferred.callback((int(self.factory.status), prep_backend_headers(self.factory.response_headers, self._config), data))
		def fail(data):
			self._deferred.errback(data)
		self.factory = getPageWithHeaders('/'.join([shard, id]), method='PUT', postdata=self._body)
		self.factory.deferred.addCallback(succeed)
		self.factory.deferred.addErrback(fail)