mysql replication handling in go

1,045 views
Skip to first unread message

Sathish VJ

unread,
May 12, 2015, 10:04:21 AM5/12/15
to golan...@googlegroups.com
I'm doing some research on mysql replication.  How does my go code change to handle that?

Right now I'm connecting to the server once for the entire app.  Will that have to change in any way?  

Kevin Malachowski

unread,
May 13, 2015, 5:56:57 PM5/13/15
to golan...@googlegroups.com
I'm not exactly sure what you mean.

Are you asking whether the Go code (via the database/sql package) for connecting/using a MySQL master is different than the code for connecting/using a MySQL slave? If so, then no, you still connect to and use the slave just like you would the master. The only caveat is that you should only read from slaves and write only to the Master.

If you expect one single program to talk to both the master and the slave then sharing a single sql.DB object from a single call to sql.Open will not work. You'll have to manage two database connections: one for reads/writes to the master and another for read-only operations.

Tim Hawkins

unread,
May 14, 2015, 1:09:12 AM5/14/15
to Kevin Malachowski, golan...@googlegroups.com
A common pattern used in larger system is to direct all writes to the master but load balance the reads to the slaves (with the proviso that if you readback a write you do it on the master) hence its common to have a class that handles that, which encompasses two connections, one for read and one for write. 

Alternatively you can put a query proxy in place that handles that for you, examples are sql-relay 


Sql relay sits in-front of your replicated cluster and routes queries according to certain rules. It also supports load balancing and fail-over.  

There is a "C" binding library that could easily be wrapped for go. 


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

ca...@doxsey.net

unread,
May 14, 2015, 9:19:11 AM5/14/15
to golan...@googlegroups.com, cho...@google.com
Or vitess: http://vitess.io/.

anthony....@kudo.co.id

unread,
Mar 12, 2018, 12:01:27 PM3/12/18
to golang-nuts
Reply all
Reply to author
Forward
0 new messages