vitessio / vitess

Vitess is a database clustering system for horizontal scaling of MySQL.
http://vitess.io
Apache License 2.0
18.47k stars 2.09k forks source link

Bug Report: VReplication --initiailize-target-sequences only supports one column definition method #16861

Open mattlord opened 18 hours ago

mattlord commented 18 hours ago

Overview of the Issue

You can specify the columns which make up a vindex in two ways within the vschema:

  1. The "legacy" way (a simple string):
    "corder": {
      "column_vindexes": [
        {
          "column": "customer_id",
          "name": "hash"
        }
      ],
      "auto_increment": {
        "column": "order_id",
        "sequence": "order_seq"
      }
    },
  2. The "new" way (an array):
    "product": {
      "column_vindexes": [
        {
          "columns": [
            "product_id"
          ],
          "name": "hash"
        }
      ],
      "auto_increment": {
        "column": "product_id",
        "sequence": "product_seq"
      }
    }

The MoveTables target sequence initialization work (added in https://github.com/vitessio/vitess/pull/13656) only supports the legacy way. It needs to be updated to support either.

Reproduction Steps

git checkout main && make build

alias vtctldclient='command vtctldclient --server=localhost:15999'

./101_initial_cluster.sh; mysql < ../common/insert_commerce_data.sql; ./201_customer_tablets.sh; ./202_move_tables.sh; ./203_switch_reads.sh; ./204_switch_writes.sh; ./205_clean_commerce.sh; ./301_customer_sharded.sh; ./302_new_shards.sh; ./303_reshard.sh; ./304_switch_reads.sh; ./305_switch_writes.sh; ./306_down_shard_0.sh; ./307_delete_shard_0.sh

vtctldclient ApplySchema --sql "alter table product drop primary key, add product_id int unsigned not null auto_increment primary key" commerce

vtctldclient ApplyVSchema --vschema='
{
  "sharded": true,
  "vindexes": {
    "hash": {
      "type": "hash"
    }
  },
  "tables": {
    "corder": {
      "column_vindexes": [
        {
          "column": "customer_id",
          "name": "hash"
        }
      ],
      "auto_increment": {
        "column": "order_id",
        "sequence": "order_seq"
      }
    },
    "customer": {
      "column_vindexes": [
        {
          "column": "customer_id",
          "name": "hash"
        }
      ],
      "auto_increment": {
        "column": "customer_id",
        "sequence": "customer_seq"
      }
    },
    "product": {
      "column_vindexes": [
        {
          "columns": [
            "product_id"
          ],
          "name": "hash"
        }
      ],
      "auto_increment": {
        "column": "product_id",
        "sequence": "product_seq"
      }
    }
  }
}
' customer

vtctldclient ApplyVSchema --vschema='
{
  "tables": {
    "customer_seq": {
      "type": "sequence"
    },
    "order_seq": {
      "type": "sequence"
    },
    "product_seq": {
      "type": "sequence"
    }
  }
}
' commerce

mysql commerce -e "create table if not exists product_seq (id int, next_id bigint, cache bigint, primary key(id)) comment 'vitess_sequence'"

sleep 5

vtctldclient MoveTables --workflow commerce2customer --target-keyspace customer create --source-keyspace commerce --tables product

sleep 5

vtctldclient MoveTables --workflow commerce2customer --target-keyspace customer switchtraffic --initialize-target-sequences

Result:

E0927 17:03:49.970158   71538 main.go:56] rpc error: code = Unknown desc = failed to get the sequence information in the customer keyspace: invalid sequence column vindex name  defined in sequence table column_vindexes:{name:"hash" columns:"product_id"} auto_increment:{column:"product_id" sequence:"product_seq"}: UnescapeID err: invalid input identifier ''

Binary Version

❯ vtgate --version
vtgate version Version: 21.0.0-SNAPSHOT (Git revision 670192deda9effd3d7181bc6c2d24d32f9eebe8f branch 'main') built on Fri Sep 27 17:00:16 EDT 2024 by matt@pslord.local using go1.23.1 darwin/arm64

Operating System and Environment details

N/A

Log Fragments

No response