gh-ost icon indicating copy to clipboard operation
gh-ost copied to clipboard

BUG (?) wrong data type in JSON data after alter table .

Open barucho opened this issue 6 years ago • 4 comments

we are facing an issue after an alter of a JSON column. after the alter completed we found wrong data types in the JSON data:

  • data after the alter :
oot@localhost(mysql-0a.96):[gallery]> select date_updated,JSON_EXTRACT(metadata, '$.photoMetadata.focalPoint.x') from gallery.items_v2 where gallery_id = '61482ce3-9431-407c-8bc7-ad7408e1ff38';
+---------------------+--------------------------------------------------------+
| date_updated        | JSON_EXTRACT(metadata, '$.photoMetadata.focalPoint.x') |
+---------------------+--------------------------------------------------------+
| 2019-12-20 13:14:14 | "0.5"                                                  |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:46 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
+---------------------+--------------------------------------------------------+
14 rows in set (0.00 sec)

  • where befor the alter the data was (this is from snapshot of the database befor the alter table )
(tbd-mysql.42) [gallery]> select date_updated,JSON_EXTRACT(metadata, '$.photoMetadata.focalPoint.x') from gallery.items_v2 where gallery_id = '61482ce3-9431-407c-8bc7-ad7408e1ff38';
+---------------------+--------------------------------------------------------+
| date_updated        | JSON_EXTRACT(metadata, '$.photoMetadata.focalPoint.x') |
+---------------------+--------------------------------------------------------+
| 2019-12-20 13:14:14 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:46 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
| 2019-12-20 13:12:45 | 0.5                                                    |
+---------------------+--------------------------------------------------------+
14 rows in set (0.17 sec)
  • As you can see the FLOAT in the JSON converted into STRING
  • versions :
> select @@version
    -> ;
+------------+
| @@version  |
+------------+
| 5.7.20-log |
+------------+
1 row in set (0.00 sec)
:~ # gh-ost --version
1.0.48

Thanks

barucho avatar Jan 01 '20 18:01 barucho

First impression is that the go-mysql library causes this issue. I'm wondering:

  1. Is the rest of the JSON correct?
  2. This specific row has a different timestamp than others. Can you confirm this row was inserted/updated during gh-ost's runtime? As opposed to other rows existing in the table before gh-ost runtime?

shlomi-noach avatar Jan 02 '20 08:01 shlomi-noach

  • this is the JSON before the alter (from snapshot backup)
{"name": "8b070d_54451f2f2bf74eaaaf3a774e0048099b~mv2_d_5369_3579_s_4_2.jpg", "tags": [], "title": "IMG_4864", "mediaUrl": "https://static.wixstatic.com/media/8b070d_54451f2f2bf74eaaaf3a774e0048099b~mv2_d_5369_3579_s_4_2.jpg/v1/fill/w_5369,h_3579,al_c,q_90/8b070d_54451f2f2bf74eaaaf3a774e0048099b~mv2_d_5369_3579_s_4_2.jpg", "mediaOwner": "Undefined", "photoMetadata": {"width": 5369, "height": 3579, "focalPoint": {"x": 0.5, "y": 0.5}}}
  • this is after
{"name": "8b070d_54451f2f2bf74eaaaf3a774e0048099b~mv2_d_5369_3579_s_4_2.jpg", "tags": [], "title": "IMG_4864", "mediaUrl": "https://static.wixstatic.com/media/8b070d_54451f2f2bf74eaaaf3a774e0048099b~mv2_d_5369_3579_s_4_2.jpg/v1/fill/w_5369,h_3579,al_c,q_90/8b070d_54451f2f2bf74eaaaf3a774e0048099b~mv2_d_5369_3579_s_4_2.jpg", "mediaOwner": "Undefined", "photoMetadata": {"width": 5369, "height": 3579, "focalPoint": {"x": "0.5", "y": "0.5"}}}

as you can see the only change is the value of "x" and "y" of "focalPoint" from FLOAT to STRING

  1. I don't think that this specific row changed during the gh-ost run time because the update time is the same before the run and after the run. the example is a different row with the same gallery id that only one got effected by the alter we found 500 more rows that got changed. this is a 700M row table that only 500 got changed by the alter.

barucho avatar Jan 02 '20 11:01 barucho

@timvaillancourt I ran into this on version 1.1.2 of gh-ost and just validated that it also exists on version 1.1.7.

The table that I'm altering is on AWS RDS MySQL and the ALTER statement is about a different column than the JSON column that gets "corrupted". I see that for the "corrupted" rows the first property in the JSON column changes from number to string (eg. 20.5 becomes "20.5"). I see that for both integers as decimals. The same thing happens with the first property in the only nested object in that JSON column. There are other properties in the JSON column that are numerical, but they stay numerical. There is also another JSON column in those rows but that one seem unaffected. That could also be because the first property of (nested) objects is not numerical.

Skipping the user, password, host, database, table, alter and serve-socket-file CLI flags, my gh-ost command is as follows:

gh-ost \
  --chunk-size=1000 \
  --nice-ratio=6 \
  --allow-on-master \
  --replica-server-id=1000000001 \
  --quiet \
  --cut-over=default \
  --concurrent-rowcount \
  --default-retries=120 \
  --initially-drop-ghost-table \
  --initially-drop-old-table \
  --ok-to-drop-table \
  --execute \
  --assume-rbr

I am able to replicate this consistently. The way I do is by adding --postpone-cut-over-flag-file=/tmp/gh-ost.cut-over and letting it run for a while. I then see in the _gho table that the number of rows on which this plays up increases over time, I think related to when those rows are updated by other database connections.

The output of gh-ost doesn't tell me much, but for completeness (redacted some values with xxx):

[2025/05/27 16:49:14] [info] binlogsyncer.go:173 create BinlogSyncer with config {ServerID:1000000001 Flavor:mysql Host:xxx Port:3306 User:xxx Password: Localhost: Charset: SemiSyncEnabled:false RawModeEnabled:false TLSConfig:<nil> ParseTime:false TimestampStringLocation:UTC UseDecimal:true RecvBufferSize:0 HeartbeatPeriod:0s ReadTimeout:0s MaxReconnectAttempts:0 DisableRetrySync:false VerifyChecksum:false DumpCommandFlag:0 Option:<nil> Logger:0x14000129140 Dialer:0x104758310 RowsEventDecodeFunc:<nil> DiscardGTIDSet:false}
[2025/05/27 16:49:14] [info] binlogsyncer.go:410 begin to sync binlog from position (mysql-bin-changelog.046975, 11841499)
[2025/05/27 16:49:14] [info] binlogsyncer.go:813 rotate to (mysql-bin-changelog.046975, 11841499)
# Migrating `xxx`.`xxx`; Ghost table is `xxx`.`_xxx_gho`
# Migrating ip-xxx:3306; inspecting ip-xxx:3306; executing on xxx
# Migration started at Tue May 27 16:49:13 +0200 2025
# chunk-size: 1000; max-lag-millis: 1500ms; dml-batch-size: 10; max-load: ; critical-load: ; nice-ratio: 6.000000
# throttle-additional-flag-file: /tmp/gh-ost.throttle 
# postpone-cut-over-flag-file: /tmp/gh-ost.cut-over [set]
# Serving on unix socket: /tmp/gh-ost.sock
Copy: 0/1095 0.0%; Applied: 0; Backlog: 0/1000; Time: 3s(total), 0s(copy); streamer: mysql-bin-changelog.046975:11959379; Lag: 0.22s, HeartbeatLag: 0.22s, State: migrating; ETA: N/A
Copy: 1000/1095 91.3%; Applied: 1; Backlog: 9/1000; Time: 4s(total), 1s(copy); streamer: mysql-bin-changelog.046975:13234498; Lag: 0.04s, HeartbeatLag: 0.07s, State: migrating; ETA: due
Copy: 1000/1095 91.3%; Applied: 1; Backlog: 22/1000; Time: 5s(total), 2s(copy); streamer: mysql-bin-changelog.046975:13292006; Lag: 0.04s, HeartbeatLag: 0.07s, State: migrating; ETA: due
Copy: 1000/1095 91.3%; Applied: 1; Backlog: 35/1000; Time: 6s(total), 3s(copy); streamer: mysql-bin-changelog.046975:13335360; Lag: 0.04s, HeartbeatLag: 0.07s, State: migrating; ETA: due
Copy: 1000/1095 91.3%; Applied: 21; Backlog: 20/1000; Time: 7s(total), 4s(copy); streamer: mysql-bin-changelog.046975:13460150; Lag: 0.04s, HeartbeatLag: 0.07s, State: migrating; ETA: due
Copy: 1231/1095 112.4%; Applied: 59; Backlog: 1/1000; Time: 8s(total), 5s(copy); streamer: mysql-bin-changelog.046975:13733423; Lag: 0.04s, HeartbeatLag: 0.07s, State: migrating; ETA: due
Copy: 1231/1095 112.4%; Applied: 59; Backlog: 7/1000; Time: 9s(total), 6s(copy); streamer: mysql-bin-changelog.046975:13799489; Lag: 0.04s, HeartbeatLag: 0.07s, State: migrating; ETA: due
Copy: 1231/1231 100.0%; Applied: 78; Backlog: 0/1000; Time: 9s(total), 6s(copy); streamer: mysql-bin-changelog.046975:13901069; Lag: 0.04s, HeartbeatLag: 0.08s, State: migrating; ETA: due
Copy: 1231/1231 100.0%; Applied: 81; Backlog: 8/1000; Time: 10s(total), 6s(copy); streamer: mysql-bin-changelog.046975:13950633; Lag: 0.04s, HeartbeatLag: 0.07s, State: postponing cut-over; ETA: due
Copy: 1231/1231 100.0%; Applied: 100; Backlog: 0/1000; Time: 11s(total), 6s(copy); streamer: mysql-bin-changelog.046975:14044174; Lag: 0.04s, HeartbeatLag: 0.07s, State: postponing cut-over; ETA: due
Copy: 1231/1231 100.0%; Applied: 101; Backlog: 15/1000; Time: 12s(total), 6s(copy); streamer: mysql-bin-changelog.046975:14098164; Lag: 0.04s, HeartbeatLag: 0.07s, State: postponing cut-over; ETA: due
Copy: 1231/1231 100.0%; Applied: 129; Backlog: 2/1000; Time: 13s(total), 6s(copy); streamer: mysql-bin-changelog.046975:14243829; Lag: 0.04s, HeartbeatLag: 0.07s, State: postponing cut-over; ETA: due
Copy: 1231/1231 100.0%; Applied: 139; Backlog: 0/1000; Time: 14s(total), 6s(copy); streamer: mysql-bin-changelog.046975:14330647; Lag: 0.04s, HeartbeatLag: 0.07s, State: postponing cut-over; ETA: due
Copy: 1231/1231 100.0%; Applied: 150; Backlog: 12/1000; Time: 15s(total), 6s(copy); streamer: mysql-bin-changelog.046975:14402291; Lag: 0.04s, HeartbeatLag: 0.07s, State: postponing cut-over; ETA: due
Copy: 1231/1231 100.0%; Applied: 180; Backlog: 2/1000; Time: 16s(total), 6s(copy); streamer: mysql-bin-changelog.046975:14554369; Lag: 0.04s, HeartbeatLag: 0.07s, State: postponing cut-over; ETA: due
Copy: 1231/1231 100.0%; Applied: 190; Backlog: 0/1000; Time: 17s(total), 6s(copy); streamer: mysql-bin-changelog.046975:14634538; Lag: 0.04s, HeartbeatLag: 0.07s, State: postponing cut-over; ETA: due
Copy: 1231/1231 100.0%; Applied: 196; Backlog: 11/1000; Time: 18s(total), 6s(copy); streamer: mysql-bin-changelog.046975:14702002; Lag: 0.04s, HeartbeatLag: 0.07s, State: postponing cut-over; ETA: due
Copy: 1231/1231 100.0%; Applied: 210; Backlog: 12/1000; Time: 19s(total), 6s(copy); streamer: mysql-bin-changelog.046975:14796694; Lag: 0.04s, HeartbeatLag: 0.07s, State: postponing cut-over; ETA: due
Copy: 1231/1231 100.0%; Applied: 227; Backlog: 1/1000; Time: 20s(total), 6s(copy); streamer: mysql-bin-changelog.046975:14875188; Lag: 0.04s, HeartbeatLag: 0.07s, State: postponing cut-over; ETA: due
Copy: 1231/1231 100.0%; Applied: 239; Backlog: 0/1000; Time: 21s(total), 6s(copy); streamer: mysql-bin-changelog.046975:14954310; Lag: 0.04s, HeartbeatLag: 0.07s, State: postponing cut-over; ETA: due
Copy: 1231/1231 100.0%; Applied: 253; Backlog: 2/1000; Time: 22s(total), 6s(copy); streamer: mysql-bin-changelog.046975:15059324; Lag: 0.04s, HeartbeatLag: 0.07s, State: postponing cut-over; ETA: due
Copy: 1231/1231 100.0%; Applied: 268; Backlog: 1/1000; Time: 23s(total), 6s(copy); streamer: mysql-bin-changelog.046975:15141017; Lag: 0.04s, HeartbeatLag: 0.07s, State: postponing cut-over; ETA: due

I also tried with --charset="utf8mb4_general_ci,utf8_general_ci,latin1" but that makes no difference

As gh-ost corrupts our data because of this bug, it is of quite high importance for us. If I can help debugging please let me know how.

everhardt avatar May 27 '25 14:05 everhardt

Tagging @meiji163 as I have not seen @timvaillancourt in this repo anymore since August 2024.

everhardt avatar May 27 '25 15:05 everhardt