diff --git a/.github/workflows/region_example.yml b/.github/workflows/region_example.yml index 71a303ef38e..ce974c4aebd 100644 --- a/.github/workflows/region_example.yml +++ b/.github/workflows/region_example.yml @@ -105,5 +105,4 @@ jobs: if [ ${{matrix.os}} = "macos-latest" ]; then export PATH="/usr/local/opt/mysql@5.7/bin:$PATH" fi - sed -i 's/user\/my-vitess/runner\/work\/vitess\/vitess/g' examples/region_sharding/main_vschema_sharded.json #set correct path to countries.json eatmydata -- go run test.go -print-log -follow -retry=1 region_example diff --git a/.github/workflows/upgrade_downgrade_test_backups_manual.yml b/.github/workflows/upgrade_downgrade_test_backups_manual.yml index 2e2490b53b8..6a06378eb74 100644 --- a/.github/workflows/upgrade_downgrade_test_backups_manual.yml +++ b/.github/workflows/upgrade_downgrade_test_backups_manual.yml @@ -191,18 +191,18 @@ jobs: # We also insert a few rows in our three tables. - name: Create the example Vitess cluster with all components using version N if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' - timeout-minutes: 5 + timeout-minutes: 10 run: | - source build.env ; cd examples/local - ./backups/start_cluster.sh + source build.env ; cd examples/backups + ./start_cluster.sh # Taking a backup - name: Take a backup of all the shards if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' - timeout-minutes: 2 + timeout-minutes: 5 run: | - source build.env ; cd examples/local - ./backups/take_backups.sh + source build.env ; cd examples/backups + ./take_backups.sh # We insert more data in every table after the backup. # When we restore the backup made in the previous step, we do not want to see the rows we are about to insert now. @@ -214,7 +214,7 @@ jobs: - name: Insert more data after the backup if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' run: | - source build.env ; cd examples/local ; source ./env.sh + source build.env ; cd examples; source ./common/env.sh echo "insert into customer(email) values('new_user_1@domain.com');" | mysql echo "insert into product(sku, description, price) values('SKU-1009', 'description', 89);" | mysql @@ -223,10 +223,10 @@ jobs: # Stop all the tablets and remove their data - name: Stop tablets if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' - timeout-minutes: 5 + timeout-minutes: 10 run: | - source build.env ; cd examples/local - ./backups/stop_tablets.sh + source build.env ; cd examples/backups + ./stop_tablets.sh # We downgrade: we use the version N-1 of vttablet - name: Downgrade - Swap binaries, use VTTablet N-1 @@ -241,18 +241,18 @@ jobs: # Starting the tablets again, they will automatically start restoring the last backup. - name: Start new tablets and restore if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' - timeout-minutes: 5 + timeout-minutes: 10 run: | - source build.env ; cd examples/local - ./backups/restart_tablets.sh + source build.env ; cd examples/backups + ./restart_tablets.sh # give enough time to the tablets to restore the backup - sleep 60 + sleep 90 # Count the number of rows in each table to make sure the restoration is successful. - name: Assert the number of rows in every table if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' run: | - source build.env ; cd examples/local ; source ./env.sh + source build.env ; cd examples ; source ./common/env.sh echo "select count(sku) from product;" | mysql 2>&1| grep 2 echo "select count(email) from customer;" | mysql 2>&1| grep 5 @@ -262,7 +262,7 @@ jobs: - name: Insert more rows in the tables if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' run: | - source build.env ; cd examples/local ; source ./env.sh + source build.env ; cd examples ; source ./common/env.sh echo "insert into customer(email) values('new_user_2@domain.com');" | mysql echo "insert into product(sku, description, price) values('SKU-1011', 'description', 111);" | mysql @@ -271,18 +271,18 @@ jobs: # Taking a second backup of the cluster. - name: Take a second backup of all the shards if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' - timeout-minutes: 2 + timeout-minutes: 10 run: | - source build.env ; cd examples/local - ./backups/take_backups.sh + source build.env ; cd examples/backups + ./take_backups.sh # Stopping the tablets so we can perform the upgrade. - name: Stop tablets if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' - timeout-minutes: 5 + timeout-minutes: 10 run: | - source build.env ; cd examples/local - ./backups/stop_tablets.sh + source build.env ; cd examples/backups + ./stop_tablets.sh # We upgrade: we swap binaries and use the version N of the tablet. - name: Upgrade - Swap binaries, use VTTablet N @@ -297,18 +297,18 @@ jobs: # Starting the tablets again and restoring the previous backup. - name: Start new tablets and restore if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' - timeout-minutes: 5 + timeout-minutes: 10 run: | - source build.env ; cd examples/local - ./backups/restart_tablets.sh + source build.env ; cd examples/backups + ./restart_tablets.sh # give enough time to the tablets to restore the backup - sleep 60 + sleep 90 # We count the number of rows in every table to check that the restore step was successful. - name: Assert the number of rows in every table if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' run: | - source build.env ; cd examples/local ; source ./env.sh + source build.env ; cd examples ; source ./common/env.sh echo "select count(sku) from product;" | mysql 2>&1| grep 3 echo "select count(email) from customer;" | mysql 2>&1| grep 6 diff --git a/.github/workflows/upgrade_downgrade_test_backups_manual_next_release.yml b/.github/workflows/upgrade_downgrade_test_backups_manual_next_release.yml index f58dff29f84..dc9be0d2781 100644 --- a/.github/workflows/upgrade_downgrade_test_backups_manual_next_release.yml +++ b/.github/workflows/upgrade_downgrade_test_backups_manual_next_release.yml @@ -194,18 +194,18 @@ jobs: # We also insert a few rows in our three tables. - name: Create the example Vitess cluster with all components using version N if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' - timeout-minutes: 5 + timeout-minutes: 10 run: | - source build.env ; cd examples/local - ./backups/start_cluster.sh + source build.env ; cd examples/backups + ./start_cluster.sh # Taking a backup - name: Take a backup of all the shards if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' - timeout-minutes: 2 + timeout-minutes: 5 run: | - source build.env ; cd examples/local - ./backups/take_backups.sh + source build.env ; cd examples/backups + ./take_backups.sh # We insert more data in every table after the backup. # When we restore the backup made in the next step, we do not want to see the rows we are about to insert now. @@ -217,7 +217,7 @@ jobs: - name: Insert more data after the backup if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' run: | - source build.env ; cd examples/local ; source ./env.sh + source build.env ; cd examples ; source ./common/env.sh echo "insert into customer(email) values('new_user_1@domain.com');" | mysql echo "insert into product(sku, description, price) values('SKU-1009', 'description', 89);" | mysql @@ -226,10 +226,10 @@ jobs: # Stop all the tablets and remove their data - name: Stop tablets if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' - timeout-minutes: 5 + timeout-minutes: 10 run: | - source build.env ; cd examples/local - ./backups/stop_tablets.sh + source build.env ; cd examples/backups + ./stop_tablets.sh # We downgrade: we use the version N+1 of vttablet - name: Downgrade - Swap binaries, use VTTablet N+1 @@ -244,10 +244,10 @@ jobs: # Starting the tablets again, they will automatically start restoring the last backup. - name: Start new tablets and restore if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' - timeout-minutes: 5 + timeout-minutes: 10 run: | - source build.env ; cd examples/local - ./backups/restart_tablets.sh + source build.env ; cd examples/backups + ./restart_tablets.sh # give enough time to the tablets to restore the backup sleep 60 @@ -255,7 +255,7 @@ jobs: - name: Assert the number of rows in every table if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' run: | - source build.env ; cd examples/local ; source ./env.sh + source build.env ; cd examples ; source ./common/env.sh echo "select count(sku) from product;" | mysql 2>&1| grep 2 echo "select count(email) from customer;" | mysql 2>&1| grep 5 @@ -265,7 +265,7 @@ jobs: - name: Insert more rows in the tables if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' run: | - source build.env ; cd examples/local ; source ./env.sh + source build.env ; cd examples ; source ./common/env.sh echo "insert into customer(email) values('new_user_2@domain.com');" | mysql echo "insert into product(sku, description, price) values('SKU-1011', 'description', 111);" | mysql @@ -274,18 +274,18 @@ jobs: # Taking a second backup of the cluster. - name: Take a second backup of all the shards if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' - timeout-minutes: 2 + timeout-minutes: 10 run: | - source build.env ; cd examples/local - ./backups/take_backups.sh + source build.env ; cd examples/backups + ./take_backups.sh # Stopping the tablets so we can perform the upgrade. - name: Stop tablets if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' - timeout-minutes: 5 + timeout-minutes: 10 run: | - source build.env ; cd examples/local - ./backups/stop_tablets.sh + source build.env ; cd examples/backups + ./stop_tablets.sh # We upgrade: we swap binaries and use the version N of the tablet. - name: Upgrade - Swap binaries, use VTTablet N @@ -300,18 +300,18 @@ jobs: # Starting the tablets again and restoring the next backup. - name: Start new tablets and restore if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' - timeout-minutes: 5 + timeout-minutes: 10 run: | - source build.env ; cd examples/local - ./backups/restart_tablets.sh + source build.env ; cd examples/backups + ./restart_tablets.sh # give enough time to the tablets to restore the backup - sleep 60 + sleep 90 # We count the number of rows in every table to check that the restore step was successful. - name: Assert the number of rows in every table if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' run: | - source build.env ; cd examples/local ; source ./env.sh + source build.env ; cd examples ; source ./common/env.sh echo "select count(sku) from product;" | mysql 2>&1| grep 3 echo "select count(email) from customer;" | mysql 2>&1| grep 6 diff --git a/docker/local/Dockerfile b/docker/local/Dockerfile index 62e2c68ae10..ec7a1db0f9d 100644 --- a/docker/local/Dockerfile +++ b/docker/local/Dockerfile @@ -12,7 +12,7 @@ RUN /vt/dist/install_dependencies.sh mysql57 COPY docker/local/install_local_dependencies.sh /vt/dist/install_local_dependencies.sh RUN /vt/dist/install_local_dependencies.sh -RUN echo "source /vt/local/env.sh" >> /etc/bash.bashrc +RUN echo "source /vt/common/env.sh" >> /etc/bash.bashrc # Allows some docker builds to disable CGO ARG CGO_ENABLED=0 diff --git a/docker/mini/Dockerfile b/docker/mini/Dockerfile index df299ce8634..f9c14932eb0 100644 --- a/docker/mini/Dockerfile +++ b/docker/mini/Dockerfile @@ -35,8 +35,9 @@ COPY docker/mini/orchestrator-vitess-mini.conf.json /etc/orchestrator.conf.json RUN chown vitess:vitess /etc/orchestrator.conf.json COPY docker/mini/docker-entry /vt/dist/docker/mini/docker-entry -COPY examples/local/scripts /vt/dist/scripts -COPY examples/local/env.sh /vt/dist/scripts/env.sh +COPY examples/common/scripts /vt/dist/scripts +COPY examples/common/env.sh /vt/dist/scripts/env.sh +COPY examples/common/lib/utils.sh /vt/dist/scripts/lib/utils.sh COPY docker/mini/vtctld-mini-up.sh /vt/dist/scripts/vtctld-mini-up.sh COPY docker/mini/vttablet-mini-up.sh /vt/dist/scripts/vttablet-mini-up.sh COPY docker/mini/orchestrator-up.sh /vt/dist/scripts/orchestrator-up.sh diff --git a/examples/local/backups/create_commerce_schema.sql b/examples/backups/create_commerce_schema.sql similarity index 100% rename from examples/local/backups/create_commerce_schema.sql rename to examples/backups/create_commerce_schema.sql diff --git a/examples/local/backups/create_customer_schema.sql b/examples/backups/create_customer_schema.sql similarity index 100% rename from examples/local/backups/create_customer_schema.sql rename to examples/backups/create_customer_schema.sql diff --git a/examples/local/backups/restart_tablets.sh b/examples/backups/restart_tablets.sh similarity index 80% rename from examples/local/backups/restart_tablets.sh rename to examples/backups/restart_tablets.sh index 038fafc5dbf..13c4ed0cfb6 100755 --- a/examples/local/backups/restart_tablets.sh +++ b/examples/backups/restart_tablets.sh @@ -17,21 +17,21 @@ # this script brings up new tablets for the two new shards that we will # be creating in the customer keyspace and copies the schema -source ./env.sh +source ../common/env.sh 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 ../common/scripts/mysqlctl-up.sh + CELL=zone1 KEYSPACE=commerce TABLET_UID=$i ../common/scripts/vttablet-up.sh done for i in 200 201 202; 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 ../common/scripts/mysqlctl-up.sh + SHARD=-80 CELL=zone1 KEYSPACE=customer TABLET_UID=$i ../common/scripts/vttablet-up.sh done 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 ../common/scripts/mysqlctl-up.sh + SHARD=80- CELL=zone1 KEYSPACE=customer TABLET_UID=$i ../common/scripts/vttablet-up.sh done sleep 5 @@ -40,7 +40,7 @@ sleep 5 # complete before we start InitShardPrimary, otherwise we end up reading the # tablet type to RESTORE and do not set semi-sync, which leads to the primary # hanging on writes. -totalTime=300 +totalTime=600 for i in 101 201 301; do while [ $totalTime -gt 0 ]; do status=$(curl "http://$hostname:15$i/debug/status_details") diff --git a/examples/local/backups/start_cluster.sh b/examples/backups/start_cluster.sh similarity index 51% rename from examples/local/backups/start_cluster.sh rename to examples/backups/start_cluster.sh index ff4fdd23342..a9e2de606cb 100755 --- a/examples/local/backups/start_cluster.sh +++ b/examples/backups/start_cluster.sh @@ -17,56 +17,60 @@ # this script brings up new tablets for the two new shards that we will # be creating in the customer keyspace and copies the schema -source ./env.sh +source ../common/env.sh # start topo server if [ "${TOPO}" = "zk2" ]; then - CELL=zone1 ./scripts/zk-up.sh + CELL=zone1 ../common/scripts/zk-up.sh elif [ "${TOPO}" = "k8s" ]; then - CELL=zone1 ./scripts/k3s-up.sh + CELL=zone1 ../common/scripts/k3s-up.sh else - CELL=zone1 ./scripts/etcd-up.sh + CELL=zone1 ../common/scripts/etcd-up.sh fi # start vtctld -CELL=zone1 ./scripts/vtctld-up.sh +CELL=zone1 ../common/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 ../common/scripts/mysqlctl-up.sh + CELL=zone1 KEYSPACE=commerce TABLET_UID=$i ../common/scripts/vttablet-up.sh done # set one of the replicas to primary vtctldclient InitShardPrimary --force commerce/0 zone1-100 # create the schema for commerce -vtctlclient ApplySchema -- --sql-file backups/create_commerce_schema.sql commerce -vtctlclient ApplyVSchema -- --vschema_file ./vschema_commerce_seq.json commerce +vtctlclient ApplySchema -- --sql-file ./create_commerce_schema.sql commerce || fail "Could not apply schema for the commerce keyspace" +vtctlclient ApplyVSchema -- --vschema_file ../local/vschema_commerce_seq.json commerce || fail "Could not apply vschema for the commerce keyspace" # start vttablets for keyspace customer for i in 200 201 202; 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 ../common/scripts/mysqlctl-up.sh + SHARD=-80 CELL=zone1 KEYSPACE=customer TABLET_UID=$i ../common/scripts/vttablet-up.sh done 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 ../common/scripts/mysqlctl-up.sh + SHARD=80- CELL=zone1 KEYSPACE=customer TABLET_UID=$i ../common/scripts/vttablet-up.sh done # set one of the replicas to primary vtctldclient InitShardPrimary --force customer/-80 zone1-200 vtctldclient InitShardPrimary --force customer/80- zone1-300 +for shard in "-80" "80-"; do + wait_for_healthy_shard customer "${shard}" || exit 1 +done + # create the schema for customer -vtctlclient ApplySchema -- --sql-file backups/create_customer_schema.sql customer -vtctlclient ApplyVSchema -- --vschema_file ./vschema_customer_sharded.json customer +vtctlclient ApplySchema -- --sql-file ./create_customer_schema.sql customer || fail "Could not apply schema for the customer keyspace" +vtctlclient ApplyVSchema -- --vschema_file ../local/vschema_customer_sharded.json customer || fail "Could not apply vschema for the customer keyspace" # start vtgate -CELL=zone1 ./scripts/vtgate-up.sh +CELL=zone1 ../common/scripts/vtgate-up.sh sleep 5 diff --git a/examples/local/backups/stop_tablets.sh b/examples/backups/stop_tablets.sh similarity index 88% rename from examples/local/backups/stop_tablets.sh rename to examples/backups/stop_tablets.sh index 25470ac5491..2a45e9e68d2 100755 --- a/examples/local/backups/stop_tablets.sh +++ b/examples/backups/stop_tablets.sh @@ -17,7 +17,7 @@ # this script brings up new tablets for the two new shards that we will # be creating in the customer keyspace and copies the schema -source ./env.sh +source ../common/env.sh for tablet in 100 200 300; do if vtctlclient --action_timeout 1s --server localhost:15999 GetTablet zone1-$tablet >/dev/null 2>&1; then @@ -25,9 +25,9 @@ for tablet in 100 200 300; do 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 + CELL=zone1 TABLET_UID=$uid ../common/scripts/vttablet-down.sh echo "Shutting down mysql zone1-$uid" - CELL=zone1 TABLET_UID=$uid ./scripts/mysqlctl-down.sh + CELL=zone1 TABLET_UID=$uid ../common/scripts/mysqlctl-down.sh echo "Removing tablet directory zone1-$uid" vtctlclient DeleteTablet -- --allow_primary=true zone1-$uid rm -Rf $VTDATAROOT/vt_0000000$uid diff --git a/examples/local/backups/take_backups.sh b/examples/backups/take_backups.sh similarity index 81% rename from examples/local/backups/take_backups.sh rename to examples/backups/take_backups.sh index f8544a95b69..dc1b049c9c3 100755 --- a/examples/local/backups/take_backups.sh +++ b/examples/backups/take_backups.sh @@ -17,8 +17,8 @@ # this script brings up new tablets for the two new shards that we will # be creating in the customer keyspace and copies the schema -source ./env.sh +source ../common/env.sh -vtctlclient BackupShard customer/-80 -vtctlclient BackupShard customer/80- -vtctlclient BackupShard commerce/0 +for shard in "customer/-80" "customer/80-" "commerce/0"; do + vtctlclient BackupShard "${shard}" || fail "Failed to backup shard: ${shard}" +done diff --git a/examples/local/env.sh b/examples/common/env.sh similarity index 98% rename from examples/local/env.sh rename to examples/common/env.sh index b6db50a27b9..3b6a23a26cb 100644 --- a/examples/local/env.sh +++ b/examples/common/env.sh @@ -14,15 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. +source "$(dirname "${BASH_SOURCE[0]:-$0}")/lib/utils.sh" + hostname=$(hostname -f) vtctld_web_port=15000 export VTDATAROOT="${VTDATAROOT:-${PWD}/vtdataroot}" -function fail() { - echo "ERROR: $1" - exit 1 -} - if [[ $EUID -eq 0 ]]; then fail "This script refuses to be run as root. Please switch to a regular user." fi diff --git a/examples/common/lib/utils.sh b/examples/common/lib/utils.sh new file mode 100644 index 00000000000..ab13e9bc6c4 --- /dev/null +++ b/examples/common/lib/utils.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +# Copyright 2023 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. +# See the License for the specific language governing permissions and +# limitations under the License. + +# This file contains utility functions that can be used throughout the +# various examples. + +# Wait for the given number of tablets to show up in the topology server +# for the keyspace/shard. Example (wait for 2 tablets in commerce/0): +# wait_for_shard_tablets commerce 0 2 +function wait_for_shard_tablets() { + if [[ -z ${1} || -z ${2} || -z ${3} ]]; then + fail "A keyspace, shard, and number of tablets must be specified when waiting for tablets to come up" + fi + keyspace=${1} + shard=${2} + num_tablets=${3} + wait_secs=180 + + for _ in $(seq 1 ${wait_secs}); do + cur_tablets=$(vtctldclient GetTablets --keyspace "${keyspace}" --shard "${shard}" | wc -l) + if [[ ${cur_tablets} -eq ${num_tablets} ]]; then + break + fi + sleep 1 + done; + + cur_tablets=$(vtctldclient GetTablets --keyspace "${keyspace}" --shard "${shard}" | wc -l) + if [[ ${cur_tablets} -lt ${num_tablets} ]]; then + fail "Timed out after ${wait_secs} seconds waiting for tablets to come up in ${keyspace}/${shard}" + fi +} + +# Wait for a primary tablet to be elected and become healthy and serving +# in the given keyspace/shard. Example: +# wait_for_healthy_shard commerce 0 +function wait_for_healthy_shard_primary() { + if [[ -z ${1} || -z ${2} ]]; then + fail "A keyspace and shard must be specified when waiting for the shard's primary to be healthy" + fi + keyspace=${1} + shard=${2} + healthy_indicator="PRIMARY: Serving" + wait_secs=180 + + for _ in $(seq 1 ${wait_secs}); do + if curl -s "http://$(vtctldclient GetTablets --keyspace "${keyspace}" --shard "${shard}" | grep -i 'primary' | awk '{print $5}')/debug/status_details" | grep -qi "${healthy_indicator}"; then + break + fi + sleep 1 + done; + + curl -s "http://$(vtctldclient GetTablets --keyspace "${keyspace}" --shard "${shard}" | grep -i 'primary' | awk '{print $5}')/debug/status_details" | grep -qi "${healthy_indicator}" \ + || fail "Timed out after ${wait_secs} seconds waiting for a primary tablet to be elected and become healthy in ${keyspace}/${shard}" +} + +# Wait for a specified number of the keyspace/shard's tablets to show up +# in the topology server (3 is the default if no value is specified) and +# then wait for one of the tablets to be promoted to primary and become +# healthy and serving. Example: +# wait_for_healthy_shard commerce 0 +function wait_for_healthy_shard() { + if [[ -z ${1} || -z ${2} ]]; then + fail "A keyspace and shard must be specified when waiting for tablets to come up" + fi + keyspace=${1} + shard=${2} + num_tablets=${3:-3} + + wait_for_shard_tablets "${keyspace}" "${shard}" "${num_tablets}" + wait_for_healthy_shard_primary "${keyspace}" "${shard}" +} + +# Print error message and exit with error code. +function fail() { + echo "ERROR: ${1}" + exit 1 +} diff --git a/examples/local/scripts/consul-down.sh b/examples/common/scripts/consul-down.sh similarity index 93% rename from examples/local/scripts/consul-down.sh rename to examples/common/scripts/consul-down.sh index 6bebb8c72ec..4da5694525a 100755 --- a/examples/local/scripts/consul-down.sh +++ b/examples/common/scripts/consul-down.sh @@ -16,7 +16,7 @@ # This is an example script that stops the consul server started by consul-up.sh. -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" echo "Stopping consul..." kill -9 `cat $VTDATAROOT/tmp/consul.pid` diff --git a/examples/local/scripts/consul-up.sh b/examples/common/scripts/consul-up.sh similarity index 96% rename from examples/local/scripts/consul-up.sh rename to examples/common/scripts/consul-up.sh index 4a69d1e1902..584a25f437a 100755 --- a/examples/local/scripts/consul-up.sh +++ b/examples/common/scripts/consul-up.sh @@ -16,7 +16,7 @@ # This is an example script that creates a single-node consul datacenter. -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" cell=${CELL:-'test'} consul_http_port=${CONSUL_HTTP_PORT:-'8500'} diff --git a/examples/region_sharding/scripts/etcd-down.sh b/examples/common/scripts/etcd-down.sh similarity index 93% rename from examples/region_sharding/scripts/etcd-down.sh rename to examples/common/scripts/etcd-down.sh index 018af7432a3..f9894f8659c 100755 --- a/examples/region_sharding/scripts/etcd-down.sh +++ b/examples/common/scripts/etcd-down.sh @@ -16,7 +16,7 @@ # This is an example script that stops the etcd servers started by etcd-up.sh. -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" echo "Stopping etcd..." kill -9 `cat $VTDATAROOT/tmp/etcd.pid` diff --git a/examples/local/scripts/etcd-up.sh b/examples/common/scripts/etcd-up.sh similarity index 96% rename from examples/local/scripts/etcd-up.sh rename to examples/common/scripts/etcd-up.sh index 5d262217c88..20a16a42260 100755 --- a/examples/local/scripts/etcd-up.sh +++ b/examples/common/scripts/etcd-up.sh @@ -16,7 +16,7 @@ # This is an example script that creates a quorum of Etcd servers. -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" cell=${CELL:-'test'} export ETCDCTL_API=2 diff --git a/examples/local/scripts/k3s-down.sh b/examples/common/scripts/k3s-down.sh similarity index 91% rename from examples/local/scripts/k3s-down.sh rename to examples/common/scripts/k3s-down.sh index 590dc604e3e..195b024bf91 100755 --- a/examples/local/scripts/k3s-down.sh +++ b/examples/common/scripts/k3s-down.sh @@ -18,9 +18,7 @@ set -e -# shellcheck source=./env.sh -# shellcheck disable=SC1091 -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" # Stop K3s server. echo "Stopping k3s server..." diff --git a/examples/local/scripts/k3s-up.sh b/examples/common/scripts/k3s-up.sh similarity index 89% rename from examples/local/scripts/k3s-up.sh rename to examples/common/scripts/k3s-up.sh index b2ead1a86d6..7c85cb0ac07 100755 --- a/examples/local/scripts/k3s-up.sh +++ b/examples/common/scripts/k3s-up.sh @@ -19,11 +19,8 @@ set -e cell=${CELL:-'test'} -script_root=$(dirname "${BASH_SOURCE[0]}") - -# shellcheck source=./env.sh -# shellcheck disable=SC1091 -source ./env.sh +script_dir="$(dirname "${BASH_SOURCE[0]:-$0}")" +source "${script_dir}/../env.sh" case $(uname) in Linux) ;; @@ -47,7 +44,7 @@ sleep 15 KUBECTL="k3s kubectl --kubeconfig=${K8S_KUBECONFIG}" # Create the CRD for vitesstopologynodes -$KUBECTL create -f ../../go/vt/topo/k8stopo/VitessTopoNodes-crd.yaml +$KUBECTL create -f "${script_dir}/../../../go/vt/topo/k8stopo/VitessTopoNodes-crd.yaml" # Add the CellInfo description for the cell set +e diff --git a/examples/local/scripts/mysqlctl-down.sh b/examples/common/scripts/mysqlctl-down.sh similarity index 94% rename from examples/local/scripts/mysqlctl-down.sh rename to examples/common/scripts/mysqlctl-down.sh index 812558d6ca8..b2dee4e2119 100755 --- a/examples/local/scripts/mysqlctl-down.sh +++ b/examples/common/scripts/mysqlctl-down.sh @@ -17,7 +17,7 @@ # This is an example script that stops the mysqld and vttablet instances # created by vttablet-up.sh -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" cell=${CELL:-'test'} uid=$TABLET_UID diff --git a/examples/region_sharding/scripts/mysqlctl-up.sh b/examples/common/scripts/mysqlctl-up.sh similarity index 95% rename from examples/region_sharding/scripts/mysqlctl-up.sh rename to examples/common/scripts/mysqlctl-up.sh index ae041cf951d..d9df27ccdc0 100755 --- a/examples/region_sharding/scripts/mysqlctl-up.sh +++ b/examples/common/scripts/mysqlctl-up.sh @@ -16,7 +16,7 @@ # This is an example script that creates a single shard vttablet deployment. -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" cell=${CELL:-'test'} uid=$TABLET_UID diff --git a/examples/local/scripts/vtadmin-down.sh b/examples/common/scripts/vtadmin-down.sh similarity index 76% rename from examples/local/scripts/vtadmin-down.sh rename to examples/common/scripts/vtadmin-down.sh index 2a7944d9d5a..011e6da7f49 100755 --- a/examples/local/scripts/vtadmin-down.sh +++ b/examples/common/scripts/vtadmin-down.sh @@ -1,6 +1,6 @@ #!/bin/bash -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" echo "Stopping vtadmin-web..." kill -9 "$(cat "$VTDATAROOT/tmp/vtadmin-web.pid")" diff --git a/examples/local/scripts/vtadmin-up.sh b/examples/common/scripts/vtadmin-up.sh similarity index 89% rename from examples/local/scripts/vtadmin-up.sh rename to examples/common/scripts/vtadmin-up.sh index 5ee04c9a959..8f3caf39c15 100755 --- a/examples/local/scripts/vtadmin-up.sh +++ b/examples/common/scripts/vtadmin-up.sh @@ -1,9 +1,10 @@ #!/bin/bash -source ./env.sh +script_dir="$(dirname "${BASH_SOURCE[0]:-$0}")" +source "${script_dir}/../env.sh" log_dir="${VTDATAROOT}/tmp" -web_dir="../../web/vtadmin" +web_dir="${script_dir}/../../../web/vtadmin" vtadmin_api_port=14200 vtadmin_web_port=14201 @@ -18,7 +19,7 @@ vtadmin \ --logtostderr \ --alsologtostderr \ --rbac \ - --rbac-config="./vtadmin/rbac.yaml" \ + --rbac-config="${script_dir}/../vtadmin/rbac.yaml" \ --cluster "id=local,name=local,discovery=staticfile,discovery-staticfile-path=./vtadmin/discovery.json,tablet-fqdn-tmpl={{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \ > "${log_dir}/vtadmin-api.out" 2>&1 & diff --git a/examples/region_sharding/scripts/vtctld-down.sh b/examples/common/scripts/vtctld-down.sh similarity index 92% rename from examples/region_sharding/scripts/vtctld-down.sh rename to examples/common/scripts/vtctld-down.sh index d96fa3b927f..a56d59b97e5 100755 --- a/examples/region_sharding/scripts/vtctld-down.sh +++ b/examples/common/scripts/vtctld-down.sh @@ -16,7 +16,7 @@ # This is an example script that stops vtctld. -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" echo "Stopping vtctld..." kill -9 `cat $VTDATAROOT/tmp/vtctld.pid` diff --git a/examples/region_sharding/scripts/vtctld-up.sh b/examples/common/scripts/vtctld-up.sh similarity index 95% rename from examples/region_sharding/scripts/vtctld-up.sh rename to examples/common/scripts/vtctld-up.sh index 5ab8017424c..e49b346ca1e 100755 --- a/examples/region_sharding/scripts/vtctld-up.sh +++ b/examples/common/scripts/vtctld-up.sh @@ -16,7 +16,7 @@ # This is an example script that starts vtctld. -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" cell=${CELL:-'test'} grpc_port=15999 diff --git a/examples/region_sharding/scripts/vtgate-down.sh b/examples/common/scripts/vtgate-down.sh similarity index 93% rename from examples/region_sharding/scripts/vtgate-down.sh rename to examples/common/scripts/vtgate-down.sh index 9da0a7179df..3eea5fdf94d 100755 --- a/examples/region_sharding/scripts/vtgate-down.sh +++ b/examples/common/scripts/vtgate-down.sh @@ -16,7 +16,7 @@ # This is an example script that stops the instance started by vtgate-up.sh. -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" # Stop vtgate. echo "Stopping vtgate..." diff --git a/examples/local/scripts/vtgate-up.sh b/examples/common/scripts/vtgate-up.sh similarity index 96% rename from examples/local/scripts/vtgate-up.sh rename to examples/common/scripts/vtgate-up.sh index cb33e27839b..03b85869e5d 100755 --- a/examples/local/scripts/vtgate-up.sh +++ b/examples/common/scripts/vtgate-up.sh @@ -16,7 +16,7 @@ # This is an example script that starts a single vtgate. -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" cell=${CELL:-'test'} web_port=15001 diff --git a/examples/local/scripts/vtorc-down.sh b/examples/common/scripts/vtorc-down.sh similarity index 60% rename from examples/local/scripts/vtorc-down.sh rename to examples/common/scripts/vtorc-down.sh index 2fdfc1491ce..f4d2e4cb8a0 100755 --- a/examples/local/scripts/vtorc-down.sh +++ b/examples/common/scripts/vtorc-down.sh @@ -1,6 +1,6 @@ #!/bin/bash -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" echo "Stopping vtorc." kill -9 "$(cat "$VTDATAROOT/tmp/vtorc.pid")" diff --git a/examples/local/scripts/vtorc-up.sh b/examples/common/scripts/vtorc-up.sh similarity index 72% rename from examples/local/scripts/vtorc-up.sh rename to examples/common/scripts/vtorc-up.sh index f5a0d75dbba..66a826da288 100755 --- a/examples/local/scripts/vtorc-up.sh +++ b/examples/common/scripts/vtorc-up.sh @@ -1,6 +1,7 @@ #!/bin/bash -source ./env.sh +script_dir="$(dirname "${BASH_SOURCE[0]:-$0}")" +source "${script_dir}/../env.sh" log_dir="${VTDATAROOT}/tmp" port=16000 @@ -9,7 +10,7 @@ vtorc \ $TOPOLOGY_FLAGS \ --logtostderr \ --alsologtostderr \ - --config="./vtorc/config.json" \ + --config="${script_dir}/../vtorc/config.json" \ --port $port \ > "${log_dir}/vtorc.out" 2>&1 & diff --git a/examples/local/scripts/vttablet-down.sh b/examples/common/scripts/vttablet-down.sh similarity index 94% rename from examples/local/scripts/vttablet-down.sh rename to examples/common/scripts/vttablet-down.sh index 47b881b9793..3de266def76 100755 --- a/examples/local/scripts/vttablet-down.sh +++ b/examples/common/scripts/vttablet-down.sh @@ -17,7 +17,7 @@ # This is an example script that stops the mysqld and vttablet instances # created by vttablet-up.sh -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" printf -v tablet_dir 'vt_%010d' $TABLET_UID pid=`cat $VTDATAROOT/$tablet_dir/vttablet.pid` diff --git a/examples/local/scripts/vttablet-up.sh b/examples/common/scripts/vttablet-up.sh similarity index 97% rename from examples/local/scripts/vttablet-up.sh rename to examples/common/scripts/vttablet-up.sh index 43d0849ce76..0e70837d235 100755 --- a/examples/local/scripts/vttablet-up.sh +++ b/examples/common/scripts/vttablet-up.sh @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" cell=${CELL:-'test'} keyspace=${KEYSPACE:-'test_keyspace'} diff --git a/examples/region_sharding/scripts/zk-down.sh b/examples/common/scripts/zk-down.sh similarity index 93% rename from examples/region_sharding/scripts/zk-down.sh rename to examples/common/scripts/zk-down.sh index 18dd7933bc9..a9fa1e80a30 100755 --- a/examples/region_sharding/scripts/zk-down.sh +++ b/examples/common/scripts/zk-down.sh @@ -16,7 +16,7 @@ # This is an example script that stops the ZooKeeper servers started by zk-up.sh. -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" # Stop ZooKeeper servers. echo "Stopping zk servers..." diff --git a/examples/local/scripts/zk-up.sh b/examples/common/scripts/zk-up.sh similarity index 97% rename from examples/local/scripts/zk-up.sh rename to examples/common/scripts/zk-up.sh index d689e167988..519d5305b25 100755 --- a/examples/local/scripts/zk-up.sh +++ b/examples/common/scripts/zk-up.sh @@ -16,7 +16,7 @@ # This is an example script that creates a quorum of ZooKeeper servers. -source ./env.sh +source "$(dirname "${BASH_SOURCE[0]:-$0}")/../env.sh" cell=${CELL:-'test'} diff --git a/examples/local/topo-etcd2.sh b/examples/common/topo-etcd2.sh similarity index 100% rename from examples/local/topo-etcd2.sh rename to examples/common/topo-etcd2.sh diff --git a/examples/local/topo-k8s.sh b/examples/common/topo-k8s.sh similarity index 100% rename from examples/local/topo-k8s.sh rename to examples/common/topo-k8s.sh diff --git a/examples/local/topo-zk2.sh b/examples/common/topo-zk2.sh similarity index 100% rename from examples/local/topo-zk2.sh rename to examples/common/topo-zk2.sh diff --git a/examples/local/vtadmin/discovery.json b/examples/common/vtadmin/discovery.json similarity index 100% rename from examples/local/vtadmin/discovery.json rename to examples/common/vtadmin/discovery.json diff --git a/examples/local/vtadmin/rbac.yaml b/examples/common/vtadmin/rbac.yaml similarity index 100% rename from examples/local/vtadmin/rbac.yaml rename to examples/common/vtadmin/rbac.yaml diff --git a/examples/local/vtorc/config.json b/examples/common/vtorc/config.json similarity index 100% rename from examples/local/vtorc/config.json rename to examples/common/vtorc/config.json diff --git a/examples/local/101_initial_cluster.sh b/examples/local/101_initial_cluster.sh index a14fa142e4b..ffa24d7f98e 100755 --- a/examples/local/101_initial_cluster.sh +++ b/examples/local/101_initial_cluster.sh @@ -17,57 +17,47 @@ # this script brings up zookeeper and all the vitess components # required for a single shard deployment. -source ./env.sh +source ../common/env.sh # start topo server if [ "${TOPO}" = "zk2" ]; then - CELL=zone1 ./scripts/zk-up.sh + CELL=zone1 ../common/scripts/zk-up.sh elif [ "${TOPO}" = "k8s" ]; then - CELL=zone1 ./scripts/k3s-up.sh + CELL=zone1 ../common/scripts/k3s-up.sh elif [ "${TOPO}" = "consul" ]; then - CELL=zone1 ./scripts/consul-up.sh + CELL=zone1 ../common/scripts/consul-up.sh else - CELL=zone1 ./scripts/etcd-up.sh + CELL=zone1 ../common/scripts/etcd-up.sh fi # start vtctld -CELL=zone1 ./scripts/vtctld-up.sh +CELL=zone1 ../common/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 ../common/scripts/mysqlctl-up.sh + CELL=zone1 KEYSPACE=commerce TABLET_UID=$i ../common/scripts/vttablet-up.sh done # set the correct durability policy for the keyspace -vtctldclient --server localhost:15999 SetKeyspaceDurabilityPolicy --durability-policy=semi_sync commerce +vtctldclient --server localhost:15999 SetKeyspaceDurabilityPolicy --durability-policy=semi_sync commerce || fail "Failed to set keyspace durability policy on the commerce keyspace" # start vtorc -./scripts/vtorc-up.sh +../common/scripts/vtorc-up.sh # Wait for all the tablets to be up and registered in the topology server -for _ in $(seq 0 200); do - vtctldclient GetTablets --keyspace commerce --shard 0 | wc -l | grep -q "3" && break - sleep 1 -done; -vtctldclient GetTablets --keyspace commerce --shard 0 | wc -l | grep -q "3" || (echo "Timed out waiting for tablets to be up in commerce/0" && exit 1) - -# Wait for a primary tablet to be elected in the shard -for _ in $(seq 0 200); do - vtctldclient GetTablets --keyspace commerce --shard 0 | grep -q "primary" && break - sleep 1 -done; -vtctldclient GetTablets --keyspace commerce --shard 0 | grep "primary" || (echo "Timed out waiting for primary to be elected in commerce/0" && exit 1) +# and for a primary tablet to be elected in the shard and become healthy/serving. +wait_for_healthy_shard commerce 0 || exit 1 # create the schema -vtctldclient ApplySchema --sql-file create_commerce_schema.sql commerce +vtctldclient ApplySchema --sql-file create_commerce_schema.sql commerce || fail "Failed to apply schema for the commerce keyspace" # create the vschema -vtctldclient ApplyVSchema --vschema-file vschema_commerce_initial.json commerce +vtctldclient ApplyVSchema --vschema-file vschema_commerce_initial.json commerce || fail "Failed to apply vschema for the commerce keyspace" # start vtgate -CELL=zone1 ./scripts/vtgate-up.sh +CELL=zone1 ../common/scripts/vtgate-up.sh # start vtadmin -./scripts/vtadmin-up.sh +../common/scripts/vtadmin-up.sh diff --git a/examples/local/201_customer_tablets.sh b/examples/local/201_customer_tablets.sh index 6a27bef6cfc..1d5bf3585ce 100755 --- a/examples/local/201_customer_tablets.sh +++ b/examples/local/201_customer_tablets.sh @@ -18,26 +18,16 @@ # resharding it also splits the vschema between the two keyspaces # old (commerce) and new (customer) -source ./env.sh +source ../common/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 ../common/scripts/mysqlctl-up.sh + CELL=zone1 KEYSPACE=customer TABLET_UID=$i ../common/scripts/vttablet-up.sh done # set the correct durability policy for the keyspace -vtctldclient --server localhost:15999 SetKeyspaceDurabilityPolicy --durability-policy=semi_sync customer +vtctldclient --server localhost:15999 SetKeyspaceDurabilityPolicy --durability-policy=semi_sync customer || fail "Failed to set keyspace durability policy on the customer keyspace" # Wait for all the tablets to be up and registered in the topology server -for _ in $(seq 0 200); do - vtctldclient GetTablets --keyspace customer --shard 0 | wc -l | grep -q "3" && break - sleep 1 -done; -vtctldclient GetTablets --keyspace customer --shard 0 | wc -l | grep -q "3" || (echo "Timed out waiting for tablets to be up in customer/0" && exit 1) - -# Wait for a primary tablet to be elected in the shard -for _ in $(seq 0 200); do - vtctldclient GetTablets --keyspace customer --shard 0 | grep -q "primary" && break - sleep 1 -done; -vtctldclient GetTablets --keyspace customer --shard 0 | grep "primary" || (echo "Timed out waiting for primary to be elected in customer/0" && exit 1) +# and for a primary tablet to be elected in the shard and become healthy/serving. +wait_for_healthy_shard customer 0 || exit 1 diff --git a/examples/local/202_move_tables.sh b/examples/local/202_move_tables.sh index 2b69817445e..f385acb12a3 100755 --- a/examples/local/202_move_tables.sh +++ b/examples/local/202_move_tables.sh @@ -17,6 +17,6 @@ # this script copies over all the data from commerce keyspace to # customer keyspace for the customer and corder tables -source ./env.sh +source ../common/env.sh vtctlclient MoveTables -- --source commerce --tables 'customer,corder' Create customer.commerce2customer diff --git a/examples/local/203_switch_reads.sh b/examples/local/203_switch_reads.sh index 1c1abbe7ff0..4bca7e4e257 100755 --- a/examples/local/203_switch_reads.sh +++ b/examples/local/203_switch_reads.sh @@ -17,6 +17,6 @@ # this script migrates traffic for the new customer keyspace to the new # tablets of types rdonly and replica -source ./env.sh +source ../common/env.sh vtctlclient MoveTables -- --tablet_types=rdonly,replica SwitchTraffic customer.commerce2customer diff --git a/examples/local/204_switch_writes.sh b/examples/local/204_switch_writes.sh index a04f6ffc947..743ca1e2512 100755 --- a/examples/local/204_switch_writes.sh +++ b/examples/local/204_switch_writes.sh @@ -17,6 +17,6 @@ # this script migrates primary traffic for the customer keyspace to the # new primary tablet -source ./env.sh +source ../common/env.sh vtctlclient MoveTables -- --tablet_types=primary SwitchTraffic customer.commerce2customer diff --git a/examples/local/205_clean_commerce.sh b/examples/local/205_clean_commerce.sh index 37824052d27..5d307a231d3 100755 --- a/examples/local/205_clean_commerce.sh +++ b/examples/local/205_clean_commerce.sh @@ -17,7 +17,7 @@ # this script removes the customer and corder tables from the commerce # keyspace -source ./env.sh +source ../common/env.sh vtctlclient MoveTables Complete customer.commerce2customer diff --git a/examples/local/301_customer_sharded.sh b/examples/local/301_customer_sharded.sh index 8f008d0638b..ad80cdd98dd 100755 --- a/examples/local/301_customer_sharded.sh +++ b/examples/local/301_customer_sharded.sh @@ -20,9 +20,9 @@ # it also changes the customer vschema from unsharded to sharded and # sets up the necessary vindexes -source ./env.sh +source ../common/env.sh -vtctldclient ApplySchema --sql-file create_commerce_seq.sql commerce -vtctldclient ApplyVSchema --vschema-file vschema_commerce_seq.json commerce -vtctldclient ApplyVSchema --vschema-file vschema_customer_sharded.json customer -vtctldclient ApplySchema --sql-file create_customer_sharded.sql customer +vtctldclient ApplySchema --sql-file create_commerce_seq.sql commerce || fail "Failed to create sequence tables in the commerce keyspace" +vtctldclient ApplyVSchema --vschema-file vschema_commerce_seq.json commerce || fail "Failed to create vschema sequences in the commerce keyspace" +vtctldclient ApplyVSchema --vschema-file vschema_customer_sharded.json customer || fail "Failed to create vschema in sharded customer keyspace" +vtctldclient ApplySchema --sql-file create_customer_sharded.sql customer || fail "Failed to create schema in sharded customer keyspace" diff --git a/examples/local/302_new_shards.sh b/examples/local/302_new_shards.sh index 40569e2c20d..b2ac94f5c7f 100755 --- a/examples/local/302_new_shards.sh +++ b/examples/local/302_new_shards.sh @@ -17,30 +17,20 @@ # this script brings up new tablets for the two new shards that we will # be creating in the customer keyspace and copies the schema -source ./env.sh +source ../common/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 ../common/scripts/mysqlctl-up.sh + SHARD=-80 CELL=zone1 KEYSPACE=customer TABLET_UID=$i ../common/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 ../common/scripts/mysqlctl-up.sh + SHARD=80- CELL=zone1 KEYSPACE=customer TABLET_UID=$i ../common/scripts/vttablet-up.sh done for shard in "-80" "80-"; do - # Wait for all the tablets to be up and registered in the topology server - for _ in $(seq 0 200); do - vtctldclient GetTablets --keyspace customer --shard $shard | wc -l | grep -q "3" && break - sleep 1 - done; - vtctldclient GetTablets --keyspace customer --shard $shard | wc -l | grep -q "3" || (echo "Timed out waiting for tablets to be up in customer/$shard" && exit 1) - - # Wait for a primary tablet to be elected in the shard - for _ in $(seq 0 200); do - vtctldclient GetTablets --keyspace customer --shard $shard | grep -q "primary" && break - sleep 1 - done; - vtctldclient GetTablets --keyspace customer --shard $shard | grep "primary" || (echo "Timed out waiting for primary to be elected in customer/$shard" && exit 1) + # Wait for all the tablets to be up and registered in the topology server + # and for a primary tablet to be elected in the shard and become healthy/serving. + wait_for_healthy_shard customer "${shard}" || exit 1 done; diff --git a/examples/local/303_reshard.sh b/examples/local/303_reshard.sh index 510ba68b815..ea12987e9ed 100755 --- a/examples/local/303_reshard.sh +++ b/examples/local/303_reshard.sh @@ -17,6 +17,6 @@ # this script copies the data from customer/0 to customer/-80 and customer/80- # each row will be copied to exactly one shard based on the vindex value -source ./env.sh +source ../common/env.sh vtctlclient Reshard -- --source_shards '0' --target_shards '-80,80-' Create customer.cust2cust diff --git a/examples/local/304_switch_reads.sh b/examples/local/304_switch_reads.sh index 67d0fb45e85..52d6093f4ff 100755 --- a/examples/local/304_switch_reads.sh +++ b/examples/local/304_switch_reads.sh @@ -16,6 +16,6 @@ # this script migrates traffic for the rdonly and replica tablets -source ./env.sh +source ../common/env.sh vtctlclient Reshard -- --tablet_types=rdonly,replica SwitchTraffic customer.cust2cust diff --git a/examples/local/305_switch_writes.sh b/examples/local/305_switch_writes.sh index 289019b1363..9bbc7ed9ea5 100755 --- a/examples/local/305_switch_writes.sh +++ b/examples/local/305_switch_writes.sh @@ -16,6 +16,6 @@ # this script migrates traffic for the primary tablet -source ./env.sh +source ../common/env.sh vtctlclient Reshard -- --tablet_types=primary SwitchTraffic customer.cust2cust diff --git a/examples/local/306_down_shard_0.sh b/examples/local/306_down_shard_0.sh index 0d956553cd5..db860b3e23c 100755 --- a/examples/local/306_down_shard_0.sh +++ b/examples/local/306_down_shard_0.sh @@ -15,11 +15,11 @@ # limitations under the License. # this script brings down the tablets for customer/0 keyspace -source ./env.sh +source ../common/env.sh vtctlclient Reshard Complete customer.cust2cust 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 ../common/scripts/vttablet-down.sh + CELL=zone1 TABLET_UID=$i ../common/scripts/mysqlctl-down.sh done diff --git a/examples/local/307_delete_shard_0.sh b/examples/local/307_delete_shard_0.sh index a09e8f15c00..e0781990f56 100755 --- a/examples/local/307_delete_shard_0.sh +++ b/examples/local/307_delete_shard_0.sh @@ -16,6 +16,6 @@ # this script deletes the old shard 0 which has been replaced by 2 shards -source ./env.sh +source ../common/env.sh -vtctldclient DeleteShards --recursive customer/0 +vtctldclient DeleteShards --force --recursive customer/0 diff --git a/examples/local/401_teardown.sh b/examples/local/401_teardown.sh index ae78d262486..08dcbf3cd29 100755 --- a/examples/local/401_teardown.sh +++ b/examples/local/401_teardown.sh @@ -17,43 +17,42 @@ # We should not assume that any of the steps have been executed. # This makes it possible for a user to cleanup at any point. -source ./env.sh +source ../common/env.sh -./scripts/vtadmin-down.sh +../common/scripts/vtadmin-down.sh -./scripts/vtorc-down.sh +../common/scripts/vtorc-down.sh -./scripts/vtgate-down.sh +../common/scripts/vtgate-down.sh for tablet in 100 200 300 400; do if vtctlclient --action_timeout 1s --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)) + uid=$((tablet + i)) printf -v alias '%s-%010d' 'zone1' $uid echo "Shutting down tablet $alias" - CELL=zone1 TABLET_UID=$uid ./scripts/vttablet-down.sh - CELL=zone1 TABLET_UID=$uid ./scripts/mysqlctl-down.sh + CELL=zone1 TABLET_UID=$uid ../common/scripts/vttablet-down.sh + CELL=zone1 TABLET_UID=$uid ../common/scripts/mysqlctl-down.sh done fi done -./scripts/vtctld-down.sh +../common/scripts/vtctld-down.sh if [ "${TOPO}" = "zk2" ]; then - CELL=zone1 ./scripts/zk-down.sh + CELL=zone1 ../common/scripts/zk-down.sh elif [ "${TOPO}" = "k8s" ]; then - CELL=zone1 ./scripts/k3s-down.sh + CELL=zone1 ../common/scripts/k3s-down.sh elif [ "${TOPO}" = "consul" ]; then - CELL=zone1 ./scripts/consul-down.sh + CELL=zone1 ../common/scripts/consul-down.sh else - CELL=zone1 ./scripts/etcd-down.sh + CELL=zone1 ../common/scripts/etcd-down.sh fi # pedantic check: grep for any remaining processes -if [ ! -z "$VTDATAROOT" ]; then - +if [ -n "$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" @@ -63,7 +62,6 @@ if [ ! -z "$VTDATAROOT" ]; then # shellcheck disable=SC2086 rm -r ${VTDATAROOT:?}/* - fi disown -a diff --git a/examples/local/README.md b/examples/local/README.md index 220ffccc1fc..cb846b7c8b1 100644 --- a/examples/local/README.md +++ b/examples/local/README.md @@ -6,7 +6,7 @@ This document contains the summary of the commands to be run. ``` # Setup environment and aliases -source env.sh +source ../common/env.sh # Bring up initial cluster and commerce keyspace ./101_initial_cluster.sh @@ -47,7 +47,7 @@ vtctlclient Reshard -- --tablet_types=primary SwitchTraffic customer.cust2cust # Down shard 0 ./306_down_shard_0.sh -vtctlclient DeleteShard -- --recursive customer/0 +vtctlclient DeleteShard -- --force --recursive customer/0 # Down cluster ./401_teardown.sh diff --git a/examples/local/scripts/etcd-down.sh b/examples/local/scripts/etcd-down.sh deleted file mode 100755 index 018af7432a3..00000000000 --- a/examples/local/scripts/etcd-down.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that stops the etcd servers started by etcd-up.sh. - -source ./env.sh - -echo "Stopping etcd..." -kill -9 `cat $VTDATAROOT/tmp/etcd.pid` diff --git a/examples/local/scripts/mysqlctl-up.sh b/examples/local/scripts/mysqlctl-up.sh deleted file mode 100755 index ae041cf951d..00000000000 --- a/examples/local/scripts/mysqlctl-up.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that creates a single shard vttablet deployment. - -source ./env.sh - -cell=${CELL:-'test'} -uid=$TABLET_UID -mysql_port=$[17000 + $uid] -printf -v alias '%s-%010d' $cell $uid -printf -v tablet_dir 'vt_%010d' $uid - -mkdir -p $VTDATAROOT/backups - -echo "Starting MySQL for tablet $alias..." -action="init" - -if [ -d $VTDATAROOT/$tablet_dir ]; then - echo "Resuming from existing vttablet dir:" - echo " $VTDATAROOT/$tablet_dir" - action='start' -fi - -mysqlctl \ - --log_dir $VTDATAROOT/tmp \ - --tablet_uid $uid \ - --mysql_port $mysql_port \ - $action diff --git a/examples/local/scripts/vtctld-down.sh b/examples/local/scripts/vtctld-down.sh deleted file mode 100755 index d96fa3b927f..00000000000 --- a/examples/local/scripts/vtctld-down.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that stops vtctld. - -source ./env.sh - -echo "Stopping vtctld..." -kill -9 `cat $VTDATAROOT/tmp/vtctld.pid` diff --git a/examples/local/scripts/vtctld-up.sh b/examples/local/scripts/vtctld-up.sh deleted file mode 100755 index 5ab8017424c..00000000000 --- a/examples/local/scripts/vtctld-up.sh +++ /dev/null @@ -1,36 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that starts vtctld. - -source ./env.sh - -cell=${CELL:-'test'} -grpc_port=15999 - -echo "Starting vtctld..." -# shellcheck disable=SC2086 -vtctld \ - $TOPOLOGY_FLAGS \ - --cell $cell \ - --service_map 'grpc-vtctl,grpc-vtctld' \ - --backup_storage_implementation file \ - --file_backup_storage_root $VTDATAROOT/backups \ - --log_dir $VTDATAROOT/tmp \ - --port $vtctld_web_port \ - --grpc_port $grpc_port \ - --pid_file $VTDATAROOT/tmp/vtctld.pid \ - > $VTDATAROOT/tmp/vtctld.out 2>&1 & diff --git a/examples/local/scripts/vtgate-down.sh b/examples/local/scripts/vtgate-down.sh deleted file mode 100755 index 9da0a7179df..00000000000 --- a/examples/local/scripts/vtgate-down.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that stops the instance started by vtgate-up.sh. - -source ./env.sh - -# Stop vtgate. -echo "Stopping vtgate..." -kill `cat $VTDATAROOT/tmp/vtgate.pid` diff --git a/examples/local/scripts/zk-down.sh b/examples/local/scripts/zk-down.sh deleted file mode 100755 index 18dd7933bc9..00000000000 --- a/examples/local/scripts/zk-down.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that stops the ZooKeeper servers started by zk-up.sh. - -source ./env.sh - -# Stop ZooKeeper servers. -echo "Stopping zk servers..." -for zkid in $zkids; do - zkctl -zk.myid $zkid -zk.cfg $zkcfg -log_dir $VTDATAROOT/tmp shutdown -done - diff --git a/examples/local/vtexplain/atomicity_method1.sh b/examples/local/vtexplain/atomicity_method1.sh deleted file mode 100644 index b946ec7434f..00000000000 --- a/examples/local/vtexplain/atomicity_method1.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -set -x -vtexplain -vschema-file vschema.json -schema-file schema.sql -shards 4 -sql 'INSERT /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ INTO t1 (c1) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20);' diff --git a/examples/local/vtexplain/atomicity_method2.sh b/examples/local/vtexplain/atomicity_method2.sh deleted file mode 100644 index 33a09cbfbee..00000000000 --- a/examples/local/vtexplain/atomicity_method2.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -set -x -vtexplain -vschema-file vschema.json -schema-file schema.sql -shards 4 -sql 'SET transaction_mode="single"; INSERT INTO t1 (c1) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20);' diff --git a/examples/local/vtexplain/atomicity_method2_reads.sh b/examples/local/vtexplain/atomicity_method2_reads.sh deleted file mode 100644 index f32732ccfc5..00000000000 --- a/examples/local/vtexplain/atomicity_method2_reads.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -set -x -vtexplain -vschema-file vschema.json -schema-file schema.sql -shards 4 -sql 'SET transaction_mode="single"; BEGIN; SELECT * from t1; COMMIT;' diff --git a/examples/local/vtexplain/atomicity_method2_working.sh b/examples/local/vtexplain/atomicity_method2_working.sh deleted file mode 100644 index f9c84e87a72..00000000000 --- a/examples/local/vtexplain/atomicity_method2_working.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -set -x -vtexplain -vschema-file vschema.json -schema-file schema.sql -shards 4 -sql 'SET transaction_mode="single"; INSERT INTO t1 (c1) values (10),(14),(15),(16);' diff --git a/examples/local/vtexplain/atomicity_method3.sh b/examples/local/vtexplain/atomicity_method3.sh deleted file mode 100644 index 772bae21460..00000000000 --- a/examples/local/vtexplain/atomicity_method3.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -x -# SET transaction_mode="multi" is implied by default -vtexplain -vschema-file vschema.json -schema-file schema.sql -shards 4 -sql 'INSERT INTO t1 (c1) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20);' diff --git a/examples/region_sharding/101_initial_cluster.sh b/examples/region_sharding/101_initial_cluster.sh index 210334cf18f..c2692440189 100755 --- a/examples/region_sharding/101_initial_cluster.sh +++ b/examples/region_sharding/101_initial_cluster.sh @@ -17,46 +17,43 @@ # this script brings up topo server and all the vitess components # required for a single shard deployment. -source ./env.sh +source ../common/env.sh # start topo server if [ "${TOPO}" = "zk2" ]; then - CELL=zone1 ./scripts/zk-up.sh + CELL=zone1 ../common/scripts/zk-up.sh elif [ "${TOPO}" = "k8s" ]; then - CELL=zone1 ./scripts/k3s-up.sh + CELL=zone1 ../common/scripts/k3s-up.sh else - CELL=zone1 ./scripts/etcd-up.sh + CELL=zone1 ../common/scripts/etcd-up.sh fi # start vtctld -CELL=zone1 ./scripts/vtctld-up.sh +CELL=zone1 ../common/scripts/vtctld-up.sh # start unsharded keyspace and tablet -CELL=zone1 TABLET_UID=100 ./scripts/mysqlctl-up.sh -SHARD=0 CELL=zone1 KEYSPACE=main TABLET_UID=100 ./scripts/vttablet-up.sh +CELL=zone1 TABLET_UID=100 ../common/scripts/mysqlctl-up.sh +SHARD=0 CELL=zone1 KEYSPACE=main TABLET_UID=100 ../common/scripts/vttablet-up.sh # set the correct durability policy for the keyspace -vtctldclient --server localhost:15999 SetKeyspaceDurabilityPolicy --durability-policy=none main +vtctldclient --server localhost:15999 SetKeyspaceDurabilityPolicy --durability-policy=none main || fail "Failed to set keyspace durability policy on the main keyspace" # start vtorc -./scripts/vtorc-up.sh +../common/scripts/vtorc-up.sh -# Wait for a primary tablet to be elected in the shard -for _ in $(seq 0 200); do - vtctldclient GetTablets --keyspace main --shard 0 | grep -q "primary" && break - sleep 1 -done; -vtctldclient GetTablets --keyspace main --shard 0 | grep "primary" || (echo "Timed out waiting for primary to be elected in main/0" && exit 1) +# Wait for a primary tablet to be elected in the shard and for it +# to become healthy/sherving. +wait_for_healthy_shard main 0 1 || exit 1 # create the schema -vtctldclient ApplySchema --sql-file create_main_schema.sql main +vtctldclient ApplySchema --sql-file create_main_schema.sql main || fail "Failed to apply schema for the main keyspace" # create the vschema -vtctldclient ApplyVSchema --vschema-file main_vschema_initial.json main +vtctldclient ApplyVSchema --vschema-file main_vschema_initial.json main || fail "Failed to apply vschema for the main keyspace" # start vtgate -CELL=zone1 ./scripts/vtgate-up.sh +CELL=zone1 ../common/scripts/vtgate-up.sh # start vtadmin -./scripts/vtadmin-up.sh +../common/scripts/vtadmin-up.sh diff --git a/examples/region_sharding/201_main_sharded.sh b/examples/region_sharding/201_main_sharded.sh index b8a589c0d49..387f89506db 100755 --- a/examples/region_sharding/201_main_sharded.sh +++ b/examples/region_sharding/201_main_sharded.sh @@ -14,20 +14,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -source ./env.sh +source ../common/env.sh # apply sharding vschema -vtctldclient ApplyVSchema --vschema-file main_vschema_sharded.json main +vtctldclient ApplyVSchema --vschema-file main_vschema_sharded.json main || fail "Failed to apply vschema for the sharded main keyspace" # optional: create the schema needed for lookup vindex #vtctlclient ApplySchema --sql-file create_lookup_schema.sql main # create the lookup vindex -vtctlclient CreateLookupVindex -- --tablet_types=PRIMARY main "$(cat lookup_vindex.json)" +vtctlclient CreateLookupVindex -- --tablet_types=PRIMARY main "$(cat lookup_vindex.json)" || fail "Failed to create lookup vindex in main keyspace" # we have to wait for replication to catch up # Can see on vttablet status page Vreplication that copy is complete sleep 5 -#externalize vindex -vtctlclient ExternalizeVindex main.customer_region_lookup +# externalize vindex +vtctlclient ExternalizeVindex main.customer_region_lookup || fail "Failed to externalize customer_region_lookup vindex in the main keyspace" diff --git a/examples/region_sharding/202_new_tablets.sh b/examples/region_sharding/202_new_tablets.sh index e570ae3b3c2..d9134a6a7a3 100755 --- a/examples/region_sharding/202_new_tablets.sh +++ b/examples/region_sharding/202_new_tablets.sh @@ -14,23 +14,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -source ./env.sh +source ../common/env.sh # start vttablets for new shards. we start only one tablet each (primary) -CELL=zone1 TABLET_UID=200 ./scripts/mysqlctl-up.sh -SHARD=-40 CELL=zone1 KEYSPACE=main TABLET_UID=200 ./scripts/vttablet-up.sh -CELL=zone1 TABLET_UID=300 ./scripts/mysqlctl-up.sh -SHARD=40-80 CELL=zone1 KEYSPACE=main TABLET_UID=300 ./scripts/vttablet-up.sh -CELL=zone1 TABLET_UID=400 ./scripts/mysqlctl-up.sh -SHARD=80-c0 CELL=zone1 KEYSPACE=main TABLET_UID=400 ./scripts/vttablet-up.sh -CELL=zone1 TABLET_UID=500 ./scripts/mysqlctl-up.sh -SHARD=c0- CELL=zone1 KEYSPACE=main TABLET_UID=500 ./scripts/vttablet-up.sh +CELL=zone1 TABLET_UID=200 ../common/scripts/mysqlctl-up.sh +SHARD=-40 CELL=zone1 KEYSPACE=main TABLET_UID=200 ../common/scripts/vttablet-up.sh +CELL=zone1 TABLET_UID=300 ../common/scripts/mysqlctl-up.sh +SHARD=40-80 CELL=zone1 KEYSPACE=main TABLET_UID=300 ../common/scripts/vttablet-up.sh +CELL=zone1 TABLET_UID=400 ../common/scripts/mysqlctl-up.sh +SHARD=80-c0 CELL=zone1 KEYSPACE=main TABLET_UID=400 ../common/scripts/vttablet-up.sh +CELL=zone1 TABLET_UID=500 ../common/scripts/mysqlctl-up.sh +SHARD=c0- CELL=zone1 KEYSPACE=main TABLET_UID=500 ../common/scripts/vttablet-up.sh for shard in "-40" "40-80" "80-c0" "c0-"; do - # Wait for a primary tablet to be elected in the shard - for _ in $(seq 0 200); do - vtctldclient GetTablets --keyspace main --shard $shard | grep -q "primary" && break - sleep 1 - done; - vtctldclient GetTablets --keyspace main --shard $shard | grep "primary" || (echo "Timed out waiting for primary to be elected in main/$shard" && exit 1) + # Wait for all the tablets to be up and registered in the topology server + # and for a primary tablet to be elected in the shard and become healthy/serving. + wait_for_healthy_shard main "${shard}" 1 || exit 1 done; diff --git a/examples/region_sharding/203_reshard.sh b/examples/region_sharding/203_reshard.sh index 0cef1dbc4f9..aaa448a135d 100755 --- a/examples/region_sharding/203_reshard.sh +++ b/examples/region_sharding/203_reshard.sh @@ -14,6 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -source ./env.sh +source ../common/env.sh vtctlclient Reshard -- --source_shards '0' --target_shards '-40,40-80,80-c0,c0-' --tablet_types=PRIMARY Create main.main2regions diff --git a/examples/region_sharding/204_switch_reads.sh b/examples/region_sharding/204_switch_reads.sh index f0e6b7fd6cb..20703938199 100755 --- a/examples/region_sharding/204_switch_reads.sh +++ b/examples/region_sharding/204_switch_reads.sh @@ -16,6 +16,6 @@ # this script migrates traffic for the rdonly and replica tablets -source ./env.sh +source ../common/env.sh vtctlclient Reshard -- --tablet_types=rdonly,replica SwitchTraffic main.main2regions diff --git a/examples/region_sharding/205_switch_writes.sh b/examples/region_sharding/205_switch_writes.sh index d337929852e..ad0d8ee51d2 100755 --- a/examples/region_sharding/205_switch_writes.sh +++ b/examples/region_sharding/205_switch_writes.sh @@ -16,7 +16,7 @@ # this script migrates traffic for the primary tablet -source ./env.sh +source ../common/env.sh vtctlclient Reshard -- --tablet_types=primary SwitchTraffic main.main2regions diff --git a/examples/region_sharding/206_down_shard_0.sh b/examples/region_sharding/206_down_shard_0.sh index d302a071a46..6b46ea34ea0 100755 --- a/examples/region_sharding/206_down_shard_0.sh +++ b/examples/region_sharding/206_down_shard_0.sh @@ -15,7 +15,7 @@ # limitations under the License. # this script brings down the tablets for main/0 keyspace/shard -source ./env.sh +source ../common/env.sh -CELL=zone1 TABLET_UID=100 ./scripts/vttablet-down.sh -CELL=zone1 TABLET_UID=100 ./scripts/mysqlctl-down.sh +CELL=zone1 TABLET_UID=100 ../common/scripts/vttablet-down.sh +CELL=zone1 TABLET_UID=100 ../common/scripts/mysqlctl-down.sh diff --git a/examples/region_sharding/207_delete_shard_0.sh b/examples/region_sharding/207_delete_shard_0.sh index 05f24679226..298afd7b273 100755 --- a/examples/region_sharding/207_delete_shard_0.sh +++ b/examples/region_sharding/207_delete_shard_0.sh @@ -16,6 +16,6 @@ # this script deletes the old shard 0 which has been replaced by 4 shards -source ./env.sh +source ../common/env.sh -vtctldclient DeleteShards --recursive main/0 +vtctldclient DeleteShards --force --recursive main/0 diff --git a/examples/region_sharding/301_teardown.sh b/examples/region_sharding/301_teardown.sh index 310c7f1277b..25f3bb259f2 100755 --- a/examples/region_sharding/301_teardown.sh +++ b/examples/region_sharding/301_teardown.sh @@ -17,37 +17,36 @@ # We should not assume that any of the steps have been executed. # This makes it possible for a user to cleanup at any point. -source ./env.sh +source ../common/env.sh -./scripts/vtadmin-down.sh +../common/scripts/vtadmin-down.sh -./scripts/vtorc-down.sh +../common/scripts/vtorc-down.sh -./scripts/vtgate-down.sh +../common/scripts/vtgate-down.sh for tablet in 100 200 300 400 500; do if vtctlclient --server localhost:15999 GetTablet zone1-$tablet >/dev/null 2>&1; then - printf -v alias '%s-%010d' 'zone1' $uid + printf -v alias '%s-%010d' 'zone1' $tablet echo "Shutting down tablet $alias" - CELL=zone1 TABLET_UID=$tablet ./scripts/vttablet-down.sh - CELL=zone1 TABLET_UID=$tablet ./scripts/mysqlctl-down.sh + CELL=zone1 TABLET_UID=$tablet ../common/scripts/vttablet-down.sh + CELL=zone1 TABLET_UID=$tablet ../common/scripts/mysqlctl-down.sh fi done -./scripts/vtctld-down.sh +../common/scripts/vtctld-down.sh if [ "${TOPO}" = "zk2" ]; then - CELL=zone1 ./scripts/zk-down.sh + CELL=zone1 ../common/scripts/zk-down.sh elif [ "${TOPO}" = "k8s" ]; then - CELL=zone1 ./scripts/k3s-down.sh + CELL=zone1 ../common/scripts/k3s-down.sh else - CELL=zone1 ./scripts/etcd-down.sh + CELL=zone1 ../common/scripts/etcd-down.sh fi # pedantic check: grep for any remaining processes -if [ ! -z "$VTDATAROOT" ]; then - +if [ -n "$VTDATAROOT" ]; then if pgrep -f -l "$VTDATAROOT" >/dev/null; then echo "ERROR: Stale processes detected! It is recommended to manually kill them:" pgrep -f -l "$VTDATAROOT" @@ -57,7 +56,6 @@ if [ ! -z "$VTDATAROOT" ]; then # shellcheck disable=SC2086 rm -r ${VTDATAROOT:?}/* - fi disown -a diff --git a/examples/region_sharding/README.md b/examples/region_sharding/README.md index 8b9ced13999..fcc2e617143 100644 --- a/examples/region_sharding/README.md +++ b/examples/region_sharding/README.md @@ -5,12 +5,8 @@ This document contains the summary of the commands to be run. ``` -# Edit main_vschema_sharded.json and set region_map to full path of countries.json file -# Example: - "region_map": "/home/user/vitess/examples/region_sharding/countries.json", - # setup environment and aliases -source env.sh +source ../common/env.sh # Bring up initial cluster and main keyspace (unsharded) ./101_initial_cluster.sh diff --git a/examples/region_sharding/env.sh b/examples/region_sharding/env.sh deleted file mode 100644 index 54b9c97fff9..00000000000 --- a/examples/region_sharding/env.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -hostname=$(hostname -f) -vtctld_web_port=15000 -export VTDATAROOT="${VTDATAROOT:-${PWD}/vtdataroot}" - -function fail() { - echo "ERROR: $1" - exit 1 -} - -if [[ $EUID -eq 0 ]]; then - fail "This script refuses to be run as root. Please switch to a regular user." -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 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; - -if [ "${TOPO}" = "zk2" ]; then - # Each ZooKeeper server needs a list of all servers in the quorum. - # Since we're running them all locally, we need to give them unique ports. - # In a real deployment, these should be on different machines, and their - # respective hostnames should be given. - zkcfg=(\ - "1@$hostname:28881:38881:21811" \ - "2@$hostname:28882:38882:21812" \ - "3@$hostname:28883:38883:21813" \ - ) - printf -v zkcfg ",%s" "${zkcfg[@]}" - zkcfg=${zkcfg:1} - - zkids='1 2 3' - - # Set topology environment parameters. - 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" - K8S_PORT="8443" - K8S_KUBECONFIG=$VTDATAROOT/tmp/k8s.kubeconfig - # shellcheck disable=SC2034 - TOPOLOGY_FLAGS="--topo_implementation k8s --topo_k8s_kubeconfig ${K8S_KUBECONFIG} --topo_global_server_address ${K8S_ADDR}:${K8S_PORT} --topo_global_root /vitess/global" -else - ETCD_SERVER="localhost:2379" - TOPOLOGY_FLAGS="--topo_implementation etcd2 --topo_global_server_address $ETCD_SERVER --topo_global_root /vitess/global" - - mkdir -p "${VTDATAROOT}/etcd" -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" -alias vtctldclient="command vtctldclient --server localhost:15999" - -# Make sure aliases are expanded in non-interactive shell -shopt -s expand_aliases - diff --git a/examples/region_sharding/main_vschema_sharded.json b/examples/region_sharding/main_vschema_sharded.json index 06d72e58981..ec51afa9ee8 100644 --- a/examples/region_sharding/main_vschema_sharded.json +++ b/examples/region_sharding/main_vschema_sharded.json @@ -4,7 +4,7 @@ "region_vdx": { "type": "region_json", "params": { - "region_map": "/vt/src/vitess.io/vitess/examples/region_sharding/countries.json", + "region_map": "./countries.json", "region_bytes": "1" } } diff --git a/examples/region_sharding/scripts/etcd-up.sh b/examples/region_sharding/scripts/etcd-up.sh deleted file mode 100755 index 9164d32806e..00000000000 --- a/examples/region_sharding/scripts/etcd-up.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that creates a quorum of ZooKeeper servers. - -source ./env.sh - -cell=${CELL:-'test'} -export ETCDCTL_API=2 - -# Check that etcd is not already running -curl "http://${ETCD_SERVER}" > /dev/null 2>&1 && fail "etcd is already running. Exiting." - -etcd --enable-v2=true --data-dir "${VTDATAROOT}/etcd/" --listen-client-urls "http://${ETCD_SERVER}" --advertise-client-urls "http://${ETCD_SERVER}" > "${VTDATAROOT}"/tmp/etcd.out 2>&1 & -PID=$! -echo $PID > "${VTDATAROOT}/tmp/etcd.pid" -sleep 5 - -echo "add /vitess/global" -etcdctl --endpoints "http://${ETCD_SERVER}" mkdir /vitess/global & - -echo "add /vitess/$cell" -etcdctl --endpoints "http://${ETCD_SERVER}" mkdir /vitess/$cell & - -# And also add the CellInfo description for the cell. -# If the node already exists, it's fine, means we used existing data. -echo "add $cell CellInfo" -set +e -# shellcheck disable=SC2086 -vtctl $TOPOLOGY_FLAGS AddCellInfo -- \ - --root /vitess/$cell \ - --server_address "${ETCD_SERVER}" \ - $cell -set -e - -echo "etcd start done..." - - diff --git a/examples/region_sharding/scripts/k3s-down.sh b/examples/region_sharding/scripts/k3s-down.sh deleted file mode 100755 index 590dc604e3e..00000000000 --- a/examples/region_sharding/scripts/k3s-down.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that stops the k3s server started by k3s-up.sh. - -set -e - -# shellcheck source=./env.sh -# shellcheck disable=SC1091 -source ./env.sh - -# Stop K3s server. -echo "Stopping k3s server..." - -pid=`cat $VTDATAROOT/tmp/k3s.pid` -echo "Stopping k3s..." -kill -9 $pid diff --git a/examples/region_sharding/scripts/k3s-up.sh b/examples/region_sharding/scripts/k3s-up.sh deleted file mode 100755 index 286b4d0ad85..00000000000 --- a/examples/region_sharding/scripts/k3s-up.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that creates a Kubernetes api for topo use by running k3s - -set -e -cell=${CELL:-'test'} - -script_root=$(dirname "${BASH_SOURCE[0]}") - -# shellcheck source=./env.sh -# shellcheck disable=SC1091 -source ./env.sh - -case $(uname) in - Linux) ;; - *) echo "WARNING: unsupported platform. K3s only supports running on Linux, the k8s topology is available for local examples."; exit 1;; -esac - -case $(uname -m) in - aarch64) ;; - x86_64) ;; - *) echo "ERROR: unsupported architecture, the k8s topology is not available for local examples."; exit 1;; -esac - -k3s server --disable-agent --data-dir "${VTDATAROOT}/k3s/" --https-listen-port "${K8S_PORT}" --write-kubeconfig "${K8S_KUBECONFIG}" > "${VTDATAROOT}"/tmp/k3s.out 2>&1 & -PID=$! -echo $PID > "${VTDATAROOT}/tmp/k3s.pid" -disown -a -echo "Waiting for k3s server to start" -sleep 15 - -# Use k3s built-in kubectl with custom config -KUBECTL="k3s kubectl --kubeconfig=${K8S_KUBECONFIG}" - -# Create the CRD for vitesstopologynodes -$KUBECTL create -f ../../go/vt/topo/k8stopo/VitessTopoNodes-crd.yaml - -# Add the CellInfo description for the cell -set +e -echo "add $cell CellInfo" -vtctl $TOPOLOGY_FLAGS AddCellInfo -- \ - --root /vitess/$cell \ - $cell -set -e - -echo "k3s start done..." diff --git a/examples/region_sharding/scripts/mysqlctl-down.sh b/examples/region_sharding/scripts/mysqlctl-down.sh deleted file mode 100755 index 37b1d0c729b..00000000000 --- a/examples/region_sharding/scripts/mysqlctl-down.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that stops the mysqld and vttablet instances -# created by vttablet-up.sh - -source ./env.sh - -cell=${CELL:-'test'} -uid=$TABLET_UID -printf -v alias '%s-%010d' $cell $uid -echo "Shutting down MySQL for tablet $alias..." - -mysqlctl --tablet_uid $TABLET_UID shutdown - diff --git a/examples/region_sharding/scripts/vtadmin-down.sh b/examples/region_sharding/scripts/vtadmin-down.sh deleted file mode 100755 index 2a7944d9d5a..00000000000 --- a/examples/region_sharding/scripts/vtadmin-down.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -source ./env.sh - -echo "Stopping vtadmin-web..." -kill -9 "$(cat "$VTDATAROOT/tmp/vtadmin-web.pid")" - -echo "Stopping vtadmin-api..." -kill -9 "$(cat "$VTDATAROOT/tmp/vtadmin-api.pid")" diff --git a/examples/region_sharding/scripts/vtadmin-up.sh b/examples/region_sharding/scripts/vtadmin-up.sh deleted file mode 100755 index 5ee04c9a959..00000000000 --- a/examples/region_sharding/scripts/vtadmin-up.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/bash - -source ./env.sh - -log_dir="${VTDATAROOT}/tmp" -web_dir="../../web/vtadmin" - -vtadmin_api_port=14200 -vtadmin_web_port=14201 - -vtadmin \ - --addr ":${vtadmin_api_port}" \ - --http-origin "http://localhost:${vtadmin_web_port}" \ - --http-tablet-url-tmpl "http://{{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \ - --tracer "opentracing-jaeger" \ - --grpc-tracing \ - --http-tracing \ - --logtostderr \ - --alsologtostderr \ - --rbac \ - --rbac-config="./vtadmin/rbac.yaml" \ - --cluster "id=local,name=local,discovery=staticfile,discovery-staticfile-path=./vtadmin/discovery.json,tablet-fqdn-tmpl={{ .Tablet.Hostname }}:15{{ .Tablet.Alias.Uid }}" \ - > "${log_dir}/vtadmin-api.out" 2>&1 & - -vtadmin_api_pid=$! -echo ${vtadmin_api_pid} > "${log_dir}/vtadmin-api.pid" - -echo "\ -vtadmin-api is running! - - API: http://localhost:${vtadmin_api_port} - - Logs: ${log_dir}/vtadmin-api.out - - PID: ${vtadmin_api_pid} -" - -# As a TODO, it'd be nice to make the assumption that vtadmin-web is already -# installed and built (since we assume that `make` has already been run for -# other Vitess components.) -npm --prefix $web_dir --silent install - -REACT_APP_VTADMIN_API_ADDRESS="http://localhost:${vtadmin_api_port}" \ - REACT_APP_ENABLE_EXPERIMENTAL_TABLET_DEBUG_VARS="true" \ - npm run --prefix $web_dir build - -"${web_dir}/node_modules/.bin/serve" --no-clipboard -l $vtadmin_web_port -s "${web_dir}/build" \ - > "${log_dir}/vtadmin-web.out" 2>&1 & - -vtadmin_web_pid=$! -echo ${vtadmin_web_pid} > "${log_dir}/vtadmin-web.pid" - -echo "\ -vtadmin-web is running! - - Browser: http://localhost:${vtadmin_web_port} - - Logs: ${log_dir}/vtadmin-web.out - - PID: ${vtadmin_web_pid} -" diff --git a/examples/region_sharding/scripts/vtgate-up.sh b/examples/region_sharding/scripts/vtgate-up.sh deleted file mode 100755 index cb33e27839b..00000000000 --- a/examples/region_sharding/scripts/vtgate-up.sh +++ /dev/null @@ -1,57 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that starts a single vtgate. - -source ./env.sh - -cell=${CELL:-'test'} -web_port=15001 -grpc_port=15991 -mysql_server_port=15306 -mysql_server_socket_path="/tmp/mysql.sock" - -# Start vtgate. -# shellcheck disable=SC2086 -vtgate \ - $TOPOLOGY_FLAGS \ - --log_dir $VTDATAROOT/tmp \ - --log_queries_to_file $VTDATAROOT/tmp/vtgate_querylog.txt \ - --port $web_port \ - --grpc_port $grpc_port \ - --mysql_server_port $mysql_server_port \ - --mysql_server_socket_path $mysql_server_socket_path \ - --cell $cell \ - --cells_to_watch $cell \ - --tablet_types_to_wait PRIMARY,REPLICA \ - --service_map 'grpc-vtgateservice' \ - --pid_file $VTDATAROOT/tmp/vtgate.pid \ - --mysql_auth_server_impl none \ - > $VTDATAROOT/tmp/vtgate.out 2>&1 & - -# Block waiting for vtgate to be listening -# Not the same as healthy - -echo "Waiting for vtgate to be up..." -while true; do - curl -I "http://$hostname:$web_port/debug/status" >/dev/null 2>&1 && break - sleep 0.1 -done; -echo "vtgate is up!" - -echo "Access vtgate at http://$hostname:$web_port/debug/status" - -disown -a diff --git a/examples/region_sharding/scripts/vtorc-down.sh b/examples/region_sharding/scripts/vtorc-down.sh deleted file mode 100755 index 2fdfc1491ce..00000000000 --- a/examples/region_sharding/scripts/vtorc-down.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -source ./env.sh - -echo "Stopping vtorc." -kill -9 "$(cat "$VTDATAROOT/tmp/vtorc.pid")" - diff --git a/examples/region_sharding/scripts/vtorc-up.sh b/examples/region_sharding/scripts/vtorc-up.sh deleted file mode 100755 index f5a0d75dbba..00000000000 --- a/examples/region_sharding/scripts/vtorc-up.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -source ./env.sh - -log_dir="${VTDATAROOT}/tmp" -port=16000 - -vtorc \ - $TOPOLOGY_FLAGS \ - --logtostderr \ - --alsologtostderr \ - --config="./vtorc/config.json" \ - --port $port \ - > "${log_dir}/vtorc.out" 2>&1 & - -vtorc_pid=$! -echo ${vtorc_pid} > "${log_dir}/vtorc.pid" - -echo "\ -vtorc is running! - - UI: http://localhost:${port} - - Logs: ${log_dir}/vtorc.out - - PID: ${vtorc_pid} -" diff --git a/examples/region_sharding/scripts/vttablet-down.sh b/examples/region_sharding/scripts/vttablet-down.sh deleted file mode 100755 index 47b881b9793..00000000000 --- a/examples/region_sharding/scripts/vttablet-down.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that stops the mysqld and vttablet instances -# created by vttablet-up.sh - -source ./env.sh - -printf -v tablet_dir 'vt_%010d' $TABLET_UID -pid=`cat $VTDATAROOT/$tablet_dir/vttablet.pid` - -kill $pid - -# Wait for vttablet to die. -while ps -p $pid > /dev/null; do sleep 1; done - - diff --git a/examples/region_sharding/scripts/vttablet-up.sh b/examples/region_sharding/scripts/vttablet-up.sh deleted file mode 100755 index 5ecc6657afc..00000000000 --- a/examples/region_sharding/scripts/vttablet-up.sh +++ /dev/null @@ -1,69 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -source ./env.sh - -cell=${CELL:-'test'} -keyspace=${KEYSPACE:-'test_keyspace'} -shard=${SHARD:-'0'} -uid=$TABLET_UID -mysql_port=$[17000 + $uid] -port=$[15000 + $uid] -grpc_port=$[16000 + $uid] -printf -v alias '%s-%010d' $cell $uid -printf -v tablet_dir 'vt_%010d' $uid -tablet_hostname='' -printf -v tablet_logfile 'vttablet_%010d_querylog.txt' $uid - -tablet_type=replica -if [[ "${uid: -1}" -gt 1 ]]; then - tablet_type=rdonly -fi - -echo "Starting vttablet for $alias..." -# shellcheck disable=SC2086 -vttablet \ - $TOPOLOGY_FLAGS \ - --log_dir $VTDATAROOT/tmp \ - --log_queries_to_file $VTDATAROOT/tmp/$tablet_logfile \ - --tablet-path $alias \ - --tablet_hostname "$tablet_hostname" \ - --init_keyspace $keyspace \ - --init_shard $shard \ - --init_tablet_type $tablet_type \ - --health_check_interval 5s \ - --enable_replication_reporter \ - --backup_storage_implementation file \ - --file_backup_storage_root $VTDATAROOT/backups \ - --restore_from_backup \ - --port $port \ - --grpc_port $grpc_port \ - --service_map 'grpc-queryservice,grpc-tabletmanager,grpc-updatestream' \ - --pid_file $VTDATAROOT/$tablet_dir/vttablet.pid \ - --vtctld_addr http://$hostname:$vtctld_web_port/ \ - --disable_active_reparents \ - > $VTDATAROOT/$tablet_dir/vttablet.out 2>&1 & - -# Block waiting for the tablet to be listening -# Not the same as healthy - -for i in $(seq 0 300); do - curl -I "http://$hostname:$port/debug/status" >/dev/null 2>&1 && break - sleep 0.1 -done - -# check one last time -curl -I "http://$hostname:$port/debug/status" || fail "tablet could not be started!" diff --git a/examples/region_sharding/scripts/zk-up.sh b/examples/region_sharding/scripts/zk-up.sh deleted file mode 100755 index 0667d806838..00000000000 --- a/examples/region_sharding/scripts/zk-up.sh +++ /dev/null @@ -1,62 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that creates a quorum of ZooKeeper servers. - -source ./env.sh - -cell=${CELL:-'test'} - -# Start ZooKeeper servers. -# The "zkctl init" command won't return until the server is able to contact its -# peers, so we need to start them all in the background and then wait for them. -echo "Starting zk servers..." -for zkid in $zkids; do - action='init' - printf -v zkdir 'zk_%03d' $zkid - if [ -f $VTDATAROOT/$zkdir/myid ]; then - echo "Resuming from existing ZK data dir:" - echo " $VTDATAROOT/$zkdir" - action='start' - fi - zkctl -zk.myid $zkid -zk.cfg $zkcfg -log_dir $VTDATAROOT/tmp $action \ - > $VTDATAROOT/tmp/zkctl_$zkid.out 2>&1 & - pids[$zkid]=$! -done - -# Wait for all the zkctl commands to return. -echo "Waiting for zk servers to be ready..." - -for zkid in $zkids; do - if ! wait ${pids[$zkid]}; then - echo "ZK server number $zkid failed to start. See log:" - echo " $VTDATAROOT/tmp/zkctl_$zkid.out" - fi -done - -echo "Started zk servers." - -# Add the CellInfo description for the $CELL cell. -# If the node already exists, it's fine, means we used existing data. -set +e -# shellcheck disable=SC2086 -vtctl $TOPOLOGY_FLAGS AddCellInfo -- \ - --root /vitess/$cell \ - --server_address $ZK_SERVER \ - $cell -set -e - -echo "Configured zk servers." diff --git a/examples/region_sharding/topo-etcd2.sh b/examples/region_sharding/topo-etcd2.sh deleted file mode 100644 index c61543a806c..00000000000 --- a/examples/region_sharding/topo-etcd2.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that creates a single shard vttablet deployment. - -export TOPO='etcd2' - - diff --git a/examples/region_sharding/topo-k8s.sh b/examples/region_sharding/topo-k8s.sh deleted file mode 100644 index 92e14ba4d69..00000000000 --- a/examples/region_sharding/topo-k8s.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that creates a single shard vttablet deployment. - -export TOPO='k8s' - - diff --git a/examples/region_sharding/topo-zk2.sh b/examples/region_sharding/topo-zk2.sh deleted file mode 100644 index 29380949d8f..00000000000 --- a/examples/region_sharding/topo-zk2.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/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. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This is an example script that creates a single shard vttablet deployment. - -export TOPO='zk2' - - diff --git a/examples/region_sharding/vtadmin/discovery.json b/examples/region_sharding/vtadmin/discovery.json deleted file mode 100644 index 92e20fb40d8..00000000000 --- a/examples/region_sharding/vtadmin/discovery.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "vtctlds": [ - { - "host": { - "fqdn": "localhost:15000", - "hostname": "localhost:15999" - } - } - ], - "vtgates": [ - { - "host": { - "fqdn": "localhost:15001", - "hostname": "localhost:15991" - } - } - ] -} diff --git a/examples/region_sharding/vtadmin/rbac.yaml b/examples/region_sharding/vtadmin/rbac.yaml deleted file mode 100644 index a2e665e4d8d..00000000000 --- a/examples/region_sharding/vtadmin/rbac.yaml +++ /dev/null @@ -1,5 +0,0 @@ -rules: - - resource: "*" - actions: ["*"] - subjects: ["*"] - clusters: ["*"] diff --git a/examples/region_sharding/vtorc/config.json b/examples/region_sharding/vtorc/config.json deleted file mode 100644 index e1f27ee5762..00000000000 --- a/examples/region_sharding/vtorc/config.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "MySQLTopologyUser": "orc_client_user", - "MySQLTopologyPassword": "orc_client_user_password", - "MySQLReplicaUser": "vt_repl", - "MySQLReplicaPassword": "", - "RecoveryPeriodBlockSeconds": 1, - "InstancePollSeconds": 1 -} \ No newline at end of file diff --git a/examples/vtexplain/atomicity_method1.sh b/examples/vtexplain/atomicity_method1.sh new file mode 100755 index 00000000000..f4e2a300f0e --- /dev/null +++ b/examples/vtexplain/atomicity_method1.sh @@ -0,0 +1,3 @@ +#!/bin/bash +set -x +vtexplain --vschema-file atomicity_vschema.json --schema-file atomicity_schema.sql --shards 4 --sql 'INSERT /*vt+ MULTI_SHARD_AUTOCOMMIT=1 */ INTO t1 (c1) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20);' diff --git a/examples/vtexplain/atomicity_method2.sh b/examples/vtexplain/atomicity_method2.sh new file mode 100755 index 00000000000..061479ecae9 --- /dev/null +++ b/examples/vtexplain/atomicity_method2.sh @@ -0,0 +1,3 @@ +#!/bin/bash +set -x +vtexplain --vschema-file atomicity_vschema.json --schema-file atomicity_schema.sql --shards 4 --sql 'SET transaction_mode="single"; INSERT INTO t1 (c1) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20);' diff --git a/examples/vtexplain/atomicity_method2_reads.sh b/examples/vtexplain/atomicity_method2_reads.sh new file mode 100755 index 00000000000..e1b383d1ef5 --- /dev/null +++ b/examples/vtexplain/atomicity_method2_reads.sh @@ -0,0 +1,3 @@ +#!/bin/bash +set -x +vtexplain --vschema-file atomicity_vschema.json --schema-file atomicity_schema.sql --shards 4 --sql 'SET transaction_mode="single"; BEGIN; SELECT * from t1; COMMIT;' diff --git a/examples/vtexplain/atomicity_method2_working.sh b/examples/vtexplain/atomicity_method2_working.sh new file mode 100755 index 00000000000..0ba844fe08f --- /dev/null +++ b/examples/vtexplain/atomicity_method2_working.sh @@ -0,0 +1,3 @@ +#!/bin/bash +set -x +vtexplain --vschema-file atomicity_vschema.json --schema-file atomicity_schema.sql --shards 4 --sql 'SET transaction_mode="single"; INSERT INTO t1 (c1) values (10),(14),(15),(16);' diff --git a/examples/vtexplain/atomicity_method3.sh b/examples/vtexplain/atomicity_method3.sh new file mode 100755 index 00000000000..e3c013b5a8d --- /dev/null +++ b/examples/vtexplain/atomicity_method3.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -x +# SET transaction_mode="multi" is implied by default +vtexplain --vschema-file atomicity_vschema.json --schema-file atomicity_schema.sql --shards 4 --sql 'INSERT INTO t1 (c1) values (1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20);' diff --git a/examples/local/vtexplain/atomicity_schema.sql b/examples/vtexplain/atomicity_schema.sql similarity index 100% rename from examples/local/vtexplain/atomicity_schema.sql rename to examples/vtexplain/atomicity_schema.sql diff --git a/examples/local/vtexplain/atomicity_vschema.json b/examples/vtexplain/atomicity_vschema.json similarity index 100% rename from examples/local/vtexplain/atomicity_vschema.json rename to examples/vtexplain/atomicity_vschema.json diff --git a/test/client_test.sh b/test/client_test.sh index 2a467cc62f1..4bd76286863 100755 --- a/test/client_test.sh +++ b/test/client_test.sh @@ -20,22 +20,22 @@ source build.env set -xe -cd "$VTROOT/examples/local" +cd "$VTROOT/examples/common/scripts" -CELL=test ./scripts/etcd-up.sh -CELL=test ./scripts/vtctld-up.sh +CELL=test ./etcd-up.sh +CELL=test ./vtctld-up.sh for i in 100 101 102; do - CELL=test TABLET_UID=$i ./scripts/mysqlctl-up.sh - CELL=test KEYSPACE=test_keyspace TABLET_UID=$i ./scripts/vttablet-up.sh + CELL=test TABLET_UID=$i ./mysqlctl-up.sh + CELL=test KEYSPACE=test_keyspace TABLET_UID=$i ./vttablet-up.sh done vtctlclient --server localhost:15999 InitShardPrimary -- --force test_keyspace/0 test-100 -vtctlclient --server localhost:15999 ApplySchema -- --sql-file create_test_table.sql test_keyspace +vtctlclient --server localhost:15999 ApplySchema -- --sql-file ../../local/create_test_table.sql test_keyspace vtctlclient --server localhost:15999 RebuildVSchemaGraph -CELL=test ./scripts/vtgate-up.sh +CELL=test ./vtgate-up.sh echo "Run Go client script..." go run $VTROOT/test/client/client.go --server=localhost:15991 @@ -48,13 +48,13 @@ $VTROOT/test/client_jdbc.sh # Clean up -./scripts/vtgate-down.sh +./vtgate-down.sh for i in 100 101 102; do - CELL=test TABLET_UID=$i ./scripts/vttablet-down.sh - CELL=test TABLET_UID=$i ./scripts/mysqlctl-down.sh + CELL=test TABLET_UID=$i ./vttablet-down.sh + CELL=test TABLET_UID=$i ./mysqlctl-down.sh done -./scripts/vtctld-down.sh -CELL=test ./scripts/etcd-down.sh +./vtctld-down.sh +CELL=test ./etcd-down.sh diff --git a/test/local_example.sh b/test/local_example.sh index b1954fca517..e71855f7960 100755 --- a/test/local_example.sh +++ b/test/local_example.sh @@ -20,12 +20,12 @@ source build.env -set -xe +set -xeo pipefail 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 +source ../common/env.sh # Required so that "mysql" works from alias ./101_initial_cluster.sh @@ -38,25 +38,31 @@ mysql --table < ../common/select_commerce_data.sql for shard in "customer/0"; do while true; do - mysql "$shard" -e 'show tables' && break || echo "waiting for shard: $shard!" + if $(mysql "$shard" -e 'show tables' &>/dev/null); then + break + fi + echo -e "waiting for shard: $shard ..." sleep 1 - done; -done; + done +done ./202_move_tables.sh sleep 3 # required for now -exit + ./203_switch_reads.sh ./204_switch_writes.sh mysql --table < ../common/select_customer0_data.sql -# Expected to fail! -mysql --table < ../common/select_commerce_data.sql || echo "DenyList working as expected" -./205_clean_commerce.sh -# Expected to fail! -mysql --table < ../common/select_commerce_data.sql || echo "Tables missing as expected" +# We expect this to fail due to the denied tables +# rules in place. +# For some reason this succeeds... +# $(mysql --table < ../common/select_commerce_data.sql &>/dev/null || true) + +./205_clean_commerce.sh +# We expect this to fail as the keyspace is now gone. +$(mysql --table < ../common/select_commerce_data.sql &>/dev/null || true) ./301_customer_sharded.sh ./302_new_shards.sh @@ -65,16 +71,17 @@ mysql --table < ../common/select_commerce_data.sql || echo "Tables missing as ex # TODO: Eliminate this race in the examples' scripts for shard in "customer/-80" "customer/80-"; do while true; do - mysql "$shard" -e 'show tables' && break || echo "waiting for shard: $shard!" + if $(mysql "$shard" -e 'show tables' &>/dev/null); then + break + fi + echo -e "waiting for shard: $shard ..." sleep 1 - done; -done; + done +done ./303_reshard.sh - sleep 3 # TODO: Required for now! - ./304_switch_reads.sh ./305_switch_writes.sh diff --git a/test/region_example.sh b/test/region_example.sh index 785aea5d477..8ef45f58a6d 100755 --- a/test/region_example.sh +++ b/test/region_example.sh @@ -20,12 +20,12 @@ source build.env -set -xe +set -xeo pipefail cd "$VTROOT/examples/region_sharding" unset VTROOT # ensure that the examples can run without VTROOT now. -source ./env.sh # Required so that "mysql" works from alias +source ../common/env.sh # Required so that "mysql" works from alias ./101_initial_cluster.sh