-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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: Cannot create a JSON value from a string with CHARACTER SET 'binary' in online ddl #13986
Comments
@vitessio/online-ddl |
@olyazavr There's no v18 yet, which specific commit / sha is this?
@mattlord It seems like there's an incorrect vitess/go/vt/vttablet/onlineddl/vrepl.go Lines 497 to 498 in 794b912
I think that logic just needs to be dropped entirely, since the JSON marshaller already does the right thing and this wrapping breaks stuff. |
Hi, this is from commit e7c0bb07ac, I pulled from main a couple of days ago |
vitess/go/vt/vttablet/onlineddl/vrepl.go Lines 497 to 498 in 794b912
Hmm, this is weird. This logic deals with column names from what I can see, not column values but for some reason we wrap a column value here 😕. No other usages of |
I'm encountering something very bizarre. I made the fix in v18 to not have that extra convert and it's a valid mysql query and yet:
if you run from the general log, that is exactly what it's doing, but rolling back:
I even added a log line into ExecuteFetch, to ensure the query and the error matched what was being reported to me, and they did as an aside, I can also repro this in v14, before the JSON_OBJECT overhaul, where it fails to run this migration and the query it fails on is valid: |
Wondering if changing the generated column query to something like, will help, in case the issue is with how MySQL internally processes json for generated columns.
|
I haven't dug deeply into the discussion yet, but just off the tip of my head:
|
On $ mysql
mysql> CREATE TABLE `orders` (
-> `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
-> `orderPaymentMethod` json DEFAULT NULL,
-> `stripePaymentMethod` tinyint(4) GENERATED ALWAYS AS (json_unquote(json_extract(`orderPaymentMethod`,'$.paymentMethod'))) STORED,
-> PRIMARY KEY (`id`)
-> ) ENGINE=InnoDB;
Query OK, 0 rows affected (0.06 sec)
mysql> insert into orders(orderPaymentMethod) values (convert('{\"customerId\": \"cus_Il7WwbIODMoaE1\"}' using utf8mb4))
-> ;
Query OK, 1 row affected (0.01 sec)
mysql> ^DBye
$ vtctldclient ApplySchema --ddl-strategy="online --postpone-completion" --sql "ALTER TABLE orders ENGINE=INNODB;" commerce
ee4facd6_57c6_11ee_a929_0a43f95f28a3
$ vtctldclient OnlineDDL complete commerce all
{
"rows_affected_by_shard": {
"0": "1"
}
}
|
Huh, I need to go back and retry my v18 migration then. I only have tablets in v18, not vtgates or vtctld, but that shouldn't matter because vreplication/onlineddl is all at the tablet level. Out of curiosity, what MySQL version are you running? We're on 5.7 and from a few bug reports, it seems like some json-related pain is fixed in 8 |
I'll also test out that workaround Rohit suggested |
I was testing with |
Ok so I tested with mysql 8 and my migration worked, even the v14 version, and also Rohit's workaround works (with 5.7 and v14) - but would require us to change the schemas of everyone with json generated columns. I also tested changing the line that does So perhaps this is a mysql 5.7 + |
I can confirm the issue reproduces on > select * from _vt.schema_migrations order by id desc limit 1\G
id: 1
migration_uuid: 31085363_583a_11ee_b258_0a43f95f28a3
keyspace: commerce
shard: 0
mysql_schema: vt_commerce
mysql_table: orders
migration_statement: alter table orders ENGINE INNODB
strategy: online
options: --postpone-completion
added_timestamp: 2023-09-21 04:49:04
requested_timestamp: 2023-09-21 04:49:05
ready_timestamp: NULL
started_timestamp: 2023-09-21 04:49:06
liveness_timestamp: 2023-09-21 04:49:06
completed_timestamp: 2023-09-21 04:49:09.949121
cleanup_timestamp: NULL
migration_status: failed
log_path:
artifacts: _31085363_583a_11ee_b258_0a43f95f28a3_20230921044905_vrepl,
retries: 0
tablet: zone1-0000000101
tablet_failure: 0
progress: 0
migration_context: vtctl:31076797-583a-11ee-b258-0a43f95f28a3
ddl_action: alter
message: task error: failed inserting rows: Cannot create a JSON value from a string with CHARACTER SET 'binary'. (errno 3144) (sqlstate
22032) during query: insert into _31085363_583a_11ee_b258_0a43f95f28a3_20230921044905_vrepl(id,orderPaymentMethod) values (1,convert(JSON_OBJECT(_utf8mb4'custome
rId', _utf8mb4'cus_Il7WwbIODMoaE1') using utf8mb4))
eta_seconds: -1
rows_copied: 0
table_rows: 1
added_unique_keys: 0
removed_unique_keys: 0
log_file:
retain_artifacts_seconds: 86400
postpone_completion: 1
removed_unique_key_names:
dropped_no_default_column_names:
expanded_column_names:
revertible_notes:
allow_concurrent: 0
reverted_uuid:
is_view: 0
ready_to_complete: 0
vitess_liveness_indicator: 1695271746 |
It does look like vitess is doing all the necessary casting for the query to be successful: convert(JSON_OBJECT(_utf8mb4'customerId', _utf8mb4'cus_Il7WwbIODMoaE1') using utf8mb4) and the problem will not reproduce is there's no |
I see, that would be quite difficult for us to implement because we'd have to run migrations (non-vitess) on every table that has a json column and a generated column (I don't know how many there are, but given we have over a thousand keyspaces, and teams can design schemas as they like, it's possible this is a large number). Is there nothing else we could do? Perhaps a condition on the |
Let me look into that, and build a test case. |
Heh I found another bug with JSON, though unrelated to this: #14089 |
Is this still an issue on main? I thought that we had fixed this, but perhaps not. |
Overview of the Issue
When running a Vitess onlineddl schema migration with json generated columns, the migration fails in the copy phase with
Cannot create a JSON value from a string with CHARACTER SET 'binary'
Reproduction Steps
Create table:
Insert:
Note that if
orderPaymentMethod
is null here, the error does not surface, nor does it surface if there are no json generated columnsRun migration:
See failures:
Binary Version
Operating System and Environment details
Log Fragments
No response
The text was updated successfully, but these errors were encountered: