-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Experimental: Multi-tenant import support in Vitess #15128
Closed
rohit-nayak-ps
wants to merge
27
commits into
vitessio:main
from
planetscale:rohit/movetables-filter
Closed
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
7b97add
Initial commit for adding filter clause to MoveTables. Working e2e test.
rohit-nayak-ps f680c67
Fix failing unit tests
rohit-nayak-ps 5a89e9c
Fix failing unit and e2e tests
rohit-nayak-ps 633e817
fix failing unit tests
rohit-nayak-ps 9767c52
Fix incorrect logic for getting reverse replication filter
rohit-nayak-ps 645a313
Fix vreplication unit tests
rohit-nayak-ps 764d39b
Fix logic for adding additional filter in reverse workflows
rohit-nayak-ps 82412b4
Fix a bunch of failing unit tests
rohit-nayak-ps 95c7742
Add Keyspace Routing Rules to proto and functions to get/put the rules
rohit-nayak-ps 04327be
Use keyspace routing rules in vtgate
rohit-nayak-ps 416cb18
Remove compressed rules for now, until we come up with a better abstr…
rohit-nayak-ps 8c21354
Add flags for keyspace routing rules in MoveTables. Add rules when cr…
rohit-nayak-ps 092d5b0
Working e2e test for single tenant migration with keyspace routing ru…
rohit-nayak-ps 91481b9
Protect map access with mutexes in e2e test. Make function scope priv…
rohit-nayak-ps e81e873
Make proto
rohit-nayak-ps d2617f6
Fix failing unit tests
rohit-nayak-ps dade06e
Generate flags help text
rohit-nayak-ps b753df4
Fix failing unit tests
rohit-nayak-ps f46061f
Improve e2e test by creating more tenants and randomize the workflow …
rohit-nayak-ps c34783f
Compression tests
rohit-nayak-ps ba8e428
Revert compression test. For now we are going to assume keyspace rout…
rohit-nayak-ps 55c7df6
Address a couple of review comments
rohit-nayak-ps 9b6b640
Address more review comments. Refactor the e2e test.The refactor of F…
rohit-nayak-ps eedb210
Allow creating new MoveTables workflows when there are previous Froze…
rohit-nayak-ps afaa323
Fix unit tests for removal of the frozen check
rohit-nayak-ps 3343c15
Reduce number of tenants in e2e test to make it run in a reasonable t…
rohit-nayak-ps 6ab42cc
Fix check in reverse traffic to account for keyspace routing rules. A…
rohit-nayak-ps File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
172 changes: 172 additions & 0 deletions
172
.github/workflows/cluster_endtoend_vreplication_multi_tenant.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
# DO NOT MODIFY: THIS FILE IS GENERATED USING "make generate_ci_workflows" | ||
|
||
name: Cluster (vreplication_multi_tenant) | ||
on: [push, pull_request] | ||
concurrency: | ||
group: format('{0}-{1}', ${{ github.ref }}, 'Cluster (vreplication_multi_tenant)') | ||
cancel-in-progress: true | ||
|
||
permissions: read-all | ||
|
||
env: | ||
LAUNCHABLE_ORGANIZATION: "vitess" | ||
LAUNCHABLE_WORKSPACE: "vitess-app" | ||
GITHUB_PR_HEAD_SHA: "${{ github.event.pull_request.head.sha }}" | ||
|
||
jobs: | ||
build: | ||
name: Run endtoend tests on Cluster (vreplication_multi_tenant) | ||
runs-on: gh-hosted-runners-4cores-1 | ||
|
||
steps: | ||
- name: Skip CI | ||
run: | | ||
if [[ "${{contains( github.event.pull_request.labels.*.name, 'Skip CI')}}" == "true" ]]; then | ||
echo "skipping CI due to the 'Skip CI' label" | ||
exit 1 | ||
fi | ||
|
||
- name: Check if workflow needs to be skipped | ||
id: skip-workflow | ||
run: | | ||
skip='false' | ||
if [[ "${{github.event.pull_request}}" == "" ]] && [[ "${{github.ref}}" != "refs/heads/main" ]] && [[ ! "${{github.ref}}" =~ ^refs/heads/release-[0-9]+\.[0-9]$ ]] && [[ ! "${{github.ref}}" =~ "refs/tags/.*" ]]; then | ||
skip='true' | ||
fi | ||
echo Skip ${skip} | ||
echo "skip-workflow=${skip}" >> $GITHUB_OUTPUT | ||
|
||
PR_DATA=$(curl \ | ||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
"https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}") | ||
draft=$(echo "$PR_DATA" | jq .draft -r) | ||
echo "is_draft=${draft}" >> $GITHUB_OUTPUT | ||
|
||
- name: Check out code | ||
if: steps.skip-workflow.outputs.skip-workflow == 'false' | ||
uses: actions/checkout@v3 | ||
|
||
- name: Check for changes in relevant files | ||
if: steps.skip-workflow.outputs.skip-workflow == 'false' | ||
uses: dorny/paths-filter@v3.0.1 | ||
id: changes | ||
with: | ||
token: '' | ||
filters: | | ||
end_to_end: | ||
- 'go/**/*.go' | ||
- 'go/vt/sidecardb/**/*.sql' | ||
- 'go/test/endtoend/onlineddl/vrepl_suite/**' | ||
- 'test.go' | ||
- 'Makefile' | ||
- 'build.env' | ||
- 'go.sum' | ||
- 'go.mod' | ||
- 'proto/*.proto' | ||
- 'tools/**' | ||
- 'config/**' | ||
- 'bootstrap.sh' | ||
- '.github/workflows/cluster_endtoend_vreplication_multi_tenant.yml' | ||
|
||
- name: Set up Go | ||
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.22.0 | ||
|
||
- name: Set up python | ||
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' | ||
uses: actions/setup-python@v4 | ||
|
||
- name: Tune the OS | ||
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' | ||
run: | | ||
# Limit local port range to not use ports that overlap with server side | ||
# ports that we listen on. | ||
sudo sysctl -w net.ipv4.ip_local_port_range="22768 65535" | ||
# Increase the asynchronous non-blocking I/O. More information at https://dev.mysql.com/doc/refman/5.7/en/innodb-parameters.html#sysvar_innodb_use_native_aio | ||
echo "fs.aio-max-nr = 1048576" | sudo tee -a /etc/sysctl.conf | ||
sudo sysctl -p /etc/sysctl.conf | ||
|
||
- name: Get dependencies | ||
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' | ||
run: | | ||
|
||
# Get key to latest MySQL repo | ||
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys A8D3785C | ||
# Setup MySQL 8.0 | ||
wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.29-1_all.deb | ||
echo mysql-apt-config mysql-apt-config/select-server select mysql-8.0 | sudo debconf-set-selections | ||
sudo DEBIAN_FRONTEND="noninteractive" dpkg -i mysql-apt-config* | ||
sudo apt-get update | ||
# Install everything else we need, and configure | ||
sudo apt-get install -y mysql-server mysql-client make unzip g++ etcd curl git wget eatmydata xz-utils libncurses5 | ||
|
||
sudo service mysql stop | ||
sudo service etcd stop | ||
sudo ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/ | ||
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld | ||
go mod download | ||
|
||
# install JUnit report formatter | ||
go install github.com/vitessio/go-junit-report@HEAD | ||
|
||
- name: Setup launchable dependencies | ||
if: steps.skip-workflow.outputs.is_draft == 'false' && steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' && github.base_ref == 'main' | ||
run: | | ||
# Get Launchable CLI installed. If you can, make it a part of the builder image to speed things up | ||
pip3 install --user launchable~=1.0 > /dev/null | ||
|
||
# verify that launchable setup is all correct. | ||
launchable verify || true | ||
|
||
# Tell Launchable about the build you are producing and testing | ||
launchable record build --name "$GITHUB_RUN_ID" --no-commit-collection --source . | ||
|
||
- name: Run cluster endtoend test | ||
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' | ||
timeout-minutes: 45 | ||
run: | | ||
# We set the VTDATAROOT to the /tmp folder to reduce the file path of mysql.sock file | ||
# which musn't be more than 107 characters long. | ||
export VTDATAROOT="/tmp/" | ||
source build.env | ||
|
||
set -exo pipefail | ||
|
||
# Increase our open file descriptor limit as we could hit this | ||
ulimit -n 65536 | ||
cat <<-EOF>>./config/mycnf/mysql80.cnf | ||
innodb_buffer_pool_dump_at_shutdown=OFF | ||
innodb_buffer_pool_in_core_file=OFF | ||
innodb_buffer_pool_load_at_startup=OFF | ||
innodb_buffer_pool_size=64M | ||
innodb_doublewrite=OFF | ||
innodb_flush_log_at_trx_commit=0 | ||
innodb_flush_method=O_DIRECT | ||
innodb_numa_interleave=ON | ||
innodb_adaptive_hash_index=OFF | ||
sync_binlog=0 | ||
sync_relay_log=0 | ||
performance_schema=OFF | ||
slow-query-log=OFF | ||
EOF | ||
|
||
cat <<-EOF>>./config/mycnf/mysql80.cnf | ||
binlog-transaction-compression=ON | ||
EOF | ||
|
||
# run the tests however you normally do, then produce a JUnit XML file | ||
eatmydata -- go run test.go -docker=false -follow -shard vreplication_multi_tenant | tee -a output.txt | go-junit-report -set-exit-code > report.xml | ||
|
||
- name: Print test output and Record test result in launchable if PR is not a draft | ||
if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' && always() | ||
run: | | ||
if [[ "${{steps.skip-workflow.outputs.is_draft}}" == "false" ]]; then | ||
# send recorded tests to launchable | ||
launchable record tests --build "$GITHUB_RUN_ID" go-test . || true | ||
fi | ||
|
||
# print test output | ||
cat output.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
Copyright 2024 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. | ||
*/ | ||
|
||
package command | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"vitess.io/vitess/go/cmd/vtctldclient/cli" | ||
"vitess.io/vitess/go/json2" | ||
|
||
vschemapb "vitess.io/vitess/go/vt/proto/vschema" | ||
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata" | ||
) | ||
|
||
var ( | ||
// ApplyKeyspaceRoutingRules makes an ApplyKeyspaceRoutingRules gRPC call to a vtctld. | ||
ApplyKeyspaceRoutingRules = &cobra.Command{ | ||
Use: "ApplyKeyspaceRoutingRules {--rules RULES | --rules-file RULES_FILE} [--cells=c1,c2,...] [--skip-rebuild] [--dry-run]", | ||
Short: "Applies the provided keyspace routing rules.", | ||
DisableFlagsInUseLine: true, | ||
Args: cobra.NoArgs, | ||
RunE: commandApplyKeyspaceRoutingRules, | ||
} | ||
// GetKeyspaceRoutingRules makes a GetKeyspaceRoutingRules gRPC call to a vtctld. | ||
GetKeyspaceRoutingRules = &cobra.Command{ | ||
Use: "GetKeyspaceRoutingRules", | ||
Short: "Displays the currently active keyspace routing rules as a JSON document.", | ||
Long: "Displays the currently active keyspace routing rules as a JSON document.", | ||
DisableFlagsInUseLine: true, | ||
Args: cobra.NoArgs, | ||
RunE: commandGetKeyspaceRoutingRules, | ||
} | ||
) | ||
|
||
var applyKeyspaceRoutingRulesOptions = struct { | ||
Rules string | ||
RulesFilePath string | ||
Cells []string | ||
SkipRebuild bool | ||
DryRun bool | ||
}{} | ||
|
||
func commandApplyKeyspaceRoutingRules(cmd *cobra.Command, args []string) error { | ||
if applyKeyspaceRoutingRulesOptions.Rules != "" && applyKeyspaceRoutingRulesOptions.RulesFilePath != "" { | ||
return fmt.Errorf("cannot pass both --rules (=%s) and --rules-file (=%s)", applyKeyspaceRoutingRulesOptions.Rules, applyKeyspaceRoutingRulesOptions.RulesFilePath) | ||
} | ||
|
||
if applyKeyspaceRoutingRulesOptions.Rules == "" && applyKeyspaceRoutingRulesOptions.RulesFilePath == "" { | ||
return errors.New("must pass exactly one of --rules or --rules-file") | ||
} | ||
|
||
cli.FinishedParsing(cmd) | ||
|
||
var rulesBytes []byte | ||
if applyKeyspaceRoutingRulesOptions.RulesFilePath != "" { | ||
data, err := os.ReadFile(applyKeyspaceRoutingRulesOptions.RulesFilePath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
rulesBytes = data | ||
} else { | ||
rulesBytes = []byte(applyKeyspaceRoutingRulesOptions.Rules) | ||
} | ||
|
||
srr := &vschemapb.KeyspaceRoutingRules{} | ||
if err := json2.Unmarshal(rulesBytes, &srr); err != nil { | ||
return err | ||
} | ||
// Round-trip so when we display the result it's readable. | ||
data, err := cli.MarshalJSON(srr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if applyKeyspaceRoutingRulesOptions.DryRun { | ||
fmt.Printf("[DRY RUN] Would have saved new KeyspaceRoutingRules object:\n%s\n", data) | ||
|
||
if applyRoutingRulesOptions.SkipRebuild { | ||
fmt.Println("[DRY RUN] Would not have rebuilt VSchema graph, would have required operator to run RebuildVSchemaGraph for changes to take effect.") | ||
} else { | ||
fmt.Print("[DRY RUN] Would have rebuilt the VSchema graph") | ||
if len(applyRoutingRulesOptions.Cells) == 0 { | ||
fmt.Print(" in all cells\n") | ||
} else { | ||
fmt.Printf(" in the following cells: %s.\n", strings.Join(applyKeyspaceRoutingRulesOptions.Cells, ", ")) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
_, err = client.ApplyKeyspaceRoutingRules(commandCtx, &vtctldatapb.ApplyKeyspaceRoutingRulesRequest{ | ||
KeyspaceRoutingRules: srr, | ||
SkipRebuild: applyKeyspaceRoutingRulesOptions.SkipRebuild, | ||
RebuildCells: applyKeyspaceRoutingRulesOptions.Cells, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("New KeyspaceRoutingRules object:\n%s\nIf this is not what you expected, check the input data (as JSON parsing will skip unexpected fields).\n", data) | ||
|
||
if applyRoutingRulesOptions.SkipRebuild { | ||
fmt.Println("Skipping rebuild of VSchema graph as requested, you will need to run RebuildVSchemaGraph for the changes to take effect.") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func commandGetKeyspaceRoutingRules(cmd *cobra.Command, args []string) error { | ||
cli.FinishedParsing(cmd) | ||
|
||
resp, err := client.GetKeyspaceRoutingRules(commandCtx, &vtctldatapb.GetKeyspaceRoutingRulesRequest{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
data, err := cli.MarshalJSON(resp.KeyspaceRoutingRules) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("%s\n", data) | ||
|
||
return nil | ||
} | ||
|
||
func init() { | ||
ApplyKeyspaceRoutingRules.Flags().StringVarP(&applyKeyspaceRoutingRulesOptions.Rules, "rules", "r", "", "Shard routing rules, specified as a string") | ||
ApplyKeyspaceRoutingRules.Flags().StringVarP(&applyKeyspaceRoutingRulesOptions.RulesFilePath, "rules-file", "f", "", "Path to a file containing shard routing rules specified as JSON") | ||
ApplyKeyspaceRoutingRules.Flags().StringSliceVarP(&applyKeyspaceRoutingRulesOptions.Cells, "cells", "c", nil, "Limit the VSchema graph rebuilding to the specified cells. Ignored if --skip-rebuild is specified.") | ||
ApplyKeyspaceRoutingRules.Flags().BoolVar(&applyKeyspaceRoutingRulesOptions.SkipRebuild, "skip-rebuild", false, "Skip rebuilding the SrvVSchema objects.") | ||
ApplyKeyspaceRoutingRules.Flags().BoolVarP(&applyKeyspaceRoutingRulesOptions.DryRun, "dry-run", "d", false, "Validate the specified shard routing rules and note actions that would be taken, but do not actually apply the rules to the topo.") | ||
Root.AddCommand(ApplyKeyspaceRoutingRules) | ||
|
||
Root.AddCommand(GetKeyspaceRoutingRules) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about extending
ApplyRoutingRules
andGetRoutingRules
to take optional keyspace and shard arguments? Then we won't have so many separate commands. We can then also deprecate and deleteApplyShardRoutingRules
andGetShardRoutingRules
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Keyspace, Routing and Shard rules are quite different in terms of functionality. It might be better to have them separate because of that.
We can't have a table routing rule just for a shard for example. Also each of these takes a rules file and those files cannot contain a combination of table and keyspace for example.
Maybe we can have think of a RoutingRule umbrella command:
table
,keyspace
andshard
subcommands andapply
andget
actions. But it will be a non-trivial refactor.