diff --git a/examples/compose/vtcompose/vtcompose.go b/examples/compose/vtcompose/vtcompose.go index 412542d8cef..5337d87b2f9 100644 --- a/examples/compose/vtcompose/vtcompose.go +++ b/examples/compose/vtcompose/vtcompose.go @@ -434,6 +434,7 @@ func applyKeyspaceDependentPatches( if keyspaceData.shards < 2 { tabAlias = tabAlias + 100 dockerComposeFile = applyTabletPatches(dockerComposeFile, tabAlias, shard, keyspaceData, externalDbInfoMap, opts) + dockerComposeFile = applyShardPatches(dockerComposeFile, tabAlias, shard, keyspaceData, opts) } else { // Determine shard range for i := 0; i < keyspaceData.shards; i++ { @@ -446,6 +447,7 @@ func applyKeyspaceDependentPatches( } tabAlias = tabAlias + 100 dockerComposeFile = applyTabletPatches(dockerComposeFile, tabAlias, shard, keyspaceData, externalDbInfoMap, opts) + dockerComposeFile = applyShardPatches(dockerComposeFile, tabAlias, shard, keyspaceData, opts) } } @@ -475,6 +477,39 @@ func applyDockerComposePatches( return dockerComposeFile } +func applyShardPatches( + dockerComposeFile []byte, + tabAlias int, + shard string, + keyspaceData keyspaceInfo, + opts vtOptions, +) []byte { + dockerComposeFile = applyInMemoryPatch(dockerComposeFile, generateDefaultShard(tabAlias, shard, keyspaceData, opts)) + return dockerComposeFile +} + +func generateDefaultShard(tabAlias int, shard string, keyspaceData keyspaceInfo, opts vtOptions) string { + aliases := []int{tabAlias + 1} // master alias, e.g. 201 + for i := 0; i < keyspaceData.replicaTablets; i++ { + aliases = append(aliases, tabAlias+2+i) // replica aliases, e.g. 202, 203, ... + } + tabletDepends := make([]string, len(aliases)) + for i, tabletId := range aliases { + tabletDepends[i] = fmt.Sprintf("vttablet%d: {condition : service_healthy}", tabletId) + } + // Wait on all shard tablets to be healthy + dependsOn := "depends_on: {" + strings.Join(tabletDepends, ", ") + "}" + + return fmt.Sprintf(` +- op: add + path: /services/init_shard_master%[2]d + value: + image: vitess/base + command: ["sh", "-c", "$$VTROOT/bin/vtctl %[5]s InitShardMaster -force %[4]s/%[3]s %[6]s-%[2]d "] + %[1]s +`, dependsOn, aliases[0], shard, keyspaceData.keyspace, opts.topologyFlags, opts.cell) +} + func applyTabletPatches( dockerComposeFile []byte, tabAlias int, @@ -674,7 +709,7 @@ func generatePrimaryVIndex(tableName, column, name string) string { return fmt.Sprintf(` [{"op": "add", "path": "/tables/%[1]s", -"value": +"value": {"column_vindexes": [ { "column": "%[2]s", diff --git a/examples/compose/vttablet-up.sh b/examples/compose/vttablet-up.sh index 7284fc37d7e..f9f08084330 100755 --- a/examples/compose/vttablet-up.sh +++ b/examples/compose/vttablet-up.sh @@ -1,13 +1,13 @@ #!/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. @@ -120,8 +120,6 @@ $VTROOT/bin/vtctl $TOPOLOGY_FLAGS AddCellInfo -root vitess/$CELL -server_address $VTROOT/bin/vtctl $TOPOLOGY_FLAGS CreateKeyspace $keyspace || true $VTROOT/bin/vtctl $TOPOLOGY_FLAGS CreateShard $keyspace/$shard || true -$VTROOT/bin/vtctl $TOPOLOGY_FLAGS InitTablet -shard $shard -keyspace $keyspace -grpc_port $grpc_port -port $web_port -allow_master_override $alias $tablet_role - #Populate external db conditional args if [ "$external" = "1" ]; then if [ $role = "master" ]; then