Skip to content

Commit

Permalink
Merge pull request #6016 from planetscale/rn-local-example-new-flows
Browse files Browse the repository at this point in the history
Local Example: modified for new vreplication workflows
  • Loading branch information
morgo authored Apr 13, 2020
2 parents fa58c10 + cf813a8 commit 056d8c2
Show file tree
Hide file tree
Showing 16 changed files with 98 additions and 80 deletions.
4 changes: 2 additions & 2 deletions examples/local/101_initial_cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ source ./env.sh

# start topo server
if [ "${TOPO}" = "zk2" ]; then
CELL=zone1 ./scripts/zk-up.sh
CELL=zone1 ./scripts/zk-up.sh
elif [ "${TOPO}" = "k8s" ]; then
CELL=zone1 ./scripts/k3s-up.sh
CELL=zone1 ./scripts/k3s-up.sh
else
CELL=zone1 ./scripts/etcd-up.sh
fi
Expand Down
20 changes: 0 additions & 20 deletions examples/local/201_customer_keyspace.sh

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2019 The Vitess Authors.
# Copyright 2020 The Vitess Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -26,7 +26,6 @@ for i in 200 201 202; do
done

vtctlclient -server localhost:15999 InitShardMaster -force customer/0 zone1-200
vtctlclient -server localhost:15999 CopySchemaShard -tables customer,corder commerce/0 customer/0
vtctlclient -server localhost:15999 ApplyVSchema -vschema_file vschema_commerce_vsplit.json commerce
vtctlclient -server localhost:15999 ApplyVSchema -vschema_file vschema_customer_vsplit.json customer
vtctlclient -server localhost:15999 ApplyVSchema -vschema '{ "tables": { "product": {} } }' commerce
vtctlclient -server localhost:15999 ApplyVSchema -vschema '{ "tables": { "customer": {}, "corder": {} } }' customer

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2019 The Vitess Authors.
# Copyright 2020 The Vitess Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,11 +19,12 @@

source ./env.sh

vtworker \
$TOPOLOGY_FLAGS \
-cell zone1 \
vtctlclient \
-server localhost:15999 \
-log_dir "$VTDATAROOT"/tmp \
-alsologtostderr \
-use_v3_resharding_mode \
VerticalSplitClone -min_healthy_tablets=1 -tables=customer,corder customer/0
MoveTables \
-workflow=commerce2customer \
commerce customer customer,corder

sleep 2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2019 The Vitess Authors.
# Copyright 2020 The Vitess Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,20 @@
# this script migrates traffic for the new customer keyspace to the new
# tablets of types rdonly and replica

vtctlclient -server localhost:15999 MigrateServedFrom customer/0 rdonly
vtctlclient -server localhost:15999 MigrateServedFrom customer/0 replica

vtctlclient \
-server localhost:15999 \
-log_dir "$VTDATAROOT"/tmp \
-alsologtostderr \
SwitchReads \
-tablet_type=rdonly \
customer.commerce2customer

vtctlclient \
-server localhost:15999 \
-log_dir "$VTDATAROOT"/tmp \
-alsologtostderr \
SwitchReads \
-tablet_type=replica \
customer.commerce2customer

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2019 The Vitess Authors.
# Copyright 2020 The Vitess Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,4 +17,9 @@
# this script migrates master traffic for the customer keyspace to the
# new master tablet

vtctlclient -server localhost:15999 MigrateServedFrom customer/0 master
vtctlclient \
-server localhost:15999 \
-log_dir "$VTDATAROOT"/tmp \
-alsologtostderr \
SwitchWrites \
customer.commerce2customer
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2019 The Vitess Authors.
# Copyright 2020 The Vitess Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 0 additions & 2 deletions examples/local/302_new_shards.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ done

vtctlclient -server localhost:15999 InitShardMaster -force customer/-80 zone1-300
vtctlclient -server localhost:15999 InitShardMaster -force customer/80- zone1-400
vtctlclient -server localhost:15999 CopySchemaShard customer/0 customer/-80
vtctlclient -server localhost:15999 CopySchemaShard customer/0 customer/80-
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2019 The Vitess Authors.
# Copyright 2020 The Vitess Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,10 +19,11 @@

source ./env.sh

vtworker \
$TOPOLOGY_FLAGS \
-cell zone1 \
-log_dir "$VTDATAROOT"/tmp \
-alsologtostderr \
-use_v3_resharding_mode \
SplitClone -min_healthy_rdonly_tablets=1 customer/0
vtctlclient \
-server localhost:15999 \
-log_dir "$VTDATAROOT"/tmp \
-alsologtostderr \
Reshard \
customer.cust2cust "0" "-80,80-"

sleep 2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2019 The Vitess Authors.
# Copyright 2020 The Vitess Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,5 +16,18 @@

# this script migrates traffic for the rdonly and replica tablets

vtctlclient -server localhost:15999 MigrateServedTypes customer/0 rdonly
vtctlclient -server localhost:15999 MigrateServedTypes customer/0 replica
vtctlclient \
-server localhost:15999 \
-log_dir "$VTDATAROOT"/tmp \
-alsologtostderr \
SwitchReads \
-tablet_type=rdonly \
customer.cust2cust

vtctlclient \
-server localhost:15999 \
-log_dir "$VTDATAROOT"/tmp \
-alsologtostderr \
SwitchReads \
-tablet_type=replica \
customer.cust2cust
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2019 The Vitess Authors.
# Copyright 2020 The Vitess Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,12 @@

# this script migrates traffic for the master tablet

vtctlclient -server localhost:15999 MigrateServedTypes customer/0 master
vtctlclient \
-server localhost:15999 \
-log_dir "$VTDATAROOT"/tmp \
-alsologtostderr \
SwitchWrites \
customer.cust2cust

# data has been copied over to shards, and databases for the new shards are now available

2 changes: 2 additions & 0 deletions examples/local/401_teardown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ for tablet in 100 200 300 400; do
# The zero tablet is up. Try to shutdown 0-2 tablet + mysqlctl
for i in 0 1 2; do
uid=$[$tablet + $i]
echo "Shutting down tablet zone1-$uid"
CELL=zone1 TABLET_UID=$uid ./scripts/vttablet-down.sh
echo "Shutting down mysql zone1-$uid"
CELL=zone1 TABLET_UID=$uid ./scripts/mysqlctl-down.sh
done
fi
Expand Down
5 changes: 3 additions & 2 deletions examples/local/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fi

# mysqld might be in /usr/sbin which will not be in the default PATH
PATH="/usr/sbin:$PATH"
for binary in mysqld etcd etcdctl curl vtctlclient vttablet vtgate vtctld vtctl mysqlctl; do
for binary in mysqld etcd etcdctl curl vtctlclient vttablet vtgate vtctld mysqlctl; do
command -v "$binary" > /dev/null || fail "${binary} is not installed in PATH. See https://vitess.io/docs/get-started/local/ for install instructions."
done;

Expand All @@ -54,6 +54,8 @@ if [ "${TOPO}" = "zk2" ]; then
ZK_SERVER="localhost:21811,localhost:21812,localhost:21813"
# shellcheck disable=SC2034
TOPOLOGY_FLAGS="-topo_implementation zk2 -topo_global_server_address ${ZK_SERVER} -topo_global_root /vitess/global"

mkdir -p $VTDATAROOT/tmp
elif [ "${TOPO}" = "k8s" ]; then
# Set topology environment parameters.
K8S_ADDR="localhost"
Expand All @@ -68,5 +70,4 @@ else
mkdir -p "${VTDATAROOT}/etcd"
fi

# Create a tmp dir
mkdir -p "${VTDATAROOT}/tmp"
5 changes: 0 additions & 5 deletions examples/local/vschema_commerce_vsplit.json

This file was deleted.

6 changes: 0 additions & 6 deletions examples/local/vschema_customer_vsplit.json

This file was deleted.

37 changes: 23 additions & 14 deletions test/local_example.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2019 The Vitess Authors.
# Copyright 2020 The Vitess Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,19 +30,30 @@ unset VTROOT # ensure that the examples can run without VTROOT now.

mysql -h 127.0.0.1 -P 15306 < ../common/insert_commerce_data.sql
mysql -h 127.0.0.1 -P 15306 --table < ../common/select_commerce_data.sql
./201_customer_keyspace.sh
./202_customer_tablets.sh
./203_vertical_split.sh
mysql -h 127.0.0.1 -P 15306 --table < ../common/select_customer0_data.sql

./204_vertical_migrate_replicas.sh
./205_vertical_migrate_master.sh
./201_customer_tablets.sh

for shard in "customer/0"; do
while true; do
mysql -h 127.0.0.1 -P 15306 "$shard" -e 'show tables' && break || echo "waiting for shard: $shard!"
sleep 1
done;
done;

./202_move_tables.sh

./203_switch_reads.sh

./204_switch_writes.sh

mysql -h 127.0.0.1 -P 15306 --table < ../common/select_customer0_data.sql
# Expected to fail!
mysql -h 127.0.0.1 -P 15306 --table < ../common/select_commerce_data.sql || echo "Blacklist working as expected"
./206_clean_commerce.sh
./205_clean_commerce.sh
# Expected to fail!
mysql -h 127.0.0.1 -P 15306 --table < ../common/select_commerce_data.sql || echo "Tables missing as expected"


./301_customer_sharded.sh
./302_new_shards.sh

Expand All @@ -55,15 +66,13 @@ for shard in "customer/-80" "customer/80-"; do
done;
done;

mysql -h 127.0.0.1 -P 15306 --table < ../common/select_customer-80_data.sql
mysql -h 127.0.0.1 -P 15306 --table < ../common/select_customer80-_data.sql
./303_reshard.sh

./303_horizontal_split.sh

./304_migrate_replicas.sh
./305_migrate_master.sh
./304_switch_reads.sh
./305_switch_writes.sh

mysql -h 127.0.0.1 -P 15306 --table < ../common/select_customer-80_data.sql
mysql -h 127.0.0.1 -P 15306 --table < ../common/select_customer80-_data.sql

./401_teardown.sh

0 comments on commit 056d8c2

Please sign in to comment.