{"id":314,"date":"2018-03-01T18:55:50","date_gmt":"2018-03-01T18:55:50","guid":{"rendered":"https:\/\/www.appsolem.nl\/?p=314"},"modified":"2021-01-30T10:17:23","modified_gmt":"2021-01-30T11:17:23","slug":"mysql-group-replication-check","status":"publish","type":"post","link":"https:\/\/appsolem.nl\/?p=314","title":{"rendered":"MySQL Group replication check"},"content":{"rendered":"<p>Running MySQL in a Kubernetes environment means that as soon as the container is started the Service will start using it. With Group Replication enabled this means it will start using the instance while its still &#8216;recovering&#8217; . So I made this little bash script which you can use as a <a href=\"https:\/\/kubernetes.io\/docs\/tasks\/configure-pod-container\/configure-liveness-readiness-probes\/\">Readiness probe<\/a>. It checks two things with one small sql query. First if its online, and second if there are 2 or more members (hopefully preventing split brain scenarios).<\/p>\n<p><code><br \/>\n<strong>group_ready_check.sh: |<\/strong><\/code><\/p>\n<p>#Pass &#8220;password&#8221; as parameter<br \/>\nip=$(ip route get 1 | awk &#8216;{print $NF;exit}&#8217;)<br \/>\nstate=&#8221;$(mysql -N -B -p@1 -e &#8220;SELECT * FROM performance_schema.replication_group_members WHERE MEMBER_STATE=&#8217;ONLINE'&#8221; 2&gt;\/dev\/null)&#8221;<br \/>\nif ([ &#8220;$(grep -c &#8220;$ip&#8221; &lt;&lt;&lt; &#8220;$state&#8221;)&#8221; -ge 1 ]) &amp;&amp; ([ &#8220;$(grep -c &#8216;^&#8217; &lt;&lt;&lt; &#8220;$state&#8221;)&#8221; -ge 2 ]); then<br \/>\nexit 0<br \/>\nelse<br \/>\nexit 1<br \/>\nfi<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Running MySQL in a Kubernetes environment means that as soon as the container is started the Service will start using [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/appsolem.nl\/index.php?rest_route=\/wp\/v2\/posts\/314"}],"collection":[{"href":"https:\/\/appsolem.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/appsolem.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/appsolem.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/appsolem.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=314"}],"version-history":[{"count":1,"href":"https:\/\/appsolem.nl\/index.php?rest_route=\/wp\/v2\/posts\/314\/revisions"}],"predecessor-version":[{"id":413,"href":"https:\/\/appsolem.nl\/index.php?rest_route=\/wp\/v2\/posts\/314\/revisions\/413"}],"wp:attachment":[{"href":"https:\/\/appsolem.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=314"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/appsolem.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=314"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/appsolem.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=314"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}