Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes vttestserver to work with sharded keyspaces #7617

Merged
merged 3 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docker/vttestserver/Dockerfile.mysql57
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ COPY --from=builder --chown=vitess:vitess /vt/install /vt
VOLUME /vt/vtdataroot
USER vitess

CMD /vt/bin/vttestserver -port $PORT -keyspaces $KEYSPACES -num_shards $NUM_SHARDS -mysql_bind_host ${MYSQL_BIND_HOST:-127.0.0.1} -mysql_server_version ${MYSQL_SERVER_VERSION:-5.7.9-vitess}
COPY docker/vttestserver/setup_vschema_folder.sh /vt/setup_vschema_folder.sh
COPY docker/vttestserver/run.sh /vt/run.sh

CMD /vt/run.sh "5.7.9-vitess"
5 changes: 4 additions & 1 deletion docker/vttestserver/Dockerfile.mysql80
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,7 @@ COPY --from=builder --chown=vitess:vitess /vt/install /vt
VOLUME /vt/vtdataroot
USER vitess

CMD /vt/bin/vttestserver -port $PORT -keyspaces $KEYSPACES -num_shards $NUM_SHARDS -mysql_bind_host ${MYSQL_BIND_HOST:-127.0.0.1} -mysql_server_version ${MYSQL_SERVER_VERSION:-8.0.21-vitess}
COPY docker/vttestserver/setup_vschema_folder.sh /vt/setup_vschema_folder.sh
COPY docker/vttestserver/run.sh /vt/run.sh

CMD /vt/run.sh "8.0.21-vitess"
20 changes: 20 additions & 0 deletions docker/vttestserver/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Copyright 2021 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.

# Setup the Vschema Folder
/vt/setup_vschema_folder.sh "$KEYSPACES" "$NUM_SHARDS"
# Run the vttestserver binary
/vt/bin/vttestserver -port "$PORT" -keyspaces "$KEYSPACES" -num_shards "$NUM_SHARDS" -mysql_bind_host "${MYSQL_BIND_HOST:-127.0.0.1}" -mysql_server_version "${MYSQL_SERVER_VERSION:-$1}" -vschema_ddl_authorized_users=% -schema_dir="/vt/schema/"
59 changes: 59 additions & 0 deletions docker/vttestserver/setup_vschema_folder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

# Copyright 2021 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.

# getLength gets the number of elements in a comma separated string
function getLength() {
COUNT=0
for _ in ${1//,/ }
do
((COUNT++))
done
echo "$COUNT"
}

# The first argument to the file is a comma separated list of keyspaces and the second argument is the comma separated list of number of shards.

KEYSPACES="$1"
NUM_SHARDS="$2"

COUNT_KEYSPACES=$(getLength "$KEYSPACES")
COUNT_NUM_SHARDS=$(getLength "$NUM_SHARDS")

# Incase the number of keyspaces and num_shards do not match, throw an error
if [ "$COUNT_KEYSPACES" != "$COUNT_NUM_SHARDS" ]; then
echo "Incompatible list of keyspaces and number of shards"
exit 1
fi

# Convert the strings to lists
read -ra KEYSPACES_LIST <<<"${KEYSPACES//,/ }"
read -ra NUM_SHARDS_LIST <<<"${NUM_SHARDS//,/ }"

# create the main schema directory
mkdir /vt/schema/

i=0;
for keyspace in "${KEYSPACES_LIST[@]}";
do
# create a directory for each keyspace
mkdir "/vt/schema/$keyspace"
num_shard=${NUM_SHARDS_LIST[$i]}
# Create a vschema.json file only if the number of shards are more than 1
if [[ $num_shard -gt "1" ]]; then
printf "{\n\t\"sharded\": true\n}" > "/vt/schema/$keyspace/vschema.json"
fi
((i++))
done