Shopify / ghostferry

The swiss army knife of live data migrations
https://shopify.github.io/ghostferry
MIT License
694 stars 65 forks source link

Corruption when using FallbackColumn in sharding #287

Closed tiwilliam closed 3 years ago

tiwilliam commented 3 years ago

Resolving #285.

After optimizing ShardedCopyFilter.BuildSelect a while back we switched to using a sub-select.

This new select works fine in most cases, as long as you don't try to paginate using something other than the primary key. When trying to paginate using a non-primary key it will return columns in an order which is different from the table schema. Ghostferry have before this bug was detected assumed that data is read and written in the table structure column order. But since USING(FallbackColumn) will put FallbackColumn first in the result set, it will confuse Ghostferry and lose track of which value needs to go where since the batch writer only have access to the table structure column order. The inline verifier caught this and crashed Ghostferry correctly.

This PR resolves this by passing the column order in the RowBatch struct. Making it possible for the batch writer to generate a correct INSERT query. This allow us to do changes to our queries fetching data without having to be too careful with in which order columns are returned.