Skip to content

Commit

Permalink
Merge pull request #6584 from planetscale/fix-docker-compose
Browse files Browse the repository at this point in the history
vtcompose/docker-compose: fix InitShardMaster
deepthi authored Aug 18, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 1a15486 + e31bf31 commit 2d0f294
Showing 2 changed files with 39 additions and 6 deletions.
37 changes: 36 additions & 1 deletion examples/compose/vtcompose/vtcompose.go
Original file line number Diff line number Diff line change
@@ -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",
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.
@@ -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

0 comments on commit 2d0f294

Please sign in to comment.