Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/cassandra/cql.py
Show All 32 Lines | EXEC_PROFILE_DEFAULT: ExecutionProfile( | ||||
load_balancing_policy=TokenAwarePolicy(DCAwareRoundRobinPolicy())), | load_balancing_policy=TokenAwarePolicy(DCAwareRoundRobinPolicy())), | ||||
} | } | ||||
# Configuration for cassandra-driver's access to servers: | # Configuration for cassandra-driver's access to servers: | ||||
# * hit the right server directly when sending a query (TokenAwarePolicy), | # * hit the right server directly when sending a query (TokenAwarePolicy), | ||||
# * if there's more than one, then pick one at random that's in the same | # * if there's more than one, then pick one at random that's in the same | ||||
# datacenter as the client (DCAwareRoundRobinPolicy) | # datacenter as the client (DCAwareRoundRobinPolicy) | ||||
def create_keyspace(hosts: List[str], keyspace: str, port: int = 9042): | def create_keyspace(hosts: List[str], keyspace: str, port: int = 9042, | ||||
*, durable_writes=True): | |||||
cluster = Cluster( | cluster = Cluster( | ||||
hosts, port=port, execution_profiles=_execution_profiles) | hosts, port=port, execution_profiles=_execution_profiles) | ||||
session = cluster.connect() | session = cluster.connect() | ||||
extra_params = '' | |||||
if not durable_writes: | |||||
extra_params = 'AND durable_writes = false' | |||||
session.execute('''CREATE KEYSPACE IF NOT EXISTS "%s" | session.execute('''CREATE KEYSPACE IF NOT EXISTS "%s" | ||||
WITH REPLICATION = { | WITH REPLICATION = { | ||||
'class' : 'SimpleStrategy', | 'class' : 'SimpleStrategy', | ||||
'replication_factor' : 1 | 'replication_factor' : 1 | ||||
}; | } %s; | ||||
''' % keyspace) | ''' % (keyspace, extra_params)) | ||||
session.execute('USE "%s"' % keyspace) | session.execute('USE "%s"' % keyspace) | ||||
for query in CREATE_TABLES_QUERIES: | for query in CREATE_TABLES_QUERIES: | ||||
session.execute(query) | session.execute(query) | ||||
T = TypeVar('T') | T = TypeVar('T') | ||||
▲ Show 20 Lines • Show All 561 Lines • Show Last 20 Lines |