From 6f5c62f50c60c5c4c75ff05a8440bd3b45bacd7f Mon Sep 17 00:00:00 2001 From: Morgan Tocker Date: Wed, 15 Apr 2020 21:40:04 -0600 Subject: [PATCH 1/2] Harmonize local examples with helm improvements Signed-off-by: Morgan Tocker --- examples/local/101_initial_cluster.sh | 22 ++++++------ examples/local/201_customer_tablets.sh | 15 ++++---- examples/local/202_move_tables.sh | 16 +++------ examples/local/203_switch_reads.sh | 25 ++++---------- examples/local/204_switch_writes.sh | 15 ++++---- examples/local/205_clean_commerce.sh | 16 +++++---- examples/local/301_customer_sharded.sh | 16 +++++---- examples/local/302_new_shards.sh | 20 +++++------ examples/local/303_reshard.sh | 15 +++----- examples/local/304_switch_reads.sh | 23 ++++-------- examples/local/305_switch_writes.sh | 16 +++------ examples/local/306_down_shard_0.sh | 13 +++---- examples/local/307_delete_shard_0.sh | 10 +++--- examples/local/401_teardown.sh | 48 +++++++++++++------------- examples/local/alias.source | 4 --- examples/local/env.sh | 17 ++++++--- test/local_example.sh | 25 ++++++++------ 17 files changed, 141 insertions(+), 175 deletions(-) delete mode 100644 examples/local/alias.source diff --git a/examples/local/101_initial_cluster.sh b/examples/local/101_initial_cluster.sh index 3d5b7221efa..5d42d908f6e 100755 --- a/examples/local/101_initial_cluster.sh +++ b/examples/local/101_initial_cluster.sh @@ -1,13 +1,13 @@ #!/bin/bash # Copyright 2019 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. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,11 +21,11 @@ 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 + CELL=zone1 ./scripts/etcd-up.sh fi # start vtctld @@ -33,18 +33,18 @@ CELL=zone1 ./scripts/vtctld-up.sh # start vttablets for keyspace commerce for i in 100 101 102; do - CELL=zone1 TABLET_UID=$i ./scripts/mysqlctl-up.sh - CELL=zone1 KEYSPACE=commerce TABLET_UID=$i ./scripts/vttablet-up.sh + CELL=zone1 TABLET_UID=$i ./scripts/mysqlctl-up.sh + CELL=zone1 KEYSPACE=commerce TABLET_UID=$i ./scripts/vttablet-up.sh done # set one of the replicas to master -vtctlclient -server localhost:15999 InitShardMaster -force commerce/0 zone1-100 +vtctlclient InitShardMaster -force commerce/0 zone1-100 # create the schema -vtctlclient -server localhost:15999 ApplySchema -sql-file create_commerce_schema.sql commerce +vtctlclient ApplySchema -sql-file create_commerce_schema.sql commerce # create the vschema -vtctlclient -server localhost:15999 ApplyVSchema -vschema_file vschema_commerce_initial.json commerce +vtctlclient ApplyVSchema -vschema_file vschema_commerce_initial.json commerce # start vtgate CELL=zone1 ./scripts/vtgate-up.sh diff --git a/examples/local/201_customer_tablets.sh b/examples/local/201_customer_tablets.sh index ec7dcbd80f0..b53ffb6cd16 100755 --- a/examples/local/201_customer_tablets.sh +++ b/examples/local/201_customer_tablets.sh @@ -1,13 +1,13 @@ #!/bin/bash # 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. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -21,11 +21,8 @@ source ./env.sh for i in 200 201 202; do - CELL=zone1 TABLET_UID=$i ./scripts/mysqlctl-up.sh - CELL=zone1 KEYSPACE=customer TABLET_UID=$i ./scripts/vttablet-up.sh + CELL=zone1 TABLET_UID=$i ./scripts/mysqlctl-up.sh + CELL=zone1 KEYSPACE=customer TABLET_UID=$i ./scripts/vttablet-up.sh done -vtctlclient -server localhost:15999 InitShardMaster -force customer/0 zone1-200 -vtctlclient -server localhost:15999 ApplyVSchema -vschema '{ "tables": { "product": {} } }' commerce -vtctlclient -server localhost:15999 ApplyVSchema -vschema '{ "tables": { "customer": {}, "corder": {} } }' customer - +vtctlclient InitShardMaster -force customer/0 zone1-200 diff --git a/examples/local/202_move_tables.sh b/examples/local/202_move_tables.sh index b7ffd9699bf..8bf69cf95dd 100755 --- a/examples/local/202_move_tables.sh +++ b/examples/local/202_move_tables.sh @@ -1,13 +1,13 @@ #!/bin/bash # 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. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,12 +19,4 @@ source ./env.sh -vtctlclient \ - -server localhost:15999 \ - -log_dir "$VTDATAROOT"/tmp \ - -alsologtostderr \ - MoveTables \ - -workflow=commerce2customer \ - commerce customer customer,corder - -sleep 2 +vtctlclient MoveTables -workflow=commerce2customer commerce customer '{"customer":{}, "corder":{}}' diff --git a/examples/local/203_switch_reads.sh b/examples/local/203_switch_reads.sh index 4027267713d..93b4a31b76c 100755 --- a/examples/local/203_switch_reads.sh +++ b/examples/local/203_switch_reads.sh @@ -1,13 +1,13 @@ #!/bin/bash # 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. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,20 +17,7 @@ # this script migrates traffic for the new customer keyspace to the new # tablets of types rdonly and replica +source ./env.sh -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 - +vtctlclient SwitchReads -tablet_type=rdonly customer.commerce2customer +vtctlclient SwitchReads -tablet_type=replica customer.commerce2customer diff --git a/examples/local/204_switch_writes.sh b/examples/local/204_switch_writes.sh index a0d5d3c31b5..b2a6434ad17 100755 --- a/examples/local/204_switch_writes.sh +++ b/examples/local/204_switch_writes.sh @@ -1,13 +1,13 @@ #!/bin/bash # 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. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,9 +17,6 @@ # this script migrates master traffic for the customer keyspace to the # new master tablet -vtctlclient \ - -server localhost:15999 \ - -log_dir "$VTDATAROOT"/tmp \ - -alsologtostderr \ - SwitchWrites \ - customer.commerce2customer +source ./env.sh + +vtctlclient SwitchWrites customer.commerce2customer diff --git a/examples/local/205_clean_commerce.sh b/examples/local/205_clean_commerce.sh index 8bccbe99b97..f01fa2429af 100755 --- a/examples/local/205_clean_commerce.sh +++ b/examples/local/205_clean_commerce.sh @@ -1,13 +1,13 @@ #!/bin/bash # 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. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -17,7 +17,9 @@ # this script removes the customer and corder tables from the commerce # keyspace -vtctlclient -server localhost:15999 ApplySchema -sql-file drop_commerce_tables.sql commerce -vtctlclient -server localhost:15999 SetShardTabletControl -blacklisted_tables=customer,corder -remove commerce/0 rdonly -vtctlclient -server localhost:15999 SetShardTabletControl -blacklisted_tables=customer,corder -remove commerce/0 replica -vtctlclient -server localhost:15999 SetShardTabletControl -blacklisted_tables=customer,corder -remove commerce/0 master +source ./env.sh + +vtctlclient SetShardTabletControl -blacklisted_tables=customer,corder -remove commerce/0 rdonly +vtctlclient SetShardTabletControl -blacklisted_tables=customer,corder -remove commerce/0 replica +vtctlclient SetShardTabletControl -blacklisted_tables=customer,corder -remove commerce/0 master +vtctlclient ApplyRoutingRules -rules='{}' diff --git a/examples/local/301_customer_sharded.sh b/examples/local/301_customer_sharded.sh index 5335a0e7392..033b219ed0b 100755 --- a/examples/local/301_customer_sharded.sh +++ b/examples/local/301_customer_sharded.sh @@ -1,13 +1,13 @@ #!/bin/bash # Copyright 2019 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. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,7 +20,9 @@ # it also changes the customer vschema from unsharded to sharded and # sets up the necessary vindexes -vtctlclient -server localhost:15999 ApplySchema -sql-file create_commerce_seq.sql commerce -vtctlclient -server localhost:15999 ApplyVSchema -vschema_file vschema_commerce_seq.json commerce -vtctlclient -server localhost:15999 ApplySchema -sql-file create_customer_sharded.sql customer -vtctlclient -server localhost:15999 ApplyVSchema -vschema_file vschema_customer_sharded.json customer +source ./env.sh + +vtctlclient ApplySchema -sql-file create_commerce_seq.sql commerce +vtctlclient ApplyVSchema -vschema_file vschema_commerce_seq.json commerce +vtctlclient ApplySchema -sql-file create_customer_sharded.sql customer +vtctlclient ApplyVSchema -vschema_file vschema_customer_sharded.json customer diff --git a/examples/local/302_new_shards.sh b/examples/local/302_new_shards.sh index c6400bd0762..33f2ec294e1 100755 --- a/examples/local/302_new_shards.sh +++ b/examples/local/302_new_shards.sh @@ -1,13 +1,13 @@ #!/bin/bash # Copyright 2019 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. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,19 +15,19 @@ # limitations under the License. # this script brings up new tablets for the two new shards that we will -# be creating in the customer keyspace and copies the schema +# be creating in the customer keyspace and copies the schema source ./env.sh for i in 300 301 302; do - CELL=zone1 TABLET_UID=$i ./scripts/mysqlctl-up.sh - SHARD=-80 CELL=zone1 KEYSPACE=customer TABLET_UID=$i ./scripts/vttablet-up.sh + CELL=zone1 TABLET_UID=$i ./scripts/mysqlctl-up.sh + SHARD=-80 CELL=zone1 KEYSPACE=customer TABLET_UID=$i ./scripts/vttablet-up.sh done for i in 400 401 402; do - CELL=zone1 TABLET_UID=$i ./scripts/mysqlctl-up.sh - SHARD=80- CELL=zone1 KEYSPACE=customer TABLET_UID=$i ./scripts/vttablet-up.sh + CELL=zone1 TABLET_UID=$i ./scripts/mysqlctl-up.sh + SHARD=80- CELL=zone1 KEYSPACE=customer TABLET_UID=$i ./scripts/vttablet-up.sh done -vtctlclient -server localhost:15999 InitShardMaster -force customer/-80 zone1-300 -vtctlclient -server localhost:15999 InitShardMaster -force customer/80- zone1-400 +vtctlclient InitShardMaster -force customer/-80 zone1-300 +vtctlclient InitShardMaster -force customer/80- zone1-400 diff --git a/examples/local/303_reshard.sh b/examples/local/303_reshard.sh index 227ea3296b2..2e980a8fee7 100755 --- a/examples/local/303_reshard.sh +++ b/examples/local/303_reshard.sh @@ -1,13 +1,13 @@ #!/bin/bash # 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. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,11 +19,4 @@ source ./env.sh -vtctlclient \ - -server localhost:15999 \ - -log_dir "$VTDATAROOT"/tmp \ - -alsologtostderr \ - Reshard \ - customer.cust2cust "0" "-80,80-" - -sleep 2 \ No newline at end of file +vtctlclient Reshard customer.cust2cust '0' '-80,80-' diff --git a/examples/local/304_switch_reads.sh b/examples/local/304_switch_reads.sh index aed6e6adada..041d4206048 100755 --- a/examples/local/304_switch_reads.sh +++ b/examples/local/304_switch_reads.sh @@ -1,13 +1,13 @@ #!/bin/bash # 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. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,18 +16,7 @@ # this script migrates traffic for the rdonly and replica tablets -vtctlclient \ - -server localhost:15999 \ - -log_dir "$VTDATAROOT"/tmp \ - -alsologtostderr \ - SwitchReads \ - -tablet_type=rdonly \ - customer.cust2cust +source ./env.sh -vtctlclient \ - -server localhost:15999 \ - -log_dir "$VTDATAROOT"/tmp \ - -alsologtostderr \ - SwitchReads \ - -tablet_type=replica \ - customer.cust2cust +vtctlclient SwitchReads -tablet_type=rdonly customer.cust2cust +vtctlclient SwitchReads -tablet_type=replica customer.cust2cust diff --git a/examples/local/305_switch_writes.sh b/examples/local/305_switch_writes.sh index 34dde1f971e..94a276e3867 100755 --- a/examples/local/305_switch_writes.sh +++ b/examples/local/305_switch_writes.sh @@ -1,13 +1,13 @@ #!/bin/bash # 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. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,12 +16,6 @@ # this script migrates traffic for the master tablet -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 +source ./env.sh +vtctlclient SwitchWrites customer.cust2cust diff --git a/examples/local/306_down_shard_0.sh b/examples/local/306_down_shard_0.sh index 25c23ab2111..9b6a0ed8180 100755 --- a/examples/local/306_down_shard_0.sh +++ b/examples/local/306_down_shard_0.sh @@ -1,13 +1,13 @@ #!/bin/bash # Copyright 2019 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. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -15,8 +15,9 @@ # limitations under the License. # this script brings down the tablets for customer/0 keyspace +source ./env.sh + for i in 200 201 202; do - CELL=zone1 TABLET_UID=$i ./scripts/vttablet-down.sh - CELL=zone1 TABLET_UID=$i ./scripts/mysqlctl-down.sh + CELL=zone1 TABLET_UID=$i ./scripts/vttablet-down.sh + CELL=zone1 TABLET_UID=$i ./scripts/mysqlctl-down.sh done - diff --git a/examples/local/307_delete_shard_0.sh b/examples/local/307_delete_shard_0.sh index 662bb7cdfe9..12fdba72c8a 100755 --- a/examples/local/307_delete_shard_0.sh +++ b/examples/local/307_delete_shard_0.sh @@ -1,13 +1,13 @@ #!/bin/bash # Copyright 2019 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. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -16,4 +16,6 @@ # this script deletes the old shard 0 which has been replaced by 2 shards -vtctlclient -server localhost:15999 DeleteShard -recursive customer/0 +source ./env.sh + +vtctlclient DeleteShard -recursive customer/0 diff --git a/examples/local/401_teardown.sh b/examples/local/401_teardown.sh index 5c6e279fb0b..ccca63bab0d 100755 --- a/examples/local/401_teardown.sh +++ b/examples/local/401_teardown.sh @@ -1,13 +1,13 @@ #!/bin/bash # Copyright 2019 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. # You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -22,41 +22,41 @@ source ./env.sh ./scripts/vtgate-down.sh for tablet in 100 200 300 400; do - if vtctlclient -server localhost:15999 GetTablet zone1-$tablet >/dev/null 2>&1 ; then - # 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 + if vtctlclient -server localhost:15999 GetTablet zone1-$tablet >/dev/null 2>&1; then + # 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 done ./scripts/vtctld-down.sh if [ "${TOPO}" = "zk2" ]; then - CELL=zone1 ./scripts/zk-down.sh + CELL=zone1 ./scripts/zk-down.sh elif [ "${TOPO}" = "k8s" ]; then - CELL=zone1 ./scripts/k3s-down.sh + CELL=zone1 ./scripts/k3s-down.sh else - CELL=zone1 ./scripts/etcd-down.sh + CELL=zone1 ./scripts/etcd-down.sh fi # pedantic check: grep for any remaining processes if [ ! -z "$VTDATAROOT" ]; then - if pgrep -f -l "$VTDATAROOT" > /dev/null; then - echo "ERROR: Stale processes detected! It is recommended to manuallly kill them:" - pgrep -f -l "$VTDATAROOT" - else - echo "All good! It looks like every process has shut down" - fi + if pgrep -f -l "$VTDATAROOT" >/dev/null; then + echo "ERROR: Stale processes detected! It is recommended to manuallly kill them:" + pgrep -f -l "$VTDATAROOT" + else + echo "All good! It looks like every process has shut down" + fi - # shellcheck disable=SC2086 - rm -r ${VTDATAROOT:?}/* + # shellcheck disable=SC2086 + rm -r ${VTDATAROOT:?}/* fi diff --git a/examples/local/alias.source b/examples/local/alias.source deleted file mode 100644 index 7bdc9cb130b..00000000000 --- a/examples/local/alias.source +++ /dev/null @@ -1,4 +0,0 @@ -echo "Setting alias mysql to mysql -h 127.0.0.1 -P 15306" -alias mysql="mysql -h 127.0.0.1 -P 15306" -echo "Setting alias vtctlclient to vtctlclient -server localhost:15999 -log_dir $VTDATAROOT/tmp -alsologtostderr" -alias vtctlclient="vtctlclient -server localhost:15999 -log_dir $VTDATAROOT/tmp -alsologtostderr" diff --git a/examples/local/env.sh b/examples/local/env.sh index 74f929692f5..c0b982a3dbe 100644 --- a/examples/local/env.sh +++ b/examples/local/env.sh @@ -14,9 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -set -e - -hostname=`hostname -f` +hostname=$(hostname -f) vtctld_web_port=15000 export VTDATAROOT="${VTDATAROOT:-${PWD}/vtdataroot}" @@ -55,7 +53,7 @@ if [ "${TOPO}" = "zk2" ]; then # shellcheck disable=SC2034 TOPOLOGY_FLAGS="-topo_implementation zk2 -topo_global_server_address ${ZK_SERVER} -topo_global_root /vitess/global" - mkdir -p $VTDATAROOT/tmp + mkdir -p "${VTDATAROOT}/tmp" elif [ "${TOPO}" = "k8s" ]; then # Set topology environment parameters. K8S_ADDR="localhost" @@ -71,3 +69,14 @@ else fi mkdir -p "${VTDATAROOT}/tmp" + +# Set aliases to simplify instructions. +# In your own environment you may prefer to use config files, +# such as ~/.my.cnf + +alias mysql="command mysql -h 127.0.0.1 -P 15306" +alias vtctlclient="command vtctlclient -server localhost:15999 -log_dir ${VTDATAROOT}/tmp -alsologtostderr" + +# Make sure aliases are expanded in non-interactive shell +shopt -s expand_aliases + diff --git a/test/local_example.sh b/test/local_example.sh index ee5cd0142ec..a46370ae459 100755 --- a/test/local_example.sh +++ b/test/local_example.sh @@ -23,35 +23,38 @@ source build.env set -xe cd "$VTROOT/examples/local" - unset VTROOT # ensure that the examples can run without VTROOT now. +source ./env.sh # Required so that "mysql" works from alias + ./101_initial_cluster.sh -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 +mysql < ../common/insert_commerce_data.sql +mysql --table < ../common/select_commerce_data.sql ./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!" + mysql "$shard" -e 'show tables' && break || echo "waiting for shard: $shard!" sleep 1 done; done; ./202_move_tables.sh +sleep 3 # required for now + ./203_switch_reads.sh ./204_switch_writes.sh -mysql -h 127.0.0.1 -P 15306 --table < ../common/select_customer0_data.sql +mysql --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" +mysql --table < ../common/select_commerce_data.sql || echo "Blacklist working as expected" ./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" +mysql --table < ../common/select_commerce_data.sql || echo "Tables missing as expected" ./301_customer_sharded.sh @@ -61,18 +64,20 @@ mysql -h 127.0.0.1 -P 15306 --table < ../common/select_commerce_data.sql || echo # TODO: Eliminate this race in the examples' scripts for shard in "customer/-80" "customer/80-"; do while true; do - mysql -h 127.0.0.1 -P 15306 "$shard" -e 'show tables' && break || echo "waiting for shard: $shard!" + mysql "$shard" -e 'show tables' && break || echo "waiting for shard: $shard!" sleep 1 done; done; ./303_reshard.sh +sleep 3 # TODO: Required for now! + ./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 +mysql --table < ../common/select_customer-80_data.sql +mysql --table < ../common/select_customer80-_data.sql ./401_teardown.sh From a7bef0577fc75621fff4f9a8f8caa0164d342c42 Mon Sep 17 00:00:00 2001 From: Morgan Tocker Date: Wed, 15 Apr 2020 22:05:42 -0600 Subject: [PATCH 2/2] Add fix for slow start vtgate Signed-off-by: Morgan Tocker --- test/local_example.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/local_example.sh b/test/local_example.sh index a46370ae459..e6a06d62c94 100755 --- a/test/local_example.sh +++ b/test/local_example.sh @@ -29,6 +29,8 @@ source ./env.sh # Required so that "mysql" works from alias ./101_initial_cluster.sh +sleep 1 # Give vtgate a second to really start. + mysql < ../common/insert_commerce_data.sql mysql --table < ../common/select_commerce_data.sql