Merge pull request #9454 from arvind-murty/am-naming-compose

Changed master to primary
This commit is contained in:
Deepthi Sigireddi 2022-01-11 21:09:50 -08:00 коммит произвёл GitHub
Родитель 56e9dd8d8c 581e4f821f
Коммит 1dfc35bfab
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
13 изменённых файлов: 59 добавлений и 59 удалений

Просмотреть файл

@ -213,12 +213,12 @@ The vreplication container included performs the following actions;
4. Prints out helpful debug information for you.
```
vitess/examples/compose$ docker-compose logs -f vreplication
vreplication_1 | + /vt/bin/vtctlclient --server vtctld:15999 VReplicationExec local-0000000101 'insert into _vt.vreplication (db_name, source, pos, max_tps, max_replication_lag, tablet_types, time_updated, transaction_timestamp, state) values('\''commerce'\'', '\''keyspace:\"ext_commerce\" shard:\"0\" filter:<rules:<match:\"/.*\" > > on_ddl:EXEC_IGNORE '\'', '\'''\'', 9999, 9999, '\''master'\'', 0, 0, '\''Running'\'')'
vreplication_1 | + /vt/bin/vtctlclient --server vtctld:15999 VReplicationExec local-0000000101 'insert into _vt.vreplication (db_name, source, pos, max_tps, max_replication_lag, tablet_types, time_updated, transaction_timestamp, state) values('\''commerce'\'', '\''keyspace:\"ext_commerce\" shard:\"0\" filter:<rules:<match:\"/.*\" > > on_ddl:EXEC_IGNORE '\'', '\'''\'', 9999, 9999, '\''primary'\'', 0, 0, '\''Running'\'')'
vreplication_1 | + /vt/bin/vtctlclient --server vtctld:15999 VReplicationExec local-0000000101 'select * from _vt.vreplication'
vreplication_1 | +----+----------+--------------------------------+-----+----------+---------+---------------------+------+--------------+--------------+-----------------------+---------+---------+----------+
vreplication_1 | | id | workflow | source | pos | stop_pos | max_tps | max_replication_lag | cell | tablet_types | time_updated | transaction_timestamp | state | message | db_name |
vreplication_1 | +----+----------+--------------------------------+-----+----------+---------+---------------------+------+--------------+--------------+-----------------------+---------+---------+----------+
vreplication_1 | | 1 | | keyspace:"ext_commerce" | | | 9999 | 9999 | | master | 0 | 0 | Running | | commerce |
vreplication_1 | | 1 | | keyspace:"ext_commerce" | | | 9999 | 9999 | | primary | 0 | 0 | Running | | commerce |
vreplication_1 | | | | shard:"0" | | | | | | | | | | | |
vreplication_1 | | | | filter:<rules:<match:"/.*" > > | | | | | | | | | | | |
vreplication_1 | | | | on_ddl:EXEC_IGNORE | | | | | | | | | | | |

Просмотреть файл

@ -44,7 +44,7 @@ func main() {
rand.Seed(time.Now().UnixNano())
// Connect to vtgate.
db, err := vitessdriver.Open(*server, "@master")
db, err := vitessdriver.Open(*server, "@primary")
if err != nil {
fmt.Printf("client error: %v\n", err)
os.Exit(1)
@ -52,7 +52,7 @@ func main() {
defer db.Close()
// Insert some messages on random pages.
fmt.Println("Inserting into master...")
fmt.Println("Inserting into primary...")
for i := 0; i < 3; i++ {
tx, err := db.Begin()
if err != nil {
@ -73,7 +73,7 @@ func main() {
}
// Read it back from the primary.
fmt.Println("Reading from master...")
fmt.Println("Reading from primary...")
rows, err := db.Query("SELECT page, time_created_ns, message FROM messages")
if err != nil {
fmt.Printf("query failed: %v\n", err)

Просмотреть файл

@ -97,7 +97,7 @@ services:
-mysql_auth_server_impl none \
-cell $CELL \
-cells_to_watch $CELL \
-tablet_types_to_wait MASTER,REPLICA \
-tablet_types_to_wait PRIMARY,REPLICA \
-service_map 'grpc-vtgateservice' \
-enable_system_settings=true \
"]
@ -158,7 +158,7 @@ services:
- DB_USER
- DB_PASS
- DB_CHARSET
- ROLE=master
- ROLE=primary
command: ["sh", "-c", "[ $$EXTERNAL_DB -eq 1 ] && /script/vttablet-up.sh 100 || exit 0"]
depends_on:
- vtctld
@ -190,7 +190,7 @@ services:
- DB_USER
- DB_PASS
- DB_CHARSET
- ROLE=master
- ROLE=primary
command: ["sh", "-c", "/script/vttablet-up.sh 101"]
depends_on:
- vtctld

Просмотреть файл

@ -142,7 +142,7 @@ services:
- '/script/run-forever.sh /vt/bin/vtgate -topo_implementation consul -topo_global_server_address
consul1:8500 -topo_global_root vitess/global -logtostderr=true -port 8080 -grpc_port
15999 -mysql_server_port 15306 -mysql_auth_server_impl none -cell test -cells_to_watch
test -tablet_types_to_wait MASTER,REPLICA,RDONLY -service_map ''grpc-vtgateservice''
test -tablet_types_to_wait PRIMARY,REPLICA,RDONLY -service_map ''grpc-vtgateservice''
-normalize_queries=true '
depends_on:
- vtctld
@ -186,7 +186,7 @@ services:
- CELL=test
- KEYSPACE=test_keyspace
- SHARD=-80
- ROLE=master
- ROLE=primary
- VTHOST=vttablet101
- EXTERNAL_DB=0
- DB_PORT=
@ -260,7 +260,7 @@ services:
- CELL=test
- KEYSPACE=test_keyspace
- SHARD=80-
- ROLE=master
- ROLE=primary
- VTHOST=vttablet201
- EXTERNAL_DB=0
- DB_PORT=
@ -334,7 +334,7 @@ services:
- CELL=test
- KEYSPACE=lookup_keyspace
- SHARD=-
- ROLE=master
- ROLE=primary
- VTHOST=vttablet301
- EXTERNAL_DB=0
- DB_PORT=

Просмотреть файл

@ -108,6 +108,6 @@ a) The Vitess Control Panel at http://<vitess_ip>:15000
b) The `lvtcl.sh` Helper Script;
The steps are same
1. Do an EmergencyReparentShard to make a replica the new master.
2. Ran InitShardPrimary on the new master.
3. If Vitess is wrong about who the MySQL master is, you can update it with TabletExternallyReparented
1. Do an EmergencyReparentShard to make a replica the new primary.
2. Ran InitShardPrimary on the new primary.
3. If Vitess is wrong about who the MySQL primary is, you can update it with TabletExternallyReparented

Просмотреть файл

@ -17,7 +17,7 @@ services:
volumes:
- vol-db:/var/lib/mysql
- ./mysql/:/docker-entrypoint-initdb.d/
- ./mysql/master_mysql57.cnf:/etc/mysql/conf.d/master_mysql57.cnf:ro
- ./mysql/mysql57.cnf:/etc/mysql/conf.d/mysql57.cnf:ro
- ./mysql/log:/var/log/mysql
command:
- --server-id=1

Просмотреть файл

@ -18,28 +18,28 @@ set -ex
VTCTLD_SERVER=${VTCTLD_SERVER:-'vtctld:15999'}
# Wait until source and destination masters are available
until (/vt/bin/vtctlclient --server $VTCTLD_SERVER ListAllTablets | grep "ext_" | grep "master" ); do
echo 'waiting for external master..';
# Wait until source and destination primaries are available
until (/vt/bin/vtctlclient --server $VTCTLD_SERVER ListAllTablets | grep "ext_" | grep "primary" ); do
echo 'waiting for external primary..';
sleep 1;
done
until (/vt/bin/vtctlclient --server $VTCTLD_SERVER ListAllTablets | grep -v "ext_" | grep "master" ); do
echo 'waiting for managed master..';
until (/vt/bin/vtctlclient --server $VTCTLD_SERVER ListAllTablets | grep -v "ext_" | grep "primary" ); do
echo 'waiting for managed primary..';
sleep 1;
done
# Get source and destination tablet and shard information
TABLET_INFO=$(/vt/bin/vtctlclient --server $VTCTLD_SERVER ListAllTablets)
source_alias=$(echo "$TABLET_INFO "| grep "ext_" | grep "master" | awk '{ print $1 }')
dest_alias=$(echo "$TABLET_INFO "| grep -v "ext_" | grep "master" | awk '{ print $1 }')
source_keyspace=$(echo "$TABLET_INFO "| grep "ext_" | grep "master" | awk '{ print $2 }')
dest_keyspace=$(echo "$TABLET_INFO "| grep -v "ext_" | grep "master" | awk '{ print $2 }')
source_shard=$(echo "$TABLET_INFO "| grep "ext_" | grep "master" | awk '{ print $3 }')
dest_shard=$(echo "$TABLET_INFO "| grep -v "ext_" | grep "master" | awk '{ print $3 }')
source_tablet=$(echo "$TABLET_INFO "| grep "ext_" | grep "master" | awk '{ print $2 "/" $3}')
dest_tablet=$(echo "$TABLET_INFO "| grep -v "ext_" | grep "master" | awk '{ print $2 "/" $3}')
source_alias=$(echo "$TABLET_INFO "| grep "ext_" | grep "primary" | awk '{ print $1 }')
dest_alias=$(echo "$TABLET_INFO "| grep -v "ext_" | grep "primary" | awk '{ print $1 }')
source_keyspace=$(echo "$TABLET_INFO "| grep "ext_" | grep "primary" | awk '{ print $2 }')
dest_keyspace=$(echo "$TABLET_INFO "| grep -v "ext_" | grep "primary" | awk '{ print $2 }')
source_shard=$(echo "$TABLET_INFO "| grep "ext_" | grep "primary" | awk '{ print $3 }')
dest_shard=$(echo "$TABLET_INFO "| grep -v "ext_" | grep "primary" | awk '{ print $3 }')
source_tablet=$(echo "$TABLET_INFO "| grep "ext_" | grep "primary" | awk '{ print $2 "/" $3}')
dest_tablet=$(echo "$TABLET_INFO "| grep -v "ext_" | grep "primary" | awk '{ print $2 "/" $3}')
# Disable foreign_key checks on destination
@ -68,7 +68,7 @@ done
/vt/bin/vtctlclient --server $VTCTLD_SERVER GetSchema $dest_alias
# Start vreplication
/vt/bin/vtctlclient --server $VTCTLD_SERVER VReplicationExec $dest_alias 'insert into _vt.vreplication (db_name, source, pos, max_tps, max_replication_lag, tablet_types, time_updated, transaction_timestamp, state) values('"'"''"$dest_keyspace"''"'"', '"'"'keyspace:\"'"$source_keyspace"'\" shard:\"'"$source_shard"'\" filter:<rules:<match:\"/.*\" > > on_ddl:EXEC_IGNORE '"'"', '"'"''"'"', 9999, 9999, '"'"'master'"'"', 0, 0, '"'"'Running'"'"')'
/vt/bin/vtctlclient --server $VTCTLD_SERVER VReplicationExec $dest_alias 'insert into _vt.vreplication (db_name, source, pos, max_tps, max_replication_lag, tablet_types, time_updated, transaction_timestamp, state) values('"'"''"$dest_keyspace"''"'"', '"'"'keyspace:\"'"$source_keyspace"'\" shard:\"'"$source_shard"'\" filter:<rules:<match:\"/.*\" > > on_ddl:EXEC_IGNORE '"'"', '"'"''"'"', 9999, 9999, '"'"'primary'"'"', 0, 0, '"'"'Running'"'"')'
# Check vreplication status
/vt/bin/vtctlclient --server $VTCTLD_SERVER VReplicationExec $dest_alias 'select * from _vt.vreplication'

Просмотреть файл

@ -15,7 +15,7 @@
# limitations under the License.
# This is a helper script to sync replicas for mysql.
# It handles the special case where the master has purged bin logs that the replica requires.
# It handles the special case where the primary has purged bin logs that the replica requires.
# To use it place a mysql dump of the database on the same directory as this script.
# The name of the dump must be $KEYSPACE.sql. The script can also download the mysqldump for you.
# Replication is fixed by restoring the mysqldump and resetting the slave.
@ -56,7 +56,7 @@ get_slave_status
# Check if SLAVE_IO is running
if [[ $SLAVE_IO_RUNNING = "No" && $LAST_ERRNO = 1236 ]]; then
echo "Master has purged bin logs that slave requires. Sync will require restore from mysqldump"
echo "Primary has purged bin logs that replica requires. Sync will require restore from mysqldump"
if [[ -f $KEYSPACE.sql ]] ; then
echo "mysqldump file $KEYSPACE.sql exists, attempting to restore.."
echo "Resetting slave.."

Просмотреть файл

@ -105,7 +105,7 @@ services:
- '/script/run-forever.sh $$VTROOT/bin/vtgate -topo_implementation consul -topo_global_server_address
consul1:8500 -topo_global_root vitess/global -logtostderr=true -port 8080 -grpc_port
15999 -mysql_server_port 15306 -mysql_auth_server_impl none -cell test -cells_to_watch
test -tablet_types_to_wait MASTER,REPLICA,RDONLY -gateway_implementation discoverygateway
test -tablet_types_to_wait PRIMARY,REPLICA,RDONLY -gateway_implementation discoverygateway
-service_map ''grpc-vtgateservice'' -pid_file $$VTDATAROOT/tmp/vtgate.pid -normalize_queries=true '
depends_on:
- vtctld
@ -131,7 +131,7 @@ services:
- CELL=test
- KEYSPACE=test_keyspace
- SHARD=-80
- ROLE=master
- ROLE=primary
- VTHOST=vttablet101
- EXTERNAL_DB=0
- DB_PORT=
@ -205,7 +205,7 @@ services:
- CELL=test
- KEYSPACE=test_keyspace
- SHARD=80-
- ROLE=master
- ROLE=primary
- VTHOST=vttablet201
- EXTERNAL_DB=0
- DB_PORT=
@ -279,7 +279,7 @@ services:
- CELL=test
- KEYSPACE=unsharded_keyspace
- SHARD=-
- ROLE=master
- ROLE=primary
- VTHOST=vttablet301
- EXTERNAL_DB=0
- DB_PORT=
@ -315,4 +315,4 @@ services:
ports:
- 15100:8080
- "15999"
version: "2.1"
version: "2.1"

Просмотреть файл

@ -421,22 +421,22 @@ func applyKeyspaceDependentPatches(
}
tabAlias := 0 + tabletsUsed*100
shard := "-"
var masterTablets []string
var primaryTablets []string
if tabletsUsed == 0 {
masterTablets = append(masterTablets, "101")
primaryTablets = append(primaryTablets, "101")
} else {
masterTablets = append(masterTablets, strconv.Itoa((tabletsUsed+1)*100+1))
primaryTablets = append(primaryTablets, strconv.Itoa((tabletsUsed+1)*100+1))
}
interval := int(math.Floor(256 / float64(keyspaceData.shards)))
for i := 1; i < keyspaceData.shards; i++ {
masterTablets = append(masterTablets, strconv.Itoa((i+1)*100+1))
primaryTablets = append(primaryTablets, strconv.Itoa((i+1)*100+1))
}
schemaLoad := generateSchemaload(masterTablets, "", keyspaceData.keyspace, externalDbInfo, opts)
schemaLoad := generateSchemaload(primaryTablets, "", keyspaceData.keyspace, externalDbInfo, opts)
dockerComposeFile = applyInMemoryPatch(dockerComposeFile, schemaLoad)
// Append Master and Replica Tablets
// Append Primary and Replica Tablets
if keyspaceData.shards < 2 {
tabAlias = tabAlias + 100
dockerComposeFile = applyTabletPatches(dockerComposeFile, tabAlias, shard, keyspaceData, externalDbInfoMap, opts)
@ -457,7 +457,7 @@ func applyKeyspaceDependentPatches(
}
}
tabletsUsed += len(masterTablets)
tabletsUsed += len(primaryTablets)
return dockerComposeFile
}
@ -511,7 +511,7 @@ func applyShardPatches(
if val, ok := externalDbInfoMap[keyspaceData.keyspace]; ok {
dbInfo = val
}
dockerComposeFile = applyInMemoryPatch(dockerComposeFile, generateExternalmaster(tabAlias, shard, keyspaceData, dbInfo, opts))
dockerComposeFile = applyInMemoryPatch(dockerComposeFile, generateExternalPrimary(tabAlias, shard, keyspaceData, dbInfo, opts))
return dockerComposeFile
}
@ -529,7 +529,7 @@ func generateDefaultShard(tabAlias int, shard string, keyspaceData keyspaceInfo,
return fmt.Sprintf(`
- op: add
path: /services/init_shard_master%[2]d
path: /services/init_shard_primary%[2]d
value:
image: vitess/lite:${VITESS_TAG:-latest}
command: ["sh", "-c", "/vt/bin/vtctlclient %[5]s InitShardPrimary -force %[4]s/%[3]s %[6]s-%[2]d "]
@ -537,7 +537,7 @@ func generateDefaultShard(tabAlias int, shard string, keyspaceData keyspaceInfo,
`, dependsOn, aliases[0], shard, keyspaceData.keyspace, opts.topologyFlags, opts.cell)
}
func generateExternalmaster(
func generateExternalPrimary(
tabAlias int,
shard string,
keyspaceData keyspaceInfo,
@ -550,7 +550,7 @@ func generateExternalmaster(
aliases = append(aliases, tabAlias+2+i) // replica aliases, e.g. 202, 203, ...
}
externalmasterTab := tabAlias
externalPrimaryTab := tabAlias
externalDb := "0"
if dbInfo.dbName != "" {
@ -577,7 +577,7 @@ func generateExternalmaster(
- CELL=%[5]s
- SHARD=%[6]s
- KEYSPACE=%[7]s
- ROLE=master
- ROLE=primary
- VTHOST=vttablet%[1]d
- EXTERNAL_DB=%[8]s
- DB_PORT=%[9]s
@ -593,7 +593,7 @@ func generateExternalmaster(
interval: 30s
timeout: 10s
retries: 15
`, externalmasterTab, opts.topologyFlags, opts.webPort, opts.gRpcPort, opts.cell, shard, keyspaceData.keyspace, externalDb, dbInfo.dbPort, dbInfo.dbHost, dbInfo.dbUser, dbInfo.dbPass, dbInfo.dbCharset)
`, externalPrimaryTab, opts.topologyFlags, opts.webPort, opts.gRpcPort, opts.cell, shard, keyspaceData.keyspace, externalDb, dbInfo.dbPort, dbInfo.dbHost, dbInfo.dbUser, dbInfo.dbPass, dbInfo.dbCharset)
}
func applyTabletPatches(
@ -608,7 +608,7 @@ func applyTabletPatches(
if val, ok := externalDbInfoMap[keyspaceData.keyspace]; ok {
dbInfo = val
}
dockerComposeFile = applyInMemoryPatch(dockerComposeFile, generateDefaultTablet(tabAlias+1, shard, "master", keyspaceData.keyspace, dbInfo, opts))
dockerComposeFile = applyInMemoryPatch(dockerComposeFile, generateDefaultTablet(tabAlias+1, shard, "primary", keyspaceData.keyspace, dbInfo, opts))
for i := 0; i < keyspaceData.replicaTablets; i++ {
dockerComposeFile = applyInMemoryPatch(dockerComposeFile, generateDefaultTablet(tabAlias+2+i, shard, "replica", keyspaceData.keyspace, dbInfo, opts))
}
@ -710,7 +710,7 @@ func generateVtgate(opts vtOptions) string {
-mysql_auth_server_impl none \
-cell %[5]s \
-cells_to_watch %[5]s \
-tablet_types_to_wait MASTER,REPLICA,RDONLY \
-tablet_types_to_wait PRIMARY,REPLICA,RDONLY \
-service_map 'grpc-vtgateservice' \
-normalize_queries=true \
"]

Просмотреть файл

@ -49,10 +49,10 @@ if (( $uid % 100 % 3 == 0 )) ; then
tablet_type='rdonly'
fi
# Consider every tablet with %d00 as external master
# Consider every tablet with %d00 as external primary
if [ $external = 1 ] && (( $uid % 100 == 0 )) ; then
tablet_type='replica'
tablet_role='externalmaster'
tablet_role='externalprimary'
keyspace="ext_$keyspace"
fi
@ -94,8 +94,8 @@ echo "Removing $VTDATAROOT/$tablet_dir/{mysql.sock,mysql.sock.lock}..."
rm -rf $VTDATAROOT/$tablet_dir/{mysql.sock,mysql.sock.lock}
# Create mysql instances
# Do not create mysql instance for master if connecting to external mysql database
if [[ $tablet_role != "externalmaster" ]]; then
# Do not create mysql instance for primary if connecting to external mysql database
if [[ $tablet_role != "externalprimary" ]]; then
echo "Initing mysql for tablet: $uid role: $role external: $external.. "
$VTROOT/bin/mysqlctld \
--init_db_sql_file=$init_db_sql_file \
@ -111,8 +111,8 @@ sleep $sleeptime
$VTROOT/bin/vtctlclient -server vtctld:$GRPC_PORT AddCellInfo -root vitess/$CELL -server_address consul1:8500 $CELL || true
#Populate external db conditional args
if [ $tablet_role = "externalmaster" ]; then
echo "Setting external db args for master: $DB_NAME"
if [ $tablet_role = "externalprimary" ]; then
echo "Setting external db args for primary: $DB_NAME"
external_db_args="-db_host $DB_HOST \
-db_port $DB_PORT \
-init_db_name_override $DB_NAME \
@ -133,7 +133,7 @@ if [ $tablet_role = "externalmaster" ]; then
-enable_replication_reporter=false \
-enforce_strict_trans_tables=false \
-track_schema_versions=true \
-vreplication_tablet_type=master \
-vreplication_tablet_type=primary \
-watch_replication_stream=true"
else
external_db_args="-init_db_name_override $DB_NAME \