def install(version='stable', cluster_name='cassandra', **kwargs): """Install cassandra via ccm""" java_home = setup_java() cluster_path = os.path.join(ccm_home, cluster_name) if os.path.exists(cluster_path): print("Cassandra cluster already created at {cluster_path}".format(**locals())) return if is_cassandra_running(): print("Another Cassandra process is already running. You must stop it (cqs stop --force) before you can install Cassandra with this tool.") return makedirs(ccm_home) try: cluster = ccmlib.cluster.Cluster(ccm_home, cluster_name, cassandra_version=version, verbose=True) with open(os.path.join(cluster_path, 'cassandra.in.sh'), 'w') as f: f.write("JAVA_HOME={java_home}\n".format(**locals())) cluster.populate(1) start(cluster_name=cluster_name) except: # If any problem occurs, clean things up by destroying the cluster: destroy(cluster_name) raise print("Cassandra started.")
def ccm_create(version="git:cassandra-2.0"): test_path = tempfile.mkdtemp(prefix='dtest-') print "cluster ccm directory: %s" % test_path cluster = ccmlib.cluster.Cluster(test_path, 'test', cassandra_version=version) cluster.set_configuration_options(values={'initial_token': None, 'num_tokens': 256}) cluster.populate(1) cluster.start()
def check_cassandra_version(cassandra_version): with GracefulCluster('thrift-test', cassandra_version, 'RandomPartitioner', ThriftMultigetTestCase.ClusterOptions) as cluster: cluster.set_log_level("TRACE") cluster.populate(3, debug=True) cluster.start() log('Populate nodes') ThriftMultigetTestCase._prepare_for_test(cluster) cluster.nodetool('settraceprobability 1') log('Enable tracing on every node') return ThriftMultigetTestCase._check_cassandra()
#!/usr/bin/python2.7 import ccmlib.cluster from pycassa import SystemManager, ConnectionPool, ColumnFamily, SIMPLE_STRATEGY, cassandra values = list(map(str, range(10))) keyspace, table = 'test_keyspace', 'test_table' cluster = ccmlib.cluster.Cluster('.', 'thrift-test', partitioner='RandomPartitioner', cassandra_version='3.11.2') cluster.set_configuration_options({'start_rpc': 'true', 'hinted_handoff_enabled': 'false'}) cluster.populate(3, debug=True).start() sys = SystemManager('127.0.0.1') sys.create_keyspace(keyspace, SIMPLE_STRATEGY, {'replication_factor': '3'}) sys.create_column_family(keyspace, table) # Imitate temporary node unavailability that cause inconsistency in data across nodes failing_node = cluster.nodelist()[2] failing_node.stop() cf = ColumnFamily(ConnectionPool(keyspace, server_list=['127.0.0.1']), table) for value in values: cf.insert(value, {'value': value}, write_consistency_level=cassandra.ttypes.ConsistencyLevel.QUORUM) failing_node.start() failing_node.wait_for_thrift_interface() cf = ColumnFamily(ConnectionPool(keyspace, server_list=['127.0.0.3']), table) # Returns many Nones records print(cf.multiget(values, read_consistency_level=cassandra.ttypes.ConsistencyLevel.QUORUM).values()) cf = ColumnFamily(ConnectionPool(keyspace, server_list=['127.0.0.1']), table) # All returned records are fine print(cf.multiget(values, read_consistency_level=cassandra.ttypes.ConsistencyLevel.ONE).values()) cluster.stop()