@@ -324,13 +324,34 @@ func (c *Canal) WaitUntilPos(pos mysql.Position, timeout time.Duration) error {
324324 }
325325}
326326
327- func (c * Canal ) GetMasterPos () (mysql.Position , error ) {
328- showBinlogStatus := "SHOW BINARY LOG STATUS"
329- if eq , err := c .conn .CompareServerVersion ("8.4.0" ); (err == nil ) && (eq < 0 ) {
330- showBinlogStatus = "SHOW MASTER STATUS"
327+ // getShowBinaryLogQuery returns the correct SQL statement to query binlog status
328+ // for the given database flavor and server version.
329+ //
330+ // Sources:
331+ //
332+ // MySQL: https://dev.mysql.com/doc/relnotes/mysql/8.4/en/news-8-4-0.html
333+ // MariaDB: https://mariadb.com/kb/en/show-binlog-status
334+ func getShowBinaryLogQuery (flavor , serverVersion string ) string {
335+ switch flavor {
336+ case mysql .MariaDBFlavor :
337+ eq , err := mysql .CompareServerVersions (serverVersion , "10.5.2" )
338+ if (err == nil ) && (eq >= 0 ) {
339+ return "SHOW BINLOG STATUS"
340+ }
341+ case mysql .MySQLFlavor :
342+ eq , err := mysql .CompareServerVersions (serverVersion , "8.4.0" )
343+ if (err == nil ) && (eq >= 0 ) {
344+ return "SHOW BINARY LOG STATUS"
345+ }
331346 }
332347
333- rr , err := c .Execute (showBinlogStatus )
348+ return "SHOW MASTER STATUS"
349+ }
350+
351+ func (c * Canal ) GetMasterPos () (mysql.Position , error ) {
352+ query := getShowBinaryLogQuery (c .cfg .Flavor , c .conn .GetServerVersion ())
353+
354+ rr , err := c .Execute (query )
334355 if err != nil {
335356 return mysql.Position {}, errors .Trace (err )
336357 }
0 commit comments