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

Make vttestserver docker image work with vtctldclient #14665

Merged
merged 4 commits into from
Dec 5, 2023

Conversation

GuptaManan100
Copy link
Member

@GuptaManan100 GuptaManan100 commented Dec 4, 2023

Description

While suggesting a way to create a new database in vttestserver with the managed mode, it was noticed that the docker image of vttestserver didn't actually support running any vtctldclient commands.

On further investigation it was found that this was happening because the bind address provided to vtcombo was hard-coded to 127.0.0.1 which meant that in a docker environment it would never accept any requests coming from the outside even if port-forwarding was used. Therefore, this PR made the changes to configure this value from vttestserver as a flag and augmented the docker image to use a new environment variable VTCOMBO_BIND_HOST to pass in the correct value.

After making these changes, we are able to run vtctld commands issued through the vtctldclient against a docker image running vttestserver. Moreover, we also able to access the vtcombo status page.

For example, if we run -

docker run --name=vttestserver \                      
-p 33577:33577 \
-p 33575:33575 \
-p 33574:33574 \
-e PORT=33574 \
-e KEYSPACES=test,unsharded \
-e NUM_SHARDS=2,1 \
-e MYSQL_MAX_CONNECTIONS=70000 \
-e MYSQL_BIND_HOST=0.0.0.0 \
-e VTCOMBO_BIND_HOST=0.0.0.0 \
--health-cmd="mysqladmin ping -h127.0.0.1 -P33577" \
--health-interval=5s \
--health-timeout=2s \
--health-retries=5 \
vitess/vttestserver:mysql80

We can connect to vtgate using the command mysql --host 127.0.0.1 --port 33577 --user "root". We can verify that we have two databases running -

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| test               |
| unsharded          |
| information_schema |
| mysql              |
| sys                |
| performance_schema |
+--------------------+
6 rows in set (0.01 sec)

We can also see the keyspaces by running the vtctldclient command like so -

vtctldclient --server 127.0.0.1:33575 GetKeyspaces              
[
  {
    "name": "test",
    "keyspace": {
      "sidecar_db_name": "_vt"
    }
  },
  {
    "name": "unsharded",
    "keyspace": {
      "sidecar_db_name": "_vt"
    }
  }
]

Then we can create a new database in the vtgate mysql shell -

mysql> create database fk_test;
Query OK, 1 row affected (5.25 sec)

We can verify that the new keyspace is created like so -

vtctldclient --server 127.0.0.1:33575 GetKeyspaces
[
  {
    "name": "fk_test",
    "keyspace": {
      "sidecar_db_name": "_vt"
    }
  },
  {
    "name": "test",
    "keyspace": {
      "sidecar_db_name": "_vt"
    }
  },
  {
    "name": "unsharded",
    "keyspace": {
      "sidecar_db_name": "_vt"
    }
  }
]

We can now create a local vschema file like so -

{
    "sidecar_db_name": "_vt",
    "foreignKeyMode": "managed",
    "tables": {
    }
}

We then use the vtctldclient to apply this vschema to the new keyspace -

vtctldclient --server 127.0.0.1:33575 ApplyVSchema --vschema-file vschema_fk_test.json fk_test 
New VSchema object:
{
  "sharded": false,
  "vindexes": {},
  "tables": {},
  "require_explicit_routing": false,
  "foreign_key_mode": "managed"
}
If this is not what you expected, check the input data (as JSON parsing will skip unexpected fields).

Finally, we can verify that the foreign key mode has been successfully changed by running the following query in vtgate mysql shell -

mysql> show vschema keyspaces;
+-----------+---------+-------------+---------+
| Keyspace  | Sharded | Foreign Key | Comment |
+-----------+---------+-------------+---------+
| test      | true    | unmanaged   |         |
| unsharded | false   | unmanaged   |         |
| fk_test   | false   | managed     |         |
+-----------+---------+-------------+---------+
3 rows in set (0.01 sec)

We can also access the /debug/status page from vtcombo by visiting the site http://localhost:33574/debug/status -
Screenshot 2023-12-05 at 1 50 13 PM

Tests to verify that vtctldclient works have also been added and ensured that they indeed work - PASS: TestVtctldCommands/vttestserver-e2etest/mysql80 (6.54s)

Related Issue(s)

Checklist

Deployment Notes

Copy link
Contributor

vitess-bot bot commented Dec 4, 2023

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Dec 4, 2023
@github-actions github-actions bot added this to the v19.0.0 milestone Dec 4, 2023
…cker image so that vtctldclient can access the vtctld server running in it

Signed-off-by: Manan Gupta <[email protected]>
@GuptaManan100 GuptaManan100 added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: vttestserver and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request labels Dec 5, 2023
@GuptaManan100 GuptaManan100 merged commit 3d53207 into vitessio:main Dec 5, 2023
116 checks passed
@GuptaManan100 GuptaManan100 deleted the vttestserver-vtctld branch December 5, 2023 14:52
ejortegau pushed a commit to slackhq/vitess that referenced this pull request Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: vttestserver Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Allow new databases/keyspaces to run in foreignKeyMode=managed by default (in vttestserver)
3 participants