本文整理汇总了Python中cassandra.metadata.NetworkTopologyStrategy.make_token_replica_map方法的典型用法代码示例。如果您正苦于以下问题:Python NetworkTopologyStrategy.make_token_replica_map方法的具体用法?Python NetworkTopologyStrategy.make_token_replica_map怎么用?Python NetworkTopologyStrategy.make_token_replica_map使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cassandra.metadata.NetworkTopologyStrategy
的用法示例。
在下文中一共展示了NetworkTopologyStrategy.make_token_replica_map方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_nts_make_token_replica_map_multi_rack
# 需要导入模块: from cassandra.metadata import NetworkTopologyStrategy [as 别名]
# 或者: from cassandra.metadata.NetworkTopologyStrategy import make_token_replica_map [as 别名]
def test_nts_make_token_replica_map_multi_rack(self):
token_to_host_owner = {}
# (A) not enough distinct racks, first skipped is used
dc1_1 = Host("dc1.1", SimpleConvictionPolicy)
dc1_2 = Host("dc1.2", SimpleConvictionPolicy)
dc1_3 = Host("dc1.3", SimpleConvictionPolicy)
dc1_4 = Host("dc1.4", SimpleConvictionPolicy)
dc1_1.set_location_info("dc1", "rack1")
dc1_2.set_location_info("dc1", "rack1")
dc1_3.set_location_info("dc1", "rack2")
dc1_4.set_location_info("dc1", "rack2")
token_to_host_owner[MD5Token(0)] = dc1_1
token_to_host_owner[MD5Token(100)] = dc1_2
token_to_host_owner[MD5Token(200)] = dc1_3
token_to_host_owner[MD5Token(300)] = dc1_4
# (B) distinct racks, but not contiguous
dc2_1 = Host("dc2.1", SimpleConvictionPolicy)
dc2_2 = Host("dc2.2", SimpleConvictionPolicy)
dc2_3 = Host("dc2.3", SimpleConvictionPolicy)
dc2_1.set_location_info("dc2", "rack1")
dc2_2.set_location_info("dc2", "rack1")
dc2_3.set_location_info("dc2", "rack2")
token_to_host_owner[MD5Token(1)] = dc2_1
token_to_host_owner[MD5Token(101)] = dc2_2
token_to_host_owner[MD5Token(201)] = dc2_3
ring = [MD5Token(0), MD5Token(1), MD5Token(100), MD5Token(101), MD5Token(200), MD5Token(201), MD5Token(300)]
nts = NetworkTopologyStrategy({"dc1": 3, "dc2": 2})
replica_map = nts.make_token_replica_map(token_to_host_owner, ring)
token_replicas = replica_map[MD5Token(0)]
self.assertItemsEqual(token_replicas, (dc1_1, dc1_2, dc1_3, dc2_1, dc2_3))
示例2: test_nts_token_performance
# 需要导入模块: from cassandra.metadata import NetworkTopologyStrategy [as 别名]
# 或者: from cassandra.metadata.NetworkTopologyStrategy import make_token_replica_map [as 别名]
def test_nts_token_performance(self):
"""
Tests to ensure that when rf exceeds the number of nodes available, that we dont'
needlessly iterate trying to construct tokens for nodes that don't exist.
@since 3.7
@jira_ticket PYTHON-379
@expected_result timing with 1500 rf should be same/similar to 3rf if we have 3 nodes
@test_category metadata
"""
token_to_host_owner = {}
ring = []
dc1hostnum = 3
current_token = 0
vnodes_per_host = 500
for i in range(dc1hostnum):
host = Host('dc1.{0}'.format(i), SimpleConvictionPolicy)
host.set_location_info('dc1', "rack1")
for vnode_num in range(vnodes_per_host):
md5_token = MD5Token(current_token+vnode_num)
token_to_host_owner[md5_token] = host
ring.append(md5_token)
current_token += 1000
nts = NetworkTopologyStrategy({'dc1': 3})
start_time = timeit.default_timer()
nts.make_token_replica_map(token_to_host_owner, ring)
elapsed_base = timeit.default_timer() - start_time
nts = NetworkTopologyStrategy({'dc1': 1500})
start_time = timeit.default_timer()
nts.make_token_replica_map(token_to_host_owner, ring)
elapsed_bad = timeit.default_timer() - start_time
difference = elapsed_bad - elapsed_base
self.assertTrue(difference < 1 and difference > -1)