Shopify / ghostferry

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

Fixed nil-pointer exception in sharding #276

Closed shuhaowu closed 3 years ago

shuhaowu commented 3 years ago

In commit f88c58523988b9fc98f14c6a69c138279f257fe6, we stop initializing ferry.ErrorHandler in sharding and copydb and make Ferry.Initialize do it. This triggers a problem where an error can occur before the ErrorHandler is initialized, which results in a nil-pointer exception as sharding uses ferry.ErrorHandler to report this error.

This is fixed here in a non-ideal way, as it's unclear how the ErrorHandler should be initialized. The original intention is that the ErrorHandler should be initialzed only by the application and then passed into Ferry. That said, Ferry still needs a default value for ErrorHandler in case it is not passed in, which would require Ferry to initialize it. Additionally, the Initialize code is structured such that it first performs the sanity check and then initialize all components (incl. the ErrorHandler). So this fix breaks up the code a bit. I'm not sure what the ideal solution is, but this is probably ok for now.

Another thing I changed is to reduce the dependency of the PanicErrorHandler on Ferry. Ideally we can completely get rid of the dependency to make the PanicErrorHandler a component independent of the Ferry, but there's no good way to do that now.