本文整理匯總了Python中cassandra.policies.RoundRobinPolicy方法的典型用法代碼示例。如果您正苦於以下問題:Python policies.RoundRobinPolicy方法的具體用法?Python policies.RoundRobinPolicy怎麽用?Python policies.RoundRobinPolicy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cassandra.policies
的用法示例。
在下文中一共展示了policies.RoundRobinPolicy方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _get_loadbalancing_policy
# 需要導入模塊: from cassandra import policies [as 別名]
# 或者: from cassandra.policies import RoundRobinPolicy [as 別名]
def _get_loadbalancing_policy(self, policy):
# NOTE(nick-ma-z): http://datastax.github.io/python-driver/
# api/cassandra/policies.html
if policy == 'rr':
return policies.RoundRobinPolicy()
elif policy == 'dc_rr':
return policies.DCAwareRoundRobinPolicy(
cfg.CONF.df_cassandra.local_dc_name,
cfg.CONF.df_cassandra.used_hosts_per_remote_dc)
elif policy == 'wl_rr':
return policies.WhiteListRoundRobinPolicy(
cfg.CONF.df_cassandra.whitelist_hosts)
elif policy == 'token_rr':
return policies.TokenAwarePolicy(
policies.RoundRobinPolicy())
else:
# by default
return policies.RoundRobinPolicy()
示例2: init
# 需要導入模塊: from cassandra import policies [as 別名]
# 或者: from cassandra.policies import RoundRobinPolicy [as 別名]
def init(args):
global solr_connection
solr_connection = SolrConnection(args.solr)
global solr_collection
solr_collection = solr_connection[args.collection]
global SOLR_UNIQUE_KEY
SOLR_UNIQUE_KEY = args.solrIdField
dc_policy = RoundRobinPolicy()
token_policy = TokenAwarePolicy(dc_policy)
global cassandra_cluster
cassandra_cluster = Cluster(contact_points=args.cassandra, port=args.cassandraPort,
protocol_version=int(args.cassandraProtocolVersion),
load_balancing_policy=token_policy)
global cassandra_session
cassandra_session = cassandra_cluster.connect(keyspace=args.cassandraKeyspace)
global cassandra_table
cassandra_table = args.cassandraTable
示例3: get_db
# 需要導入模塊: from cassandra import policies [as 別名]
# 或者: from cassandra.policies import RoundRobinPolicy [as 別名]
def get_db(args):
log = logging.getLogger("cassandra")
patch_tables(args)
try:
cas_host, cas_port = args.cassandra.split(":")
except ValueError:
cas_host = args.cassandra
cas_port = "9042"
def get_cluster():
return Cluster((cas_host,), port=int(cas_port),
load_balancing_policy=RoundRobinPolicy())
cluster = get_cluster()
log.info("Connecting to %s", args.cassandra)
try:
session = cluster.connect(args.keyspace)
except NoHostAvailable:
log.warning("Keyspace %s does not exist", args.keyspace)
cluster = get_cluster()
session = cluster.connect()
return session
示例4: make_execution_profile
# 需要導入模塊: from cassandra import policies [as 別名]
# 或者: from cassandra.policies import RoundRobinPolicy [as 別名]
def make_execution_profile(retry_policy=FlakyRetryPolicy(), consistency_level=ConsistencyLevel.ONE, **kwargs):
if 'load_balancing_policy' in kwargs:
return ExecutionProfile(retry_policy=retry_policy,
consistency_level=consistency_level,
**kwargs)
else:
return ExecutionProfile(retry_policy=retry_policy,
consistency_level=consistency_level,
load_balancing_policy=RoundRobinPolicy(),
**kwargs)