зеркало из https://github.com/github/vitess-gh.git
region_sharding: working resharding example
Signed-off-by: deepthi <deepthi@planetscale.com>
This commit is contained in:
Родитель
2130a0e759
Коммит
1653579180
|
@ -51,5 +51,5 @@ jobs:
|
|||
fi
|
||||
# Make sure that testing is entirely non-reliant on config
|
||||
mv config config-moved
|
||||
sed -i 's/user\/my-vitess/runner\/work\/vitess\/vitess/g' examples/region_sharding/main_vschema.json #set correct path to countries.json
|
||||
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 -- test/region_example.sh
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# this script brings up zookeeper and all the vitess components
|
||||
# this script brings up topo server and all the vitess components
|
||||
# required for a single shard deployment.
|
||||
|
||||
source ./env.sh
|
||||
|
@ -31,27 +31,17 @@ fi
|
|||
# start vtctld
|
||||
CELL=zone1 ./scripts/vtctld-up.sh
|
||||
|
||||
# start vttablets for main keyspace. we start only one tablet each (master)
|
||||
# start unsharded keyspace and tablet
|
||||
CELL=zone1 TABLET_UID=100 ./scripts/mysqlctl-up.sh
|
||||
SHARD=-40 CELL=zone1 KEYSPACE=main TABLET_UID=100 ./scripts/vttablet-up.sh
|
||||
CELL=zone1 TABLET_UID=200 ./scripts/mysqlctl-up.sh
|
||||
SHARD=40-80 CELL=zone1 KEYSPACE=main TABLET_UID=200 ./scripts/vttablet-up.sh
|
||||
CELL=zone1 TABLET_UID=300 ./scripts/mysqlctl-up.sh
|
||||
SHARD=80-c0 CELL=zone1 KEYSPACE=main TABLET_UID=300 ./scripts/vttablet-up.sh
|
||||
CELL=zone1 TABLET_UID=400 ./scripts/mysqlctl-up.sh
|
||||
SHARD=c0- CELL=zone1 KEYSPACE=main TABLET_UID=400 ./scripts/vttablet-up.sh
|
||||
SHARD=0 CELL=zone1 KEYSPACE=main TABLET_UID=100 ./scripts/vttablet-up.sh
|
||||
|
||||
# set master
|
||||
vtctlclient InitShardMaster -force main/-40 zone1-100
|
||||
vtctlclient InitShardMaster -force main/40-80 zone1-200
|
||||
vtctlclient InitShardMaster -force main/80-c0 zone1-300
|
||||
vtctlclient InitShardMaster -force main/c0- zone1-400
|
||||
vtctlclient InitShardMaster -force main/0 zone1-100
|
||||
|
||||
# create the schema
|
||||
vtctlclient ApplySchema -sql-file create_main_schema.sql main
|
||||
|
||||
# create the vschema
|
||||
vtctlclient ApplyVSchema -vschema_file main_vschema.json main
|
||||
vtctlclient ApplyVSchema -vschema_file main_vschema_initial.json main
|
||||
|
||||
# start vtgate
|
||||
CELL=zone1 ./scripts/vtgate-up.sh
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2020 The Vitess Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
source ./env.sh
|
||||
|
||||
# apply sharding vschema
|
||||
vtctlclient ApplyVSchema -vschema_file main_vschema_sharded.json main
|
||||
|
||||
# create the schema needed for lookup vindex
|
||||
vtctlclient ApplySchema -sql-file create_lookup_schema.sql main
|
||||
|
||||
# create the lookup vindex
|
||||
vtctlclient CreateLookupVindex -tablet_types=MASTER main "$(cat lookup_vindex.json)"
|
||||
|
||||
# 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
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2020 The Vitess Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
source ./env.sh
|
||||
|
||||
# start vttablets for new shards. we start only one tablet each (master)
|
||||
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
|
||||
|
||||
# set master
|
||||
vtctlclient InitShardMaster -force main/-40 zone1-200
|
||||
vtctlclient InitShardMaster -force main/40-80 zone1-300
|
||||
vtctlclient InitShardMaster -force main/80-c0 zone1-400
|
||||
vtctlclient InitShardMaster -force main/c0- zone1-500
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2020 The Vitess Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
source ./env.sh
|
||||
|
||||
vtctlclient Reshard -tablet_types=MASTER main.main2regions '0' '-40,40-80,80-c0,c0-'
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2020 The Vitess Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# this script migrates traffic for the rdonly and replica tablets
|
||||
|
||||
source ./env.sh
|
||||
|
||||
vtctlclient SwitchReads -tablet_type=rdonly main.main2regions
|
||||
vtctlclient SwitchReads -tablet_type=replica main.main2regions
|
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Copyright 2020 The Vitess Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
# this script migrates traffic for the master tablet
|
||||
|
||||
source ./env.sh
|
||||
|
||||
vtctlclient SwitchWrites main.main2regions
|
||||
|
||||
# to go back to unsharded
|
||||
# call SwitchReads and SwitchWrites with workflow main.main2regions_reverse
|
||||
# delete vreplication rows from sharded tablets
|
||||
# drop all the tables
|
||||
# change vschema back to unsharded
|
||||
# drop lookup table
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
#!/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 script brings down the tablets for main/0 keyspace/shard
|
||||
|
||||
source ./env.sh
|
||||
|
||||
CELL=zone1 TABLET_UID=100 ./scripts/vttablet-down.sh
|
||||
CELL=zone1 TABLET_UID=100 ./scripts/mysqlctl-down.sh
|
|
@ -0,0 +1,21 @@
|
|||
#!/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 script deletes the old shard 0 which has been replaced by 4 shards
|
||||
|
||||
source ./env.sh
|
||||
|
||||
vtctlclient DeleteShard -recursive main/0
|
|
@ -21,7 +21,7 @@ source ./env.sh
|
|||
|
||||
./scripts/vtgate-down.sh
|
||||
|
||||
for tablet in 100 200 300 400; do
|
||||
for tablet in 200 300 400 500; do
|
||||
if vtctlclient -server localhost:15999 GetTablet zone1-$tablet >/dev/null 2>&1; then
|
||||
echo "Shutting down tablet zone1-$tablet"
|
||||
CELL=zone1 TABLET_UID=$tablet ./scripts/vttablet-down.sh
|
||||
|
@ -45,7 +45,7 @@ fi
|
|||
if [ ! -z "$VTDATAROOT" ]; then
|
||||
|
||||
if pgrep -f -l "$VTDATAROOT" >/dev/null; then
|
||||
echo "ERROR: Stale processes detected! It is recommended to manuallly kill them:"
|
||||
echo "ERROR: Stale processes detected! It is recommended to manually kill them:"
|
||||
pgrep -f -l "$VTDATAROOT"
|
||||
else
|
||||
echo "All good! It looks like every process has shut down"
|
|
@ -10,13 +10,45 @@ This document contains the summary of the commands to be run.
|
|||
"region_map": "/home/user/vitess/examples/region_sharding/countries.json",
|
||||
|
||||
|
||||
# Bring up initial cluster and main keyspace
|
||||
# Bring up initial cluster and main keyspace (unsharded)
|
||||
./101_initial_cluster.sh
|
||||
|
||||
# setup aliases
|
||||
alias mysql="command mysql -h 127.0.0.1 -P 15306"
|
||||
alias vtctlclient="command vtctlclient -server localhost:15999 -log_dir ${VTDATAROOT}/tmp -alsologtostderr"
|
||||
|
||||
# Insert and verify data
|
||||
mysql < insert_customers.sql
|
||||
mysql --table < show_initial_data.sql
|
||||
|
||||
# create schema and vschema for sharding (+lookup vindex)
|
||||
./201_main_sharded.sh
|
||||
|
||||
# bring up shards and tablets
|
||||
./202_new_tablets.sh
|
||||
|
||||
# reshard
|
||||
./203_reshard.sh
|
||||
|
||||
# SwitchReads
|
||||
./204_switch_reads.sh
|
||||
|
||||
# run script to create traffic before switching writes
|
||||
#./client.sh
|
||||
|
||||
# SwitchWrites
|
||||
./205_switch_writes.sh
|
||||
# show no / minimal write errors during switch
|
||||
|
||||
# verify sharded data
|
||||
mysql --table < show_data.sql
|
||||
|
||||
# down shard
|
||||
./206_down_shard_0.sh
|
||||
|
||||
# delete shard 0
|
||||
./207_delete_shard_0.sh
|
||||
|
||||
# Down cluster
|
||||
./201_teardown.sh
|
||||
./301_teardown.sh
|
||||
```
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
CREATE TABLE customer_lookup (
|
||||
id int NOT NULL,
|
||||
keyspace_id varbinary(256),
|
||||
primary key(id)
|
||||
);
|
|
@ -5,8 +5,3 @@ CREATE TABLE customer (
|
|||
country varbinary(256),
|
||||
primary key(id)
|
||||
);
|
||||
CREATE TABLE customer_lookup (
|
||||
id int NOT NULL,
|
||||
keyspace_id varbinary(256),
|
||||
primary key(id)
|
||||
);
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"sharded": true,
|
||||
"vindexes": {
|
||||
"customer_region_lookup": {
|
||||
"type": "consistent_lookup_unique",
|
||||
"params": {
|
||||
"table": "main.customer_lookup",
|
||||
"from": "id",
|
||||
"to": "keyspace_id"
|
||||
},
|
||||
"owner": "customer"
|
||||
}
|
||||
},
|
||||
"tables": {
|
||||
"customer": {
|
||||
"column_vindexes": [
|
||||
{
|
||||
"column": "id",
|
||||
"name": "customer_region_lookup"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
{
|
||||
"sharded": true,
|
||||
"vindexes": {
|
||||
"region_vdx": {
|
||||
"type": "region_json",
|
||||
"params": {
|
||||
"region_map": "/home/user/my-vitess/examples/region_sharding/countries.json",
|
||||
"region_bytes": "1"
|
||||
}
|
||||
},
|
||||
"customer_region_lookup": {
|
||||
"type": "consistent_lookup_unique",
|
||||
"params": {
|
||||
"table": "customer_lookup",
|
||||
"from": "id",
|
||||
"to": "keyspace_id"
|
||||
},
|
||||
"owner": "customer"
|
||||
},
|
||||
"identity": {
|
||||
"type": "binary"
|
||||
}
|
||||
},
|
||||
"tables": {
|
||||
"customer_lookup": {
|
||||
"column_vindexes": [
|
||||
{
|
||||
"column": "keyspace_id",
|
||||
"name": "identity"
|
||||
}
|
||||
]
|
||||
},
|
||||
"customer": {
|
||||
"column_vindexes": [
|
||||
{
|
||||
"columns": ["id", "country"],
|
||||
"name": "region_vdx"
|
||||
},
|
||||
{
|
||||
"column": "id",
|
||||
"name": "customer_region_lookup"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"tables": {
|
||||
"customer": {}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"sharded": true,
|
||||
"vindexes": {
|
||||
"region_vdx": {
|
||||
"type": "region_json",
|
||||
"params": {
|
||||
"region_map": "/home/user/my-vitess/examples/region_sharding/countries.json",
|
||||
"region_bytes": "1"
|
||||
}
|
||||
}
|
||||
},
|
||||
"tables": {
|
||||
"customer": {
|
||||
"column_vindexes": [
|
||||
{
|
||||
"columns": ["id", "country"],
|
||||
"name": "region_vdx"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
use main;
|
||||
select * from customer;
|
|
@ -32,6 +32,28 @@ source ./env.sh # Required so that "mysql" works from alias
|
|||
sleep 5 # Give vtgate time to really start.
|
||||
|
||||
mysql < insert_customers.sql
|
||||
mysql --table < show_data.sql
|
||||
mysql --table < show_initial_data.sql
|
||||
|
||||
./201_teardown.sh
|
||||
# create schema and vschema for sharding (+lookup vindex)
|
||||
./201_main_sharded.sh
|
||||
|
||||
# bring up shards and tablets
|
||||
./202_new_tablets.sh
|
||||
|
||||
# reshard
|
||||
./203_reshard.sh
|
||||
|
||||
# SwitchReads
|
||||
./204_switch_reads.sh
|
||||
|
||||
# SwitchWrites
|
||||
./205_switch_writes.sh
|
||||
|
||||
# down shard
|
||||
./206_down_shard_0.sh
|
||||
|
||||
# delete shard 0
|
||||
./207_delete_shard_0.sh
|
||||
|
||||
# Down cluster
|
||||
./301_teardown.sh
|
||||
|
|
Загрузка…
Ссылка в новой задаче