vitess.io/vitess@v0.16.2/examples/backups/restart_tablets.sh (about)

     1  #!/bin/bash
     2  
     3  # Copyright 2022 The Vitess Authors.
     4  #
     5  # Licensed under the Apache License, Version 2.0 (the "License");
     6  # you may not use this file except in compliance with the License.
     7  # You may obtain a copy of the License at
     8  #
     9  #     http://www.apache.org/licenses/LICENSE-2.0
    10  #
    11  # Unless required by applicable law or agreed to in writing, software
    12  # distributed under the License is distributed on an "AS IS" BASIS,
    13  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  # See the License for the specific language governing permissions and
    15  # limitations under the License.
    16  
    17  # this script brings up new tablets for the two new shards that we will
    18  # be creating in the customer keyspace and copies the schema
    19  
    20  source ../common/env.sh
    21  
    22  for i in 100 101 102; do
    23    CELL=zone1 TABLET_UID=$i ../common/scripts/mysqlctl-up.sh
    24    CELL=zone1 KEYSPACE=commerce TABLET_UID=$i ../common/scripts/vttablet-up.sh
    25  done
    26  
    27  for i in 200 201 202; do
    28    CELL=zone1 TABLET_UID=$i ../common/scripts/mysqlctl-up.sh
    29    SHARD=-80 CELL=zone1 KEYSPACE=customer TABLET_UID=$i ../common/scripts/vttablet-up.sh
    30  done
    31  
    32  for i in 300 301 302; do
    33    CELL=zone1 TABLET_UID=$i ../common/scripts/mysqlctl-up.sh
    34    SHARD=80- CELL=zone1 KEYSPACE=customer TABLET_UID=$i ../common/scripts/vttablet-up.sh
    35  done
    36  sleep 5
    37  
    38  # Wait for all the replica tablets to be in the serving state before initiating
    39  # InitShardPrimary. This is essential, since we want the RESTORE phase to be
    40  # complete before we start InitShardPrimary, otherwise we end up reading the
    41  # tablet type to RESTORE and do not set semi-sync, which leads to the primary
    42  # hanging on writes.
    43  totalTime=600
    44  for i in 101 201 301; do
    45    while [ $totalTime -gt 0 ]; do
    46      status=$(curl "http://$hostname:15$i/debug/status_details")
    47      echo "$status" | grep "REPLICA: Serving" && break
    48      totalTime=$((totalTime-1))
    49      sleep 0.1
    50    done
    51  done
    52  
    53  # Check that all the replica tablets have reached REPLICA: Serving state
    54  for i in 101 201 301; do
    55    status=$(curl "http://$hostname:15$i/debug/status_details")
    56    echo "$status" | grep "REPLICA: Serving" && continue
    57    echo "tablet-$i did not reach REPLICA: Serving state. Exiting due to failure."
    58    exit 1
    59  done
    60  
    61  vtctldclient InitShardPrimary --force commerce/0 zone1-100
    62  vtctldclient InitShardPrimary --force customer/-80 zone1-200
    63  vtctldclient InitShardPrimary --force customer/80- zone1-300