Skip to content

Instantly share code, notes, and snippets.

@davidlzs
davidlzs / ccm_create_manage_local_cassandra_cluster.sh
Created April 8, 2021 22:53
Using ccm to create and manage local Cassandra cluster
# create a three node Cassandra Cluster
# the following command will create a cluster with Cassandra verion: 3.11.10, with 3 nodes, and start the cluster
python ccm.py create test -v 3.11.10 -n 3 -s
# view the status of the ring from node1's perspective, you can change to node2, node3 accordingly
python ccm.py node1 ring
# start a cqlsh connected to node1
python ccm.py node1 cqlsh
# stop node2
python ccm.py node2 stop
# start node2
@davidlzs
davidlzs / install_ccm_and_its_dependencies.sh
Created April 8, 2021 22:43
Install ccm and it's dependencies in miniconda
# activate ccm_env env
conda activate ccm_env
# install psutil
pip install psutil
# install ccm, which will install pyYAML and six
pip install ccm
@davidlzs
davidlzs / create_ccm_env_in_miniconda.sh
Created April 8, 2021 22:36
Create python environment in miniconda
# create ccm_env env by clone base env
conda create --name ccm_env --clone base
# list env
conda env list
-- begin new transaction; expect lost connection error here.
begin;
-- new transaction should succeed
begin;
insert into test values (22);
commit;
begin;
insert into test values (21);
commit;
# open a bash to our test conainer
docker exec -it db_backend_switch_nose_1 bash
# in the bash shell connect to proxysql admin
mysql -usbtest1 -ppassword -hproxysql -P6032
# view the current query rules
SELECT destination_hostgroup,apply FROM mysql_query_rules WHERE username='sbtest1';
# swtich to hostgroup 20
UPDATE mysql_query_rules SET destination_hostgroup=20 WHERE username='sbtest1';
# apply the changes
@davidlzs
davidlzs / simulated_application_connect_to_mysql_via_proxysql.sh
Created March 25, 2021 22:21
Open a bash shell to test container to simulate application connection to mysql via ProxySQL
# open a bash to our test conainer
docker exec -it db_backend_switch_nose_1 bash
# in the bash shell connect to mysql db via proxysql
mysql -usbtest1 -ppassword -hproxysql -P6033
# turn off autocommit
set autocommit=0;
# start long running transaction
begin;
insert into test values (11);
@davidlzs
davidlzs / create_mysql_test_schema.sh
Created March 25, 2021 21:55
Create mysql test schema for ProxySQL test
# open a bash to our test conainer
docker exec -it db_backend_switch_nose_1 bash
# in the bash shell connect to db1 directly
mysql -usbtest1 -ppassword -hdb1
# run the following sql to create our test table in db1
create table test(id int primary key);
# in the bash shell connect to db2 directly
mysql -usbtest1 -ppassword -hdb2
@davidlzs
davidlzs / gist:0435e74c970b3634388c84514d989690
Created March 19, 2021 17:51
Cassandra UDF textToTimestamp
CREATE OR REPLACE FUNCTION akka_projection.textToTimestamp (
input TEXT
)
CALLED ON NULL INPUT
RETURNS Timestamp
LANGUAGE java AS
$$
final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L;
UUID uuid = UUID.fromString(input);
@davidlzs
davidlzs / enable_cassandra_user_defined_functions.sh
Created March 19, 2021 17:48
Update cassandra.yaml to enable user defined functions
sed -i -r 's/enable_user_defined_functions: false/enable_user_defined_functions: true/' /etc/cassandra/cassandra.yaml