Menu Close

Mariadb主库启用FEDERATED引擎导致从库失效

环境说明:10.5.8-MariaDB-log 主从库

1. 故障现象(SYMPTOMS)

从库 Slave_SQL_Running: No ,即不再应用主库上的变化

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
                Slave_IO_State: Queueing master event to the relay log
                   Master_Host: 172.16.5.70
                   Master_User: repliuser
                   Master_Port: 3306
                 Connect_Retry: 60
               Master_Log_File: mysql-bin.000012
           Read_Master_Log_Pos: 61008868
                Relay_Log_File: mysqld-relay-bin.000032
                 Relay_Log_Pos: 555
         Relay_Master_Log_File: mysql-bin.000012
              Slave_IO_Running: Yes
             Slave_SQL_Running: No
               Replicate_Do_DB: 
           Replicate_Ignore_DB: 
            Replicate_Do_Table: 
        Replicate_Ignore_Table: 
       Replicate_Wild_Do_Table: 
   Replicate_Wild_Ignore_Table: 
                    Last_Errno: 1286
                    Last_Error: Error 'Unknown storage engine 'FEDERATED'' on query. Default database: 'easytong1db'. Query: '/*==============================================================*/
/* Table: SC_CardCode                                           */
/*==============================================================*/
create table SC_CardCode1
(
   CardCode             int not null,
   UseFlag              tinyint not null,
   ReleaseTime          datetime not null,
   ReleaseMode          tinyint not null default 0,
   primary key (CardCode)
)
ENGINE = FEDERATED
CONNECTION='mysql://root:hzxy00yz@172.16.5.70:3306/easytong_0630/SC_CardCode1''
                  Skip_Counter: 0
           Exec_Master_Log_Pos: 20114666
               Relay_Log_Space: 40895067
               Until_Condition: None
                Until_Log_File: 
                 Until_Log_Pos: 0
            Master_SSL_Allowed: No
            Master_SSL_CA_File: 
            Master_SSL_CA_Path: 
               Master_SSL_Cert: 
             Master_SSL_Cipher: 
                Master_SSL_Key: 
         Seconds_Behind_Master: NULL
 Master_SSL_Verify_Server_Cert: No
                 Last_IO_Errno: 0
                 Last_IO_Error: 
                Last_SQL_Errno: 1286
                Last_SQL_Error: Error 'Unknown storage engine 'FEDERATED'' on query. Default database: 'easytong1db'. Query: '/*==============================================================*/
/* Table: SC_CardCode                                           */
/*==============================================================*/
create table SC_CardCode1
(
   CardCode             int not null,
   UseFlag              tinyint not null,
   ReleaseTime          datetime not null,
   ReleaseMode          tinyint not null default 0,
   primary key (CardCode)
)
ENGINE = FEDERATED
CONNECTION='mysql://root:hzxy00yz@172.16.5.70:3306/easytong_0630/SC_CardCode1''
   Replicate_Ignore_Server_Ids: 
              Master_Server_Id: 70
                Master_SSL_Crl: 
            Master_SSL_Crlpath: 
                    Using_Gtid: No
                   Gtid_IO_Pos: 
       Replicate_Do_Domain_Ids: 
   Replicate_Ignore_Domain_Ids: 
                 Parallel_Mode: optimistic
                     SQL_Delay: 0
           SQL_Remaining_Delay: NULL
       Slave_SQL_Running_State: 
              Slave_DDL_Groups: 1
Slave_Non_Transactional_Groups: 0
    Slave_Transactional_Groups: 0
1 row in set (0.000 sec)

2. 变化(CHANGES)

3. 故障原因(CAUSE)

主库增加了 FEDERATED 引擎,而从库却不支持,导致主从复制失效。

4. 解决方案(SOLUTION)

在从库中启用 FEDERATED 引擎。步骤如下:

  • 安装 FederatedX引擎。在 MariaDB 命令行下执行

    install plugin federated soname 'ha_federatedx.so';
  • 停止 MariaDB

    systemctl stop mariadb
  • 修改 /etc/my.cnf 文件,在 [mysqld] 节点下增加如下内容

    federated = 1
  • 最后重新启动 MariaDB

    systemctl start mariadb
  • 查看引擎并开启slave

    MariaDB [(none)]>
    show engines;
    start slave;
    show slave status\G

5. 总结(SUMMARY)

Federate存储引擎也是mysql比较常用的存储引擎,使用它可以访问远程的mysql数据库上的表,这种引擎的作用类似于oracle数据库的dblink,以mysql5.5为例默认是不启用federated引擎的,可以使用 INSTALL PLUGIN plugin_name SONAME 'shared_library_name' 语句动态加载,下面来看看federated引擎的架构:

federated table并不保存数据只有.frm文件,真实的数据存在于远程数据库,访问federated引擎表时本地数据库接受用户SQL请求后使用msyql client c api 的 mysql_real_query() 发送到远程数据库,使用  mysql_store_result() 函数读取远程数据库查询结果.
由于federate不能使用缓存,而且多了网络开销所以他的性能不理想。federated引擎的局限还是比较多的,特别在并发查询的情况下性能下降很快,不适合高并发的环境。