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

vtcompose/docker-compose: fix InitShardMaster #6584

Merged
merged 1 commit into from
Aug 18, 2020
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
37 changes: 36 additions & 1 deletion examples/compose/vtcompose/vtcompose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++ {
Expand All @@ -446,6 +447,7 @@ func applyKeyspaceDependentPatches(
}
tabAlias = tabAlias + 100
dockerComposeFile = applyTabletPatches(dockerComposeFile, tabAlias, shard, keyspaceData, externalDbInfoMap, opts)
dockerComposeFile = applyShardPatches(dockerComposeFile, tabAlias, shard, keyspaceData, opts)
}
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 3 additions & 5 deletions examples/compose/vttablet-up.sh
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down