本文整理汇总了Python中swift.common.ring.Ring.get_more_nodes方法的典型用法代码示例。如果您正苦于以下问题:Python Ring.get_more_nodes方法的具体用法?Python Ring.get_more_nodes怎么用?Python Ring.get_more_nodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类swift.common.ring.Ring
的用法示例。
在下文中一共展示了Ring.get_more_nodes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ObjectReplicator
# 需要导入模块: from swift.common.ring import Ring [as 别名]
# 或者: from swift.common.ring.Ring import get_more_nodes [as 别名]
#.........这里部分代码省略.........
'/' + '-'.join(suffixes),
headers={'Content-Length': '0'}).getresponse().read()
responses.append(success)
if not suffixes or (len(responses) == \
len(job['nodes']) and all(responses)):
self.logger.info(_("Removing partition: %s"), job['path'])
tpool.execute(shutil.rmtree, job['path'], ignore_errors=True)
except (Exception, Timeout):
self.logger.exception(_("Error syncing handoff partition"))
finally:
self.partition_times.append(time.time() - begin)
self.logger.timing_since('partition.delete.timing', begin)
def update(self, job):
"""
High-level method that replicates a single partition.
:param job: a dict containing info about the partition to be replicated
"""
self.replication_count += 1
self.logger.increment('partition.update.count.%s' % (job['device'],))
begin = time.time()
try:
hashed, local_hash = tpool.execute(tpooled_get_hashes, job['path'],
do_listdir=(self.replication_count % 10) == 0,
reclaim_age=self.reclaim_age)
# See tpooled_get_hashes "Hack".
if isinstance(hashed, BaseException):
raise hashed
self.suffix_hash += hashed
self.logger.update_stats('suffix.hashes', hashed)
attempts_left = len(job['nodes'])
nodes = itertools.chain(job['nodes'],
self.object_ring.get_more_nodes(int(job['partition'])))
while attempts_left > 0:
# If this throws StopIterator it will be caught way below
node = next(nodes)
attempts_left -= 1
try:
with Timeout(self.http_timeout):
resp = http_connect(node['ip'], node['port'],
node['device'], job['partition'], 'REPLICATE',
'', headers={'Content-Length': '0'}).getresponse()
if resp.status == HTTP_INSUFFICIENT_STORAGE:
self.logger.error(_('%(ip)s/%(device)s responded'
' as unmounted'), node)
attempts_left += 1
continue
if resp.status != HTTP_OK:
self.logger.error(_("Invalid response %(resp)s "
"from %(ip)s"),
{'resp': resp.status, 'ip': node['ip']})
continue
remote_hash = pickle.loads(resp.read())
del resp
suffixes = [suffix for suffix in local_hash if
local_hash[suffix] != remote_hash.get(suffix, -1)]
if not suffixes:
continue
hashed, recalc_hash = tpool.execute(tpooled_get_hashes,
job['path'], recalculate=suffixes,
reclaim_age=self.reclaim_age)
# See tpooled_get_hashes "Hack".
if isinstance(hashed, BaseException):
raise hashed
self.logger.update_stats('suffix.hashes', hashed)
示例2: ObjectReplicator
# 需要导入模块: from swift.common.ring import Ring [as 别名]
# 或者: from swift.common.ring.Ring import get_more_nodes [as 别名]
#.........这里部分代码省略.........
reclaim_age=self.reclaim_age)
self.suffix_hash += hashed
self.logger.update_stats('suffix.hashes', hashed)
part_hash_local = tpool_reraise(get_part_hash, job['path'])
"""hashed, local_hash = tpool_reraise(
get_hashes, job['path'],
do_listdir=(self.replication_count % 10) == 0,
reclaim_age=self.reclaim_age)
self.suffix_hash += hashed
self.logger.update_stats('suffix.hashes', hashed)"""
attempts_left = True
nodes = itertools.chain(job['nodes'])
while (True):
##
# If this throws StopIterator it will be caught way below
node = next(nodes)
try:
#MODIFIED LightSync
req_suff = '' if part_hash_local is None else '/_SHORTREP_-'\
+part_hash_local
with Timeout(self.http_timeout):
resp = http_connect(
node['replication_ip'], node['replication_port'],
node['device'], job['partition'], 'REPLICATE',
req_suff, headers=self.headers).getresponse()
if resp.status == HTTP_INSUFFICIENT_STORAGE:
self.logger.error(_('%(ip)s/%(device)s responded'
' as unmounted'), node)
if(attempts_left):
attempts_left = False
########To modify to start from current node's hand-off: Hash node info to get hand-off position
nodes = itertools.chain(
self.object_ring.get_more_nodes(int(job['partition'])),
nodes)
continue
if resp.status != HTTP_OK:
self.logger.error(_("Invalid response %(resp)s "
"from %(ip)s"),
{'resp': resp.status,
'ip': node['replication_ip']})
continue
part_hash_remote = pickle.loads(resp.read())
del resp
if part_hash_remote == "OK":
break
remote_hash = part_hash_remote
if local_hash is None:
hashed, local_hash = tpool_reraise(
get_hashes, job['path'],
do_listdir=(self.replication_count % 10) == 0,
reclaim_age=self.reclaim_age)
self.suffix_hash += hashed
self.logger.update_stats('suffix.hashes', hashed)
'''
with Timeout(self.http_timeout):
resp = http_connect(
node['replication_ip'], node['replication_port'],
node['device'], job['partition'], 'REPLICATE',
'', headers=self.headers).getresponse()
if resp.status == HTTP_INSUFFICIENT_STORAGE:
self.logger.error(_('%(ip)s/%(device)s responded'
' as unmounted'), node)
attempts_left += 1
continue
if resp.status != HTTP_OK:
示例3: Ring
# 需要导入模块: from swift.common.ring import Ring [as 别名]
# 或者: from swift.common.ring.Ring import get_more_nodes [as 别名]
from swift.common.ring import Ring
if __name__ == '__main__':
# example path for sample object
# update this to and existing account/container/object
# in your environment
account = 'AUTH_9fbaa44c45ab4902a46110fd90629a79'
container = 'testing'
obj = 'testing.pem'
ring = Ring('.', ring_name='object')
part, nodes = ring.get_nodes(account, container, obj)
print 'nodes: '
for n in nodes:
print 'node: ', n
print 'part = ', part
morenodes = ring.get_more_nodes(part)
print 'more nodes:'
for n in morenodes:
print 'node: ', n
示例4: ObjectReplicator
# 需要导入模块: from swift.common.ring import Ring [as 别名]
# 或者: from swift.common.ring.Ring import get_more_nodes [as 别名]
#.........这里部分代码省略.........
node["port"],
node["device"],
job["partition"],
"REPLICATE",
"/" + "-".join(suffixes),
headers={"Content-Length": "0"},
).getresponse().read()
responses.append(success)
if not suffixes or (len(responses) == len(job["nodes"]) and all(responses)):
self.logger.info(_("Removing partition: %s"), job["path"])
tpool.execute(shutil.rmtree, job["path"], ignore_errors=True)
except (Exception, Timeout):
self.logger.exception(_("Error syncing handoff partition"))
finally:
self.partition_times.append(time.time() - begin)
self.logger.timing_since("partition.delete.timing", begin)
def update(self, job):
"""
High-level method that replicates a single partition.
:param job: a dict containing info about the partition to be replicated
"""
self.replication_count += 1
self.logger.increment("partition.update.count.%s" % (job["device"],))
begin = time.time()
try:
hashed, local_hash = tpool_reraise(
get_hashes, job["path"], do_listdir=(self.replication_count % 10) == 0, reclaim_age=self.reclaim_age
)
self.suffix_hash += hashed
self.logger.update_stats("suffix.hashes", hashed)
attempts_left = len(job["nodes"])
nodes = itertools.chain(job["nodes"], self.object_ring.get_more_nodes(int(job["partition"])))
while attempts_left > 0:
# If this throws StopIterator it will be caught way below
node = next(nodes)
attempts_left -= 1
try:
with Timeout(self.http_timeout):
resp = http_connect(
node["ip"],
node["port"],
node["device"],
job["partition"],
"REPLICATE",
"",
headers={"Content-Length": "0"},
).getresponse()
if resp.status == HTTP_INSUFFICIENT_STORAGE:
self.logger.error(_("%(ip)s/%(device)s responded" " as unmounted"), node)
attempts_left += 1
continue
if resp.status != HTTP_OK:
self.logger.error(
_("Invalid response %(resp)s " "from %(ip)s"), {"resp": resp.status, "ip": node["ip"]}
)
continue
remote_hash = pickle.loads(resp.read())
del resp
suffixes = [suffix for suffix in local_hash if local_hash[suffix] != remote_hash.get(suffix, -1)]
if not suffixes:
continue
hashed, recalc_hash = tpool_reraise(
get_hashes, job["path"], recalculate=suffixes, reclaim_age=self.reclaim_age
)