[toc]

The foreword 0.

Due to the introduction of the MGR ARBITRATOR node (voting node, ARBITRATOR) feature in GreatSQL 8.0.27, mysql-shell provided by MySQL cannot recognize this feature, so mysql-shell for GreatSQL is provided.

1. Modify the description

Need to modify mysql-shell source code, add support for arbitration node (voting node) role type, involving two files:

  • mysqlshdk/libs/mysql/group_replication.h
  • Mysqlshdk/libs/mysql/group_replication. Cc inMember_roleAdd to objectARBITRATORThe role type is sufficient. The entire patch file is just 35 lines long and simple:
$cat mysqlsh - for - greatsql - 8.0.27. Patch diff - git a/mysqlshdk/libs/mysql/group_replication cc b/mysqlshdk/libs/mysql/group_replication.cc index ef6a8e1b9.. 9edbab628 100644 --- a/mysqlshdk/libs/mysql/group_replication.cc +++ b/mysqlshdk/libs/mysql/group_replication.cc @@ -108,6 +108,8 @@std ::string to_string(const Member_role role) {return "PRIMARY"; case Member_role::SECONDARY: return "SECONDARY"; + case Member_role::ARBITRATOR: + return "ARBITRATOR"; case Member_role::NONE: return "NONE"; } @@-119,6 +121,8 @@member_role to_member_role(const STD ::string &role) {return Member_role::PRIMARY; } else if (shcore::str_casecmp("SECONDARY", role.c_str()) == 0) { return Member_role::SECONDARY; + } else if (shcore::str_casecmp("ARBITRATOR", role.c_str()) == 0) { + return Member_role::ARBITRATOR; } else if (role.empty()) { return Member_role::NONE; } else { diff --git a/mysqlshdk/libs/mysql/group_replication.h b/mysqlshdk/libs/mysql/group_replication.h index c76385e4b.. 100644 - a / 1 d957eae5 mysqlshdk/libs/mysql/group_replication h + + + b/mysqlshdk/libs/mysql/group_replication. @ @ h - 73, 7 + 75,7 @@enum class Member_state {MISSING}; -enum class Member_role { PRIMARY, SECONDARY, NONE }; +enum class Member_role { PRIMARY, SECONDARY, ARBITRATOR, NONE }; enum class Topology_mode { SINGLE_PRIMARY, MULTI_PRIMARY, NONE };Copy the code

2. Compile mysql – shell

Cmakelists. TXT file is required to be manually modified. I have already submitted the bug (#106730), just upgrade to 8.0.28.

Official reference documents github.com/mysql/mysql… The version is too old (last updated Aug 19, 2020) and almost completely unavailable.

I’ll have to find out for myself.

2.1 Environment Preparation

Download several related installation packages:

  • Protobuf – all – 3.11.4. Tar. Gz, github.com/protocolbuf…
  • Mysql – 8.0.27. Tar. Gz, downloads.mysql.com/archives/co…
  • Mysql – the shell – 8.0.27 – SRC. Tar. Gz, downloads.mysql.com/archives/sh…
  • Boost_1_73_0. Tar. Gz, boostorg. Jfrog. IO/artifactory…
  • Patchelf – 0.14.5. Tar. Gz, github.com/NixOS/patch…
  • RPCSVC – proto, github.com/thkukuk/rpc…

Mysql > create a CentOS 8 docker image using the following Dockerfile:

FROM docker.io/arm64v8/centos RUN rm -f /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Linux-AppStream.repo /etc/yum.repos.d/CentOS-Linux-BaseOS.repo && \ curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo && \ sed - I - e - e '/ mirrors.cloud.aliyuncs.com/d' '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo RUN yum install -y epel-release && \ yum clean all && \ yum makecache RUN yum install -y --skip-broken yum-utils wget diffutils net-tools vim git gcc gcc-c++ automake libtool cmake  cmake3 \ make psmisc openssl openssl-devel zlib-devel readline-devel bzip2-devel expat-devel \ bison flex wget unzip libcurl-devel libevent-devel libffi-devel lz4-devel \ file clang bzip2 libxml2-devel libtirpc libtirpc-devel numactl-devel numactl-libs \ numactl openldap-devel openldap-clients pam-devel valgrind boost-devel \ libzstd libzstd-devel patchelf perl perl-Env perl-JSON perl-Memoize perl-Time-HiRes time libaio-devel libarchive \ ncurses-devel  ncurses-libs pam redhat-lsb-core scl-utils-build pkg-config ccache \ jemalloc jemalloc-devel libicu-devel re2-devel redhat-lsb-core rpm* tar libssh \ cyrus-sasl-devel cyrus-sasl-scram python36 python36-devel RUN dnf install -y dnf RUN dnf install -y gcc-toolset-10 && source /opt/rh/gcc-toolset-10/enable RUN echo 'source /opt/rh/gcc-toolset-10/enable' >> Bash_profile # Patchelf COPY PatchELf-0.14.5.tar. gz/TMP / #rpcsvc-proto COPY rpcsvc-proto-1.4.tar.gz / TMP /rpcsvc-proto-1.4.tar.gz COPY boost_1_73_0.tar.gz /opt/ RUN rm -fr/TMP /*Copy the code

Next is to make docker image package, and then start a Docker container, detailed process method can refer to this article: homemade GreatSQL Docker image.

After starting the container, copy the downloaded installation packages to the /opt/ directory in the container and decompress them:

drwxr-xr-x 8 root root 65536 Apr 22 2020 boost_1_73_0 -rw------- 1 root root 128699082 Dec 7 08:34 boost_1_73_0.tar.gz Drwxr-xr-x 31 7161 31415 65536 Mar 15 06:30 mysql-8.0.27-rw-r --r-- 1 root root 285550905 Mar 15 06:12 Drwxr-xr-x 17 root root 65536 Mar 15 07:12 mysql-shell 8.0.27-src-rw-r --r-- 1 root root 81013338 Mar 15 06:12 mysql-shell-8.0.27-src.tar. gz-rw-r --r-- 1 root root 1372 Mar 15 06:12 mysqlsh-for-greatSQL-8.0.27. patch -rw-r--r-- 1 root root 313132 Mar 16 09:26 PatchELF-0.14.5-x86_64.tar. gz drwxr-xr-x 18 411487 89939 65536 Mar 15 07:00 Protobuf-3.11.4-rw-r --r-- 1 root root 7408292 Mar 15 06:12 protobuf-all-3.11.4.tar.gz drwxr-xr-x 3 root root 28 Mar 15 06:01 RH drwxr-xr-x 4 1000 Users 65536 Mar 15 06:29 Rpcsvc-proto-1.4-RW-r --r-- 1 root root 149354 Dec 7 08:23 RPCSVC proto - 1.4. Tar. GzCopy the code

Next, compile and install several dependency packages:

$CD /opt/protobuf-3.11.4./autogen.sh &&./configure && make && make install $CD /opt/rpcsvc-proto-1.4./configure && make && make installCopy the code

2.2 Compiling mysql & mysql-shell

Mysql > install mysql-shell mysql > install mysql-shell

CD /opt/mysql -8.0.27&& rm -fr BLD && mkdir BLD && CD BLD && cmake.. -DBOOST_INCLUDE_DIR=/opt/boost_1_73_0/ \ -DLOCAL_BOOST_DIR=/opt/boost_1_73_0/ \ -DWITH_SSL=system && \ cmake --build . --target mysqlclient; \ cmake --build. --target mysqlxClient && CD /opt/mysql-shell-8.0.27-src && rm -fr BLD && mkdir BLD && CD BLD && \ cmake .. \ - DCMAKE_INSTALL_PREFIX = / usr/local/mysql - the shell - 8.0.27-18 - Linux - glibc2.28 - x86_64 \ - DMYSQL_SOURCE_DIR = / opt/mysql - 8.0.27 \ -dmysql_build_dir =/opt/mysql-8.0.27/ BLD / \ -dhave_python =1 -dwith_protobuf =bundled && \ make -j64 && make installCopy the code

The binaries will be installed in /usr/local/mysql-shell-8.0.27-18-linux-glibc2.28-x86_64.

2.3 Using Patchelf to modify the mysqlsh binary File

Mysql > select * from mysqlsh binaries; mysql > select * from mysqlsh binaries;

$CD /usr/local/mysql-shell-8.0.27-18-linux-glibc2.28-x86_64 $LDD bin/mysqlsh linux-vdso.so.1 (0x00007ffd3adce000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f96f73a8000) ... libprotobuf.so.22 => not found ...Copy the code

This is because the libprotobuf.so.22 dynamic library file is in /usr/local/lib/ and cannot be found.

In this case, we can use Patchelf to change the dependency path from absolute path to relative path in mysqlsh:

- first of all, $PWD /usr/local/mysql-shell-8.0.27-18-linux-glibc2.28-x86_64 $mkdir -p lib/private - copy the libprotobuf file to $ Cp/usr/local/lib/libprotobuf. So the 22.0.4 lib/private - do a soft link $CD lib/private / $ln -s libprotobuf. So. 22.0.4 Mysqlsh CD /usr/local/mysql-shell-8.0.27-18-linux-glibc2.28-x86_64 $patchelf --set-rpath '$ORIGIN/.. /lib/private' ./bin/mysqlsh $ ldd bin/mysqlsh cd .. /.. [root@mysqlsh-c8 mysql-shell-8.0.27-18-linux-glibc2.28-x86_64]# LDD bin/mysqlsh linux-vdso.so1 (0x00007ffec77e1000)...  Libprotobuf. So. = > 22 / usr/local/mysql - the shell - 8.0.27-18 - Linux - glibc2.28 - x86_64 / bin /.. /lib/private/libprotobuf.so.22 (0x00007f2b8a5db000)Copy the code

Mysqlsh can find the libprotobuf dynamic library file and use it properly.

3. Run mysql-shell for GreatSQL

If you want the mysql-shell to support JavaScript syntax, you need to add libv8 to the compile, but it’s too difficult, SO I’ll just give it up…

Js syntax is not supported, but Python syntax is supported. Here are some common examples:

Js grammar Py grammar
$ var c=dba.getCluster() $c=dba.get_cluster()
c.status() c.statsu()
c.setPrimaryInstance() c.set_primary_instance()
c.switchToMultiPrimaryMode() c.switch_to_multi_primary_mode()
c.rebootClusterFromCompleteOutage() c.reboot_cluster_from_complete_outage()

As you can see, it’s just a slight difference in grammar style.

Now you can play with the new quorum node feature in GreatSQL 8.0.27:

MySQL 172.16.16.12:33060+ SSL Py > c.status() {"clusterName": "GreatSQL8027", "defaultReplicaSet": {"name": "Default" and "primary", "172.16.16.12:3306", "SSL" : "REQUIRED", "status" : "OK," "statusText" : "Cluster is ONLINE and can tolerate up to ONE failure.", "Topology ": {"172.16.16.10:3306": {"address": "172.16.16.10:3306", "memberRole": "ARBITRATOR", <-- Arbitration node "mode": "R/O", "readReplicas": {}, "replicationLag": Null, "role" : "HA", "status" : "ONLINE", "version" : "8.0.27"}, "172.16.16.11:3306" : {" address ": "172.16.16.11:3306", "memberRole": "SECONDARY", <-- SECONDARY node "mode": "R/O", "readReplicas": {}, "replicationLag": "00:00:00. 001422", "role" : "HA", "status" : "ONLINE", "version" : "8.0.27"}, "172.16.16.12:3306" : {" address ": "172.16.16.12:3306", "memberRole": "PRIMARY", <-- PRIMARY node "mode": "R/W", "readReplicas": {}, "replicationLag": Null, "role" : "HA", "status" : "ONLINE", "version" : "8.0.27}}", "topologyMode" : "Single - Primary"}, "groupInformationSourceMember" : "172.16.16.12:3306"}Copy the code

By the way, the first time you start mysqlsh, you might get something like the following:

WARNING: Found errors loading plugins, for more details look at the log at: /root/.mysqlsh/mysqlsh.log
Copy the code

Simply install the Python module Certifi by executing the following instructions:

$ pip3.6 install --user certifi
Copy the code

Ok, start feeling the magic of the MGR arbitration node

P.s1: This is the emergency version of Old Ye’s last-minute cramming. There may be many imperfections, but the official version will be released later.

PS2: GreatSQL 8.0.27 and 5.7.36 will be released soon, please be patient. In addition, if you want to use MGR, it is strongly recommended to use version 8.0 rather than 5.7, which is much better than 5.7 in terms of functionality and reliability.

In this paper, to the end.

Enjoy GreatSQL 🙂