Skip to content

Allow multiple databases in one mysql instance#4727

Merged
sougou merged 9 commits intovitessio:masterfrom
planetscale:ds-vt-dbname
Apr 16, 2019
Merged

Allow multiple databases in one mysql instance#4727
sougou merged 9 commits intovitessio:masterfrom
planetscale:ds-vt-dbname

Conversation

@deepthi
Copy link
Copy Markdown
Collaborator

@deepthi deepthi commented Mar 16, 2019

We would like to allow multiple vttablets to run against the same MySQL server, with each one using a separate database/schema. The way this will be used is by having a separate schema for each keyspace.
Care needs to be taken in designating tablets as master/replica to match the underlying MySQL configuration.

For this to work, the following are needed:

  • vreplication table should be scoped by db_name. the PK does not need to change (since it is a unique id). Most selects and deletes will remain the same with a few exceptions.
  • reparent_journal does not need to change. Vitess only writes to this table and there is enough information for a human operator to recognize the reparenting events.
  • local_metadata table is used for orchestrator integration. Alias in local_metadata is the tablet alias. This is used in orchestrator config to call TER for the tablet. With multiple vttablets pointing to one mysql server, in case of failover this will need to change to TER all the vttablets pointing to the new master. ClusterAlias in local_metadata is currently keyspace.shard. It is used in the Orc web UI.
  • local_metadata and shard_metadata are used by schema_swap, which needs to change to work at the individual database/schema level
  • To ensure feature parity, tables used by 2PC also need a new column db_name

How to use:

Tasks:

  • add db_name to _vt tables (vreplication, local_metadata, shard_metadata).
  • new integration test with 2 vttablets running against each MySQL
  • change orchestrator conf
  • TwoPC related tables

This PR addresses the basic workflows (reparenting, resharding). It also includes the necessary changes to schema_swap code. Orchestrator and TwoPC will be addressed in forthcoming PRs.

cc @tirsen
Signed-off-by: deepthi deepthi@planetscale.com

@deepthi deepthi requested a review from sougou March 16, 2019 04:05
@tirsen
Copy link
Copy Markdown
Collaborator

tirsen commented Mar 25, 2019

This is not going to work for us. We still need to be able to change the _vt database name through configuration. The reason is we want to host multiple apps in the same Aurora instance in staging due to cost and they will have different permissions.

@tirsen
Copy link
Copy Markdown
Collaborator

tirsen commented Mar 31, 2019

Actually this will work for us short and medium term since we don't currently share database clusters between services. So let's keep going down this path.

deepthi added 7 commits April 9, 2019 16:41
Signed-off-by: deepthi <deepthi@planetscale.com>
Signed-off-by: deepthi <deepthi@planetscale.com>
Signed-off-by: deepthi <deepthi@planetscale.com>
Signed-off-by: deepthi <deepthi@planetscale.com>
Signed-off-by: deepthi <deepthi@planetscale.com>
Signed-off-by: deepthi <deepthi@planetscale.com>
Signed-off-by: deepthi <deepthi@planetscale.com>
@deepthi deepthi marked this pull request as ready for review April 10, 2019 00:55
@deepthi deepthi requested a review from tirsen April 10, 2019 00:56
deepthi added 2 commits April 11, 2019 19:10
Signed-off-by: deepthi <deepthi@planetscale.com>
Signed-off-by: deepthi <deepthi@planetscale.com>
Copy link
Copy Markdown
Contributor

@sougou sougou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my first pass, I'm not feeling comfortable about the local_metadata change. Let's see if we can avoid changing it at all.
I'm thinking we should even kill schema swap if need be, since it's the only other tool that depends on it, and needs the db_name field.

I also don't like the bloat on the vreplication alter, but it appears unavoidable. So, let's leave that part alone.

@sougou sougou merged commit b383d00 into vitessio:master Apr 16, 2019
@deepthi
Copy link
Copy Markdown
Collaborator Author

deepthi commented Apr 16, 2019

On my first pass, I'm not feeling comfortable about the local_metadata change. Let's see if we can avoid changing it at all.
I'm thinking we should even kill schema swap if need be, since it's the only other tool that depends on it, and needs the db_name field.

For the record, @sougou and I discussed this at length. We decided to keep these changes so that orchestrator can be used with vitess in the multiple vttablet vs single mysql configuration.

@rafael
Copy link
Copy Markdown
Member

rafael commented Apr 22, 2019

I think this PR introduces a regression when you have tablets that have a build that does not use db_name. We are trying to provision new tablets in our dev environment and seeing the following error:

F0422 12:54:35.889873    3243 vttablet.go:130] NewActionAgent() failed: Field 'db_name' doesn't have a default value (errno 1364) (sqlstate HY000) during query: INSERT INTO _vt.local_metadata (name,value) VALUES ('PromotionRule','neutral') ON DUPLICATE KEY UPDATE value = 'neutral'
failed to -init_populate_metadata

setassociative pushed a commit to tinyspeck/vitess that referenced this pull request Apr 26, 2019
It's been busy and exciting in vitess upstream. Some changes that felt worth calling out as they could impact assumptions about behavior:

- vitessio#4832 — this adds a timeout that is 3x the `healthCheckInterval` which at which point the tablet will stop reporting as healthy
- vitessio#4814 — this changes when command line args are used by vttablet
- vitessio#4811 — a planned reparent now sets `super_read_only`
- vitessio#4805 — behavior coming back from a failed backup is different

**Slack changes**  
        @demmer vitessio#4827 Correct suppress logging for begin...commit in autocommit
        @rafael vitessio#4824 adds timeouts for all statements
        @demmer vitessio#4826 adds logging of stack traces as opt-in
        @demmer vitessio#4819 remove begin/commit logs from autocommit txns
        @demmer vitessio#4796 improves support for vtexplain for begin/dml/dml/commit txns

**Non slack changes**  
        vitessio#4839 Improve behavior with reference table routing & vreplication
        vitessio#4833 Support query routing given there could be multiple targets for a table
        vitessio#4832 tablets get new health check behavior (health checks time out)
        vitessio#4837 refresh bug around row streamer handling creds
        vitessio#4830 apply a default value to the db_name attribute in local_metadata
        vitessio#4785 SHOW SCHEMAS aliased to SHOW DATABASES
        vitessio#4829 add experimental support for split clone & vertical split clone via vreplication
        vitessio#4822 do not normalize in order by
        vitessio#4791 Adds vreplication row streaming support
        vitessio#4814 command line flags now used regardless of management mode
        vitessio#4811 vttablet sets super_read_only during planned reparent
        vitessio#4803 xtrabackup testing
        vitessio#4727 support multiple vttablets running against one mysql instance
        vitessio#4746 TopoCat can now produce JSON output
        vitessio#4805 mysqld is now restarted after a failed backup
        vitessio#4685 macos bootstrap bug
        vitessio#4874 ZK opts and java land
        vitessio#4695 Adds support for xtrabackup
        vitessio#4794 fixes build failures
        vitessio#4725 changes mysql8.0 start args
        vitessio#4736 introduce new states to support vreplication
        vitessio#4788 expands orc error

**Docs etc**  
        vitessio#4831 lint
        vitessio#4827 docs
        vitessio#4816 const declaration cleanup
        vitessio#4820 const declaration cleanup
        vitessio#4825 docs
        vitessio#4818 docs
        vitessio#4809 docs
        vitessio#4812 moves consts around
        vitessio#4813 docs
        vitessio#4808 docs
        vitessio#4800 docs
        vitessio#4795 docs
@deepthi
Copy link
Copy Markdown
Collaborator Author

deepthi commented Apr 29, 2019

I think this PR introduces a regression when you have tablets that have a build that does not use db_name. We are trying to provision new tablets in our dev environment and seeing the following error:

F0422 12:54:35.889873    3243 vttablet.go:130] NewActionAgent() failed: Field 'db_name' doesn't have a default value (errno 1364) (sqlstate HY000) during query: INSERT INTO _vt.local_metadata (name,value) VALUES ('PromotionRule','neutral') ON DUPLICATE KEY UPDATE value = 'neutral'
failed to -init_populate_metadata

As it turns out, a new tablet was deployed with a new build, and a backup was taken from that.
Then tablets on hosts with old builds tried to restore from this backup, and failed.
This is really a 'forward-compatibility' type of scenario that we did not design for.
In order to avoid such problems during rolling updates that might span days or weeks, a fix has been implemented in #4830

@deepthi
Copy link
Copy Markdown
Collaborator Author

deepthi commented Oct 26, 2019

Re orchestrator integration, we will not change the config file at docker/orchestrator/orchestrator.conf.json, that will continue to be for the single-schema case. With multiple schemas, the conf file needs to change as follows:

"DetectClusterAliasQuery": "SELECT GROUP_CONCAT(value) FROM _vt.local_metadata WHERE name='ClusterAlias'",
  "DetectInstanceAliasQuery": "SELECT GROUP_CONCAT(value) FROM _vt.local_metadata WHERE name='Alias'",
  "PostMasterFailoverProcesses": [
    "echo 'Recovered from {failureType} on {failureCluster}. Failed: {failedHost}:{failedPort}; Promoted: {successorHost}:{successorPort}' >> /tmp/recovery.log",
    "IFS=','  for tablet in {successorAlias}; do vtctlclient -server vtctld:15999 TabletExternallyReparented $tablet; done"]

@deepthi deepthi deleted the ds-vt-dbname branch July 6, 2020 19:02
@yzsfly
Copy link
Copy Markdown

yzsfly commented Jul 21, 2021

One question: two keyspaces against one shard, will the orchestrator still work well as expected?

@yzsfly
Copy link
Copy Markdown

yzsfly commented Jul 22, 2021

if multiple database in one mysql, how to set cluster_to_watch flag, will the vtorc detecting result still ok?

@deepthi
Copy link
Copy Markdown
Collaborator Author

deepthi commented Aug 5, 2021

if multiple database in one mysql, how to set cluster_to_watch flag, will the vtorc detecting result still ok?

good question. vtorc must be configured to watch all keyspaces in the same mysql instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants