apecloud / myduckserver

MySQL & Postgres Analytics, Reimagined
184 stars 8 forks source link

fix: be compatible with 'show slave status' #127

Closed VWagen1989 closed 2 weeks ago

VWagen1989 commented 2 weeks ago

This PR addresses the issue of compatibility with older applications that use 'SHOW SLAVE STATUS' to retrieve the replication status, like MaxScale.

The approach is intercepting the request and modify it to 'SHOW REPLICA STATUS' before sending to real backend. And then it add a result modifier to change the terms in resultset schema to the old fashion ones before sending back to client.

Before

mysql> SHOW SLAVE STATUS;                                             
ERROR 1105 (HY000): syntax error at position 11 near 'SLAVE'                                                                                                                                                                                                                             

After

mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 127.0.0.1
                  Master_User: lol
                  Master_Port: 33306
                Connect_Retry: 60
              Master_Log_File: INVALID
          Read_Master_Log_Pos: 0
               Relay_Log_File: NULL
                Relay_Log_Pos: NULL
        Relay_Master_Log_File: INVALID
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: NULL
          Replicate_Ignore_DB: NULL
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: NULL
  Replicate_Wild_Ignore_Table: NULL
                   Last_Errno: 1105
                   Last_Error: Applying query failed: Operation CREATE USER failed for 'admin'@'%'
                 Skip_Counter: NULL
          Exec_Master_Log_Pos: 0
              Relay_Log_Space: NULL
              Until_Condition: None
               Until_Log_File: NULL
                Until_Log_Pos: NULL
           Master_SSL_Allowed: Ignored
           Master_SSL_CA_File: NULL
           Master_SSL_CA_Path: NULL
              Master_SSL_Cert: NULL
            Master_SSL_Cipher: NULL
          Master_SSL_CRL_File: NULL
          Master_SSL_CRL_Path: NULL
               Master_SSL_Key: NULL
Master_SSL_Verify_Server_Cert: NULL
        Seconds_Behind_Master: 0
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 1105
               Last_SQL_Error: Applying query failed: Operation CREATE USER failed for 'admin'@'%'
  Replicate_Ignore_Server_Ids: NULL
             Master_Server_Id: 
                  Master_UUID: fb3fbb0b-9b59-11ef-bb14-0242ac110008
             Master_Info_File: NULL
                    SQL_Delay: 0
          SQL_Remaining_Delay: 0
      Slave_SQL_Running_State: NULL
           Master_Retry_Count: 86400
                  Master_Bind: NULL
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: Thu Nov  7 17:54:26 CST 2024
           Retrieved_Gtid_Set: fb3fbb0b-9b59-11ef-bb14-0242ac110008:1-19:21
            Executed_Gtid_Set: fb3fbb0b-9b59-11ef-bb14-0242ac110008:1-19:21
                Auto_Position: 1
         Replicate_Rewrite_DB: NULL
1 row in set (0.01 sec)

And the resultset of SHOW REPLICA STATUS remains what it should be:

mysql> SHOW REPLICA STATUS\G                                                                                                                                                                                                                                                             
*************************** 1. row ***************************                                                                                                                                                                                                                           
             Replica_IO_State:                                                                                                                                                                                                                                                           
                  Source_Host: 127.0.0.1                                                                                                                                                                                                                                                 
                  Source_User: lol                                                                                                                                                                                                                                                       
                  Source_Port: 33306                                                                                                                                                                                                                                                     
                Connect_Retry: 60                                                                                                                                                                                                                                                        
              Source_Log_File: INVALID                                                                                                                                                                                                                                                   
          Read_Source_Log_Pos: 0                                                                                                                                                                                                                                                         
               Relay_Log_File: NULL                                                                                                                                                                                                                                                      
                Relay_Log_Pos: NULL                                                                                                                                                                                                                                                      
        Relay_Source_Log_File: INVALID                                                                                                                                                                                                                                                   
           Replica_IO_Running: Yes                                                                                                                                                                                                                                                       
          Replica_SQL_Running: Yes                                                                                                                                                                                                                                                       
              Replicate_Do_DB: NULL                                                                                                                                                                                                                                                      
          Replicate_Ignore_DB: NULL                                                                                                                                                                                                                                                      
           Replicate_Do_Table:                                                                                                                                                                                                                                                           
       Replicate_Ignore_Table:                                                                                                                                                                                                                                                           
      Replicate_Wild_Do_Table: NULL                                                                                                                                                                                                                                                      
  Replicate_Wild_Ignore_Table: NULL                                                                                                                                                                                                                                                      
                   Last_Errno: 1105                                                                                                                                                                                                                                                      
                   Last_Error: Applying query failed: Operation CREATE USER failed for 'admin'@'%'                                                                                                                                                                                       
                 Skip_Counter: NULL                                                                                                                                                                                                                                                      
          Exec_Source_Log_Pos: 0                                                                                                                                                                                                                                                         
              Relay_Log_Space: NULL                                                                                                                                                                                                                                                      
              Until_Condition: None                                                                                                                                                                                                                                                      
               Until_Log_File: NULL                                                                                                                                                                                                                                                      
                Until_Log_Pos: NULL                                                                                                         
           Source_SSL_Allowed: Ignored                                                                                                                                                                                                                                                   
           Source_SSL_CA_File: NULL                                   
           Source_SSL_CA_Path: NULL                                                                                                                                                                                                                                                      
              Source_SSL_Cert: NULL                                                                                                         
            Source_SSL_Cipher: NULL                                                                                                                                                                                                                                                      
          Source_SSL_CRL_File: NULL                                                                                                                                                                                                                                                      
          Source_SSL_CRL_Path: NULL                                                                                                                                                                                                                                                      
               Source_SSL_Key: NULL                                                                                                                                                                                                                                                      
Source_SSL_Verify_Server_Cert: NULL                                                                                                                                                                                                                                                      
        Seconds_Behind_Source: 0                                                                                                                                                                                                                                                         
                Last_IO_Errno: 0                                                                                                                                                                                                                                                         
                Last_IO_Error:                                        
               Last_SQL_Errno: 1105                                   
               Last_SQL_Error: Applying query failed: Operation CREATE USER failed for 'admin'@'%'                                                                                                                                                                                       
  Replicate_Ignore_Server_Ids: NULL                                                                                                                                                                                                                                                      
             Source_Server_Id:                                                                                                                                                                                                                                                           
                  Source_UUID: fb3fbb0b-9b59-11ef-bb14-0242ac110008   
             Source_Info_File: NULL                                   
                    SQL_Delay: 0                                                                                                                                                                                                                                                         
          SQL_Remaining_Delay: 0                                      
    Replica_SQL_Running_State: NULL                                                                                                                                                                                                                                                      
           Source_Retry_Count: 86400                                                                                                                                                                                                                                                     
                  Source_Bind: NULL                                                                                                                                                                                                                                                      
      Last_IO_Error_Timestamp:                                                                                                              
     Last_SQL_Error_Timestamp: Wed Nov  6 17:44:24 CST 2024                                                                                                                                                                                                                              
           Retrieved_Gtid_Set: fb3fbb0b-9b59-11ef-bb14-0242ac110008:1-19:21                                                                 
            Executed_Gtid_Set: fb3fbb0b-9b59-11ef-bb14-0242ac110008:1-19:21                                                                                                                                                                                                              
                Auto_Position: 1                                                                                                                                                                                                                                                         
         Replicate_Rewrite_DB: NULL                                                                                                         
1 row in set (0.00 sec)