MCPcopy Index your code
hub / github.com/Shopify/ghostferry

github.com/Shopify/ghostferry @v1.3.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.3.1 ↗ · + Follow
1,400 symbols 5,515 edges 111 files 149 documented · 11%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Ghostferry

Ghostferry is a library that enables you to selectively copy data from one mysql instance to another with minimal amount of downtime.

It is inspired by Github's gh-ost, although instead of copying data from and to the same database, Ghostferry copies data from one database to another and has the ability to only partially copy data.

There is an example application called ghostferry-copydb included (under the copydb directory) that demonstrates this library by copying an entire database from one machine to another.

Talk to us on IRC at irc.freenode.net #ghostferry.

  • Tutorial and General Documentations: https://shopify.github.io/ghostferry
  • Code documentations: https://godoc.org/github.com/Shopify/ghostferry

Overview of How it Works

An overview of Ghostferry's high-level design is expressed in the TLA+ specification, under the tlaplus directory. It may be good to consult with that as it has a concise definition. However, the specification might not be entirely correct as proofs remain elusive.

On a high-level, Ghostferry is broken into several components, enabling it to copy data. This is documented at https://shopify.github.io/ghostferry/main/technicaloverview.html

Development Setup

Installation

For Internal Contributors

dev up

For External Contributors

  • Have Docker installed
  • Clone the repo
  • docker-compose up -d
  • nix-shell

Testing

Run all tests

  • make test

Run example copydb usage

  • make copydb && ghostferry-copydb -verbose examples/copydb/conf.json
  • For a more detailed tutorial, see the documentation.

Ruby Integration Tests

Kindly take note of following options:

  • DEBUG=1: To see more detailed debug output by Ghostferry live, as opposed to only when the test fails. This is helpful for debugging hanging test.

Examples:

Run all tests

rake test

Run a single file

rake test TEST=test/integration/trivial_test.rb

or

ruby -Itest test/integration/trivial_test.rb

Run a specific test

DEBUG=1 ruby -Itest test/integration/trivial_test.rb -n "TrivialIntegrationTest#test_logged_query_omits_columns"

Releasing new version

Canary

Tag your commit with canary/* and push, i.e.

git tag --sign --message="Initial support for UUIDs as pagination keys" canary/v1.1.2-uuid-pagination-keys-alpha-1
git push origin --tags

This will create the release named by tag.

Production

Final releases are created automatically on merge to main branch, they will end up with release-SHA name.

Remember to update version prior to bigger releases in Makefile along with updating the CHANGELOG.md.

Extension points exported contracts — how you extend this code

Verifier (Interface)
The sole purpose of this interface is to make it easier for one to implement their own strategy for verification and hoo [3 …
verifier.go
Logger (Interface)
Logger is the interface for structured logging throughout ghostferry. It is designed to be backend-agnostic, allowing sw [2 …
logger.go
DataIteratorSorter (Interface)
DataIteratorSorter is an interface for the DataIterator to choose which order it will process table [2 implementers]
data_iterator_sorter.go
SqlPreparer (Interface)
both `sql.Tx` and `sql.DB` allow a SQL query to be `Prepare`d [2 implementers]
cursor.go
PaginationKey (Interface)
PaginationKey represents a cursor position for paginating through table rows. It abstracts over different primary key ty [2 …
pagination_key.go
CopyFilter (Interface)
CopyFilter provides an interface for restricting the copying to a subset of data. This typically involves adding a WHERE [1 …
filter.go
ErrorHandler (Interface)
(no doc) [2 implementers]
error_handler.go
DataWriter (Interface)
(no doc) [2 implementers]
testhelpers/data_writer.go

Core symbols most depended-on inside this repo

query
called by 193
test/helpers/db_helper.rb
Error
called by 133
logger.go
Errorf
called by 133
logger.go
Exec
called by 117
sqlwrapper/ghostferry_db.go
String
called by 80
pagination_key.go
on_status
called by 77
test/helpers/ghostferry_helper.rb
WithError
called by 74
logger.go
PanicIfError
called by 74
testhelpers/helper_methods.go

Shape

Method 908
Function 316
Struct 128
Class 21
TypeAlias 14
Interface 13

Languages

Go86%
Ruby14%

Modules by API surface

dml_events.go55 symbols
test/go/logger_test.go45 symbols
test/go/iterative_verifier_test.go38 symbols
test/go/table_schema_cache_test.go37 symbols
inline_verifier.go37 symbols
ferry.go36 symbols
test/go/pagination_key_test.go35 symbols
iterative_verifier.go34 symbols
config.go34 symbols
pagination_key.go33 symbols
test/integration/inline_verifier_test.rb31 symbols
logger.go28 symbols

For agents

$ claude mcp add ghostferry \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact