Skip to content

Instantly share code, notes, and snippets.

@mattlord
Last active December 6, 2023 23:05
Show Gist options
  • Save mattlord/73ae73ffcc3df427652249b3b8a42217 to your computer and use it in GitHub Desktop.
Save mattlord/73ae73ffcc3df427652249b3b8a42217 to your computer and use it in GitHub Desktop.
VStream VEvent Test of ENUMs

Setup the test env:

git checkout main && make build

pushd examples/local

./101_initial_cluster.sh

mysql < ../common/insert_commerce_data.sql

vtctldclient ApplySchema --ddl-strategy=direct --sql "alter table customer add size enum ('small', 'medium', 'large') default 'medium'" commerce

Modify the vstream_client example to stream everything from the customer table in the unsharded commerce keyspace:

diff --git a/examples/local/vstream_client.go b/examples/local/vstream_client.go
index 98d2129f89..939178159f 100644
--- a/examples/local/vstream_client.go
+++ b/examples/local/vstream_client.go
@@ -38,7 +38,7 @@ import (
 */
 func main() {
        ctx := context.Background()
-       streamCustomer := true
+       streamCustomer := false
        var vgtid *binlogdatapb.VGtid
        if streamCustomer {
                vgtid = &binlogdatapb.VGtid{

In another Terminal, start a vtgate VStream of the customer table. It will start with the copy phase and then continue on in the running/replicating phase:

cd ${VTROOT}/examples/local

go run vstream_client.go

Generate some more data now that the vstream is past the copy phase and in the running/replicating phase:

mysql commerce
# ... perform inserts, updates, deletes against the customer table

Clean up:

./401_teardown.sh
popd

Sample results:

[type:BEGIN  keyspace:"commerce"  shard:"0" type:FIELD  field_event:{table_name:"commerce.customer"  fields:{name:"customer_id"  type:INT64  table:"customer"  org_table:"customer"  database:"vt_commerce"  org_name:"customer_id"  column_length:20  charset:63  flags:49667  column_type:"bigint"}  fields:{name:"email"  type:VARBINARY  table:"customer"  org_table:"customer"  database:"vt_commerce"  org_name:"email"  column_length:128  charset:63  flags:128  column_type:"varbinary(128)"}  fields:{name:"size"  type:ENUM  table:"customer"  org_table:"customer"  database:"vt_commerce"  org_name:"size"  column_length:24  charset:255  flags:256  column_type:"enum('small','medium','large')"}  keyspace:"commerce"  shard:"0"}  keyspace:"commerce"  shard:"0"]
[type:VGTID  vgtid:{shard_gtids:{keyspace:"commerce"  shard:"0"  gtid:"MySQL56/f9370c8c-9484-11ee-a06b-d03490376450:1-62"}}  keyspace:"commerce"  shard:"0"]
[type:ROW  row_event:{table_name:"commerce.customer"  row_changes:{after:{lengths:1  lengths:16  lengths:6  values:"1alice@domain.commedium"}}  keyspace:"commerce"  shard:"0"}  keyspace:"commerce"  shard:"0" type:ROW  row_event:{table_name:"commerce.customer"  row_changes:{after:{lengths:1  lengths:14  lengths:6  values:"2bob@domain.commedium"}}  keyspace:"commerce"  shard:"0"}  keyspace:"commerce"  shard:"0" type:ROW  row_event:{table_name:"commerce.customer"  row_changes:{after:{lengths:1  lengths:18  lengths:6  values:"3charlie@domain.commedium"}}  keyspace:"commerce"  shard:"0"}  keyspace:"commerce"  shard:"0" type:ROW  row_event:{table_name:"commerce.customer"  row_changes:{after:{lengths:1  lengths:14  lengths:6  values:"4dan@domain.commedium"}}  keyspace:"commerce"  shard:"0"}  keyspace:"commerce"  shard:"0" type:ROW  row_event:{table_name:"commerce.customer"  row_changes:{after:{lengths:1  lengths:14  lengths:6  values:"5eve@domain.commedium"}}  keyspace:"commerce"  shard:"0"}  keyspace:"commerce"  shard:"0" type:VGTID  vgtid:{shard_gtids:{keyspace:"commerce"  shard:"0"  gtid:"MySQL56/f9370c8c-9484-11ee-a06b-d03490376450:1-62"  table_p_ks:{table_name:"customer"  lastpk:{fields:{name:"customer_id"  type:INT64  charset:63  flags:49667}  rows:{lengths:1  values:"5"}}}}}  keyspace:"commerce"  shard:"0" type:COMMIT  keyspace:"commerce"  shard:"0"]
[type:BEGIN  keyspace:"commerce"  shard:"0" type:VGTID  vgtid:{shard_gtids:{keyspace:"commerce"  shard:"0"  gtid:"MySQL56/f9370c8c-9484-11ee-a06b-d03490376450:1-62"}}  keyspace:"commerce"  shard:"0" type:COMMIT  keyspace:"commerce"  shard:"0"]
[type:COPY_COMPLETED  keyspace:"commerce"  shard:"0" type:COPY_COMPLETED]
[type:BEGIN  timestamp:1701901111  current_time:1701901111210764000  keyspace:"commerce"  shard:"0" type:FIELD  timestamp:1701901111  field_event:{table_name:"commerce.customer"  fields:{name:"customer_id"  type:INT64  table:"customer"  org_table:"customer"  database:"vt_commerce"  org_name:"customer_id"  column_length:20  charset:63  flags:49667  column_type:"bigint"}  fields:{name:"email"  type:VARBINARY  table:"customer"  org_table:"customer"  database:"vt_commerce"  org_name:"email"  column_length:128  charset:63  flags:128  column_type:"varbinary(128)"}  fields:{name:"size"  type:ENUM  table:"customer"  org_table:"customer"  database:"vt_commerce"  org_name:"size"  column_length:24  charset:255  flags:256  column_type:"enum('small','medium','large')"}  keyspace:"commerce"  shard:"0"}  current_time:1701901111213501000  keyspace:"commerce"  shard:"0" type:ROW  timestamp:1701901111  row_event:{table_name:"commerce.customer"  row_changes:{after:{lengths:1  lengths:21  lengths:1  values:"6mlord@planetscale.com1"}}  keyspace:"commerce"  shard:"0"  flags:1}  current_time:1701901111213523000  keyspace:"commerce"  shard:"0" type:VGTID  vgtid:{shard_gtids:{keyspace:"commerce"  shard:"0"  gtid:"MySQL56/f9370c8c-9484-11ee-a06b-d03490376450:1-63"}}  keyspace:"commerce"  shard:"0" type:COMMIT  timestamp:1701901111  current_time:1701901111213534000  keyspace:"commerce"  shard:"0"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment