MySQL: An Online Schema Change Tool from Facebook
Most of the NoSQL databases are schema-less (key-value stores, document databases, and graph databases) or allow to (easily) update their schemas. On the other hand, updating relational databases schema can be a challenging operation.
Facebook has ☞ open sourced a tool used internally for online (nb as in no downtime required) MySQL schema updates.
OSC (Online Schema Change) algorithms typically have several phases:
- copy - where they make a copy of the table
- build - where they work on the copy until the copy is ready with the new schema
- replay - where they propagate the changes that happened on the original table to the copy table. This assumes that there is a mechanism for capturing changes.
- cut-over - where they switch the tables ie rename the copy table as original. There is typically small amount of downtime while switching the tables. A small amount of replay is also typically needed during the cut-over.
Note that the above operations can be done within the storage engine itself, or using an external (PHP) script. We followed the latter approach as it can be implemented much faster. An advantage of doing within storage engine is some optimizations can be done that are not available while doing these operations externally.
Quite smart!
Original title and link: MySQL: An Online Schema Change Tool from Facebook (NoSQL databases © myNoSQL)