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 MoveTables target sequence initialization fails when a shard has no rows in the using table #15295

Closed
mattlord opened this issue Feb 20, 2024 · 0 comments · Fixed by #15289

Comments

@mattlord
Copy link
Contributor

Overview of the Issue

When moving tables from an unsharded keyspace to a sharded one, the management of sequences during the traffic switch can be cumbersome and challenging -- which is why we added to support to automatically manage this in #13656

However, if one or more of the shards have no records in the table using the sequence then the sequence initialization step will fail as it tries to covert NULL to an int.

Reproduction Steps

git checkout main && make build

pushd ${VTROOT}/examples/local

./101_initial_cluster.sh

mysql < ../common/insert_commerce_data.sql

mysql commerce -e "insert into customer (customer_id, email) values (99999, 'mlord@planetscale.com')" --binary-as-hex=false

vtctldclient --server localhost:15999 CreateKeyspace --durability-policy=semi_sync customer || fail "Failed to create and configure the commerce keyspace"

./301_customer_sharded.sh; ./302_new_shards.sh

sleep 30

vtctldclient ApplySchema --sql-file create_customer_sharded.sql customer

mysql commerce -e "select * from customer order by customer_id" --binary-as-hex=false
mysql commerce -e "select * from customer_seq" --binary-as-hex=false

vtctldclient MoveTables --target-keyspace customer --workflow commerce2customer create --tables 'customer,corder' --source-keyspace commerce

sleep 30

mysql customer -e "select * from customer order by customer_id" --binary-as-hex=false

# Delete the record that is on the 80- shard
primaryuid=$(vtctldclient GetTablets --keyspace customer --tablet-type primary --shard "80-" | awk '{print $1}' | cut -d- -f2 | bc)
command mysql -u root --socket=${VTDATAROOT}/vt_0000000${primaryuid}/mysql.sock --binary-as-hex=false vt_customer -e "delete from vt_customer.customer"

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

Binary Version

vtgate version Version: 20.0.0-SNAPSHOT (Git revision af3809949587dd4c03673880ec46365339dfd522 branch 'main') built on Tue Feb 20 07:14:25 EST 2024 by matt@pslord.local using go1.22.0 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