Skip to content

Commit

Permalink
Vtctldclient MoveTables (#13015)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord authored Jul 25, 2023
1 parent d43ada1 commit 96e1932
Show file tree
Hide file tree
Showing 93 changed files with 97,413 additions and 69,235 deletions.
2 changes: 1 addition & 1 deletion examples/common/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fi

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

Expand Down
29 changes: 29 additions & 0 deletions examples/common/lib/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,35 @@ function wait_for_healthy_shard() {
wait_for_shard_vreplication_engine "${keyspace}" "${shard}"
}

# Wait for a workflow to reach the running state. Example:
# wait_for_workflow_running customer customer2customer
function wait_for_workflow_running() {
if [[ -z ${1} || -z ${2} ]]; then
fail "A keyspace and workflow must be specified when waiting for a workflow to reach the running state"
fi

local keyspace=${1}
local workflow=${2}
local wait_secs=90
local result=""

echo "Waiting for the ${workflow} workflow in the ${keyspace} keyspace to finish the copy phase..."

for _ in $(seq 1 ${wait_secs}); do
result=$(vtctldclient Workflow --keyspace="${keyspace}" show --workflow="${workflow}" 2>/dev/null | grep "Copy phase completed")
if [[ ${result} != "" ]]; then
break
fi
sleep 1
done;

if [[ ${result} == "" ]]; then
fail "Timed out after ${wait_secs} seconds waiting for the ${workflow} workflow in the ${keyspace} keyspace to reach the running state"
fi

echo "The ${workflow} workflow in the ${keyspace} keyspace is now running. $(sed -rn 's/.*"(Copy phase.*)".*/\1/p' <<< "${result}")."
}

# Stop the specified binary name using the provided PID file.
# Example:
# stop_process "vtadmin-web" "$VTDATAROOT/tmp/vtadmin-web.pid"
Expand Down
5 changes: 4 additions & 1 deletion examples/local/202_move_tables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@

source ../common/env.sh

vtctlclient MoveTables -- --source commerce --tables 'customer,corder' Create customer.commerce2customer
vtctldclient MoveTables --workflow commerce2customer --target-keyspace customer create --source-keyspace commerce --tables "customer,corder"

# Wait for the workflow to reach the running state.
wait_for_workflow_running customer commerce2customer
2 changes: 1 addition & 1 deletion examples/local/203_switch_reads.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

source ../common/env.sh

vtctlclient MoveTables -- --tablet_types=rdonly,replica SwitchTraffic customer.commerce2customer
vtctldclient MoveTables --workflow commerce2customer --target-keyspace customer switchtraffic --tablet-types "rdonly,replica"
2 changes: 1 addition & 1 deletion examples/local/204_switch_writes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

source ../common/env.sh

vtctlclient MoveTables -- --tablet_types=primary SwitchTraffic customer.commerce2customer
vtctldclient MoveTables --workflow commerce2customer --target-keyspace customer switchtraffic --tablet-types primary
3 changes: 1 addition & 2 deletions examples/local/205_clean_commerce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@

source ../common/env.sh

vtctlclient MoveTables Complete customer.commerce2customer

vtctldclient MoveTables --workflow commerce2customer --target-keyspace customer complete
2 changes: 1 addition & 1 deletion go/cmd/internal/docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func restructure(rootDir string, dir string, name string, commands []*cobra.Comm
}

func newParentLinkSedCommand(parent string, file string) *exec.Cmd {
return exec.Command("sed", "-i ''", "-e", fmt.Sprintf("s:(./%s/):(../):", parent), file)
return exec.Command("sed", "-i", "", "-e", fmt.Sprintf("s:(./%s/):(../):i", parent), file)
}

func recursivelyDisableAutoGenTags(root *cobra.Command) {
Expand Down
22 changes: 22 additions & 0 deletions go/cmd/vtctldclient/cli/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,25 @@ func MarshalJSON(obj any) ([]byte, error) {
return data, nil
}
}

// MarshalJSONCompact works the same as MarshalJSON but elides zero value elements.
func MarshalJSONCompact(obj any) ([]byte, error) {
switch obj := obj.(type) {
case proto.Message:
m := protojson.MarshalOptions{
Multiline: true,
Indent: " ",
UseEnumNumbers: true,
UseProtoNames: true,
EmitUnpopulated: false, // elide zero value elements
}
return m.Marshal(obj)
default:
data, err := json.MarshalIndent(obj, "", " ")
if err != nil {
return nil, fmt.Errorf("json.Marshal = %v", err)
}

return data, nil
}
}
Loading

0 comments on commit 96e1932

Please sign in to comment.