{"id":6865,"date":"2014-06-02T10:04:09","date_gmt":"2014-06-02T08:04:09","guid":{"rendered":"http:\/\/code.openark.org\/blog\/?p=6865"},"modified":"2014-06-02T10:04:09","modified_gmt":"2014-06-02T08:04:09","slug":"using-deep-nested-replication-topologies","status":"publish","type":"post","link":"https:\/\/code.openark.org\/blog\/mysql\/using-deep-nested-replication-topologies","title":{"rendered":"Using deep nested replication topologies"},"content":{"rendered":"<p>If you&#8217;re running more than a few slaves in a replication topology, you might choose to use deeply nested replication: slaves replicating from other slaves at 2, 3 or even 4 levels. There are pros and cons to such topologies, discussed below.<\/p>\n<p>A simple, small deep nested topology is depicted below (it is also a real production topology of ours):<\/p>\n<blockquote><p><a href=\"http:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/05\/topology-sample-02.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6878\" src=\"http:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/05\/topology-sample-02.png\" alt=\"topology-sample-02\" width=\"736\" height=\"309\" srcset=\"https:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/05\/topology-sample-02.png 736w, https:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/05\/topology-sample-02-300x125.png 300w\" sizes=\"auto, (max-width: 736px) 100vw, 736px\" \/><\/a><\/p><\/blockquote>\n<p>Two slaves, <strong>srv-4<\/strong> and <strong>srv-8<\/strong> act as local masters to yet other slaves. Why would we want to have this complexity?<\/p>\n<h4>Pros<\/h4>\n<ul>\n<li>Reduce load on master: too many slaves replicating from single master means the master becomes loaded with serving the binary logs. Typically, when all slaves are up to date, this isn&#8217;t a big deal, since they all get served roughly the same entries, and caching works great. If not all are in sync, the master needs to look up different log entries and pays with more disk I\/O.<\/li>\n<li>Reduce network load. We serve from three different data centres. Our master is in one DC, and our slaves are spread through all three. Inter-DC network is naturally slower; it is also more expensive, hence more easily saturated. Reducing cross-DC network is done across all our systems, including MySQL. <strong>srv-4<\/strong>, for example, could depict a slave that is a local master in its own DC, serving <strong>srv-5<\/strong>, <strong>srv-6<\/strong>, <strong>srv-7<\/strong> all in the same DC, hence only using cross-DC network for one slave instead of four. A bit over-simplistic example but true.<\/li>\n<li>Failover. <a href=\"http:\/\/code.google.com\/p\/mysql-master-ha\/\">MHA<\/a> does a good job at synchronizing slaves of same master by figuring out the missing binary log entries for each slave. It should do well within a single region, but I do not know that it would do the same cross region (I&#8217;m assuming the binlog entries copy should work, but I haven&#8217;t tried it cross region). In case of a disaster such as an entire DC going down (we actually had such a case a couple weeks ago; power went out for the entire DC), we have a designated master into which we can fail over in each other DC, and which contains enough slaves (from each remaining DCs) to keep serving. That it, we&#8217;re willing to skip the fancy syncing and just point to a newly promoted master, with the benefit that the entire replication topology under it is intact.<\/li>\n<li>Testing &amp; upgrades. For example, I might want to upgrade to <strong>5.6<\/strong>. Upgrading a slave from <strong>5.5<\/strong> to <strong>5.6<\/strong> is a good start; we look at replication and see that nothing gets broken. But how will our production master behave with <strong>5.6<\/strong>? Put some more slaves under your newly upgraded <strong>5.6<\/strong> server and get a clearer picture. At some stage you might just promote this entire subtree as the new topology.<\/li>\n<\/ul>\n<p>Here&#8217;s another topology; DC info is not depicted in this image, but you can guess what designated masters we have:<!--more--><\/p>\n<blockquote><p><a href=\"http:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/05\/topology-sample-03.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-6881\" src=\"http:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/05\/topology-sample-03.png\" alt=\"topology-sample-03\" width=\"718\" height=\"609\" srcset=\"https:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/05\/topology-sample-03.png 718w, https:\/\/code.openark.org\/blog\/wp-content\/uploads\/2014\/05\/topology-sample-03-300x254.png 300w\" sizes=\"auto, (max-width: 718px) 100vw, 718px\" \/><\/a><\/p><\/blockquote>\n<h4>Cons<\/h4>\n<p>You must be willing to pay the price for the cons. These are:<\/p>\n<ul>\n<li>Accumulated replication lag: a local master that is lagging for some internal problem will cause all of its slaves to implicitly lag, even if those slaves machines aren&#8217;t busy at all.<\/li>\n<li>Corruption: if a local master gets corrupted, so do all of its slaves. This is not a problem if you&#8217;re using GTID. At the time of this writing very few companies I know of are using GTID, even though it&#8217;s been out for over a year. Like many others, we are still using good (?) old binary log file:position coordinates based replication.<\/li>\n<li><del>Complex to maintain<\/del>. Problem solved. The images above are real depictions of our topology (with some details obfuscated or changed). It&#8217;s a <a href=\"http:\/\/d3js.org\/\">D3<\/a> graph that auto presents our topologies. To move slaves around we <em>Drag &amp; Drop them<\/em>. This will shortly be announced as our latest open source release.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re running more than a few slaves in a replication topology, you might choose to use deeply nested replication: slaves replicating from other slaves at 2, 3 or even 4 levels. There are pros and cons to such topologies, discussed below. A simple, small deep nested topology is depicted below (it is also a [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[5],"tags":[8],"class_list":["post-6865","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-replication"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2bZZp-1MJ","_links":{"self":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/6865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/comments?post=6865"}],"version-history":[{"count":13,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/6865\/revisions"}],"predecessor-version":[{"id":6897,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/posts\/6865\/revisions\/6897"}],"wp:attachment":[{"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/media?parent=6865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/categories?post=6865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/code.openark.org\/blog\/wp-json\/wp\/v2\/tags?post=6865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}