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

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

Closed
mattlord opened this issue Sep 27, 2024 · 0 comments · Fixed by #16862

Comments

@mattlord
Copy link
Contributor

mattlord commented Sep 27, 2024

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"
      }
    },
  1. 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 #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

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

Successfully merging a pull request may close this issue.

1 participant