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

VSchema not updated after MoveTable. #7217

Closed
jfg956 opened this issue Dec 22, 2020 · 0 comments · Fixed by #7234
Closed

VSchema not updated after MoveTable. #7217

jfg956 opened this issue Dec 22, 2020 · 0 comments · Fixed by #7234

Comments

@jfg956
Copy link
Contributor

jfg956 commented Dec 22, 2020

I am doing the Vitess tutorial and I am at the MoveTable part. I am surprised to see that the VSchema is not updated after the completion of the MoveTable, and this makes the query select count(*) from customer ambiguous. I would expect all queries working before the MoveTable to also work after the MoveTable, which is the case, until I clear the routing rules. For that, I would expect the DropSources called in 205_clean_commerce.sh to update the VSchema. The steps to reproduce can be found below. Thanks for looking into this.

I am using vitess-8.0.0-7e09d0c.tar.gz.

I start the tutorial in local by running this:

mkdir ~/my-vitess-example
cd ~/my-vitess-example
. ./env
./101_initial_cluster.sh
./200_insert_commerce_data.sh

At this point, I can select-count on the three tables in the tutorial:

$ for t in product customer corder; do mysql -N -e "select count(*) from $t"; done
+---+
| 2 |
+---+
+---+
| 5 |
+---+
+---+
| 5 |
+---+

Than, I do the MoveTable, and the queries still work (I am skipping the queries in below):

./201_customer_tablets.sh
./202_move_tables.sh
vtctlclient VDiff customer.commerce2customer
./203_switch_reads.sh
./204_switch_writes.sh
./205_clean_commerce.sh

But I do not like having "magic-routing", so I remove it:

$ vtctlclient GetRoutingRules
{
  "rules": [
    {
      "fromTable": "corder",
      "toTables": [
        "customer.corder"
      ]
    },
    {
      "fromTable": "commerce.corder",
      "toTables": [
        "customer.corder"
      ]
    },
    {
      "fromTable": "commerce.customer",
      "toTables": [
        "customer.customer"
      ]
    },
    {
      "fromTable": "customer",
      "toTables": [
        "customer.customer"
      ]
    }
  ]
}
$ vtctlclient ApplyRoutingRules -rules "{}"
New RoutingRules object:
{

}
If this is not what you expected, check the input data (as JSON parsing will skip unexpected fields).

But now, two of the queries are failing:

$ for t in product customer corder; do mysql -N -e "select count(*) from $t"; done
+---+
| 2 |
+---+
ERROR 1105 (HY000) at line 1: vtgate: http://ip-172-31-40-211.us-east-2.compute.internal:15001/: ambiguous table reference: customer
ERROR 1105 (HY000) at line 1: vtgate: http://ip-172-31-40-211.us-east-2.compute.internal:15001/: ambiguous table reference: corder

I narrowed this down to the VSchemas where I think the commerce keyspace should not have tables corder and customer because they have been moved to the customer keyspace:

$ vtctlclient GetVSchema commerce
{
  "tables": {
    "corder": {

    },
    "customer": {

    },
    "product": {

    }
  }
}
$ vtctlclient GetVSchema customer
{
  "tables": {
    "corder": {

    },
    "customer": {

    }
  }
}

If I "fix" the commerce VSchema, the queries work again:

$ vtctlclient ApplyVSchema -vschema '{ "tables": { "product" : {} } }' commerce
New VSchema object:
{
  "tables": {
    "product": {

    }
  }
}
If this is not what you expected, check the input data (as JSON parsing will skip unexpected fields).
$ for t in product customer corder; do mysql -N -e "select count(*) from $t"; done
+---+
| 2 |
+---+
+---+
| 5 |
+---+
+---+
| 5 |
+---+

I would expect not needing to "fix" the VSchema of the commerce keyspace after a MoveTable.

Thanks again for looking into this.

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

Successfully merging a pull request may close this issue.

3 participants