[MCOL-4556] master detection not work properly in cmapi Created: 2021-02-24  Updated: 2021-06-28  Resolved: 2021-03-09

Status: Closed
Project: MariaDB ColumnStore
Component/s: cmapi
Affects Version/s: None
Fix Version/s: cmapi-1.3

Type: Bug Priority: Major
Reporter: Richard Stracke Assignee: Todd Stoffel (Inactive)
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Relates
relates to MCOL-4763 CMAPI status shows wrong node as mast... Closed

 Description   

Hello,

cmapi detects master with

SELECT VARIABLE_VALUE FROM information_schema.GLOBAL_STATUS WHERE VARIABLE_NAME = 'SLAVE_CONNECTIONS';

SLAVE_CONNECTIONS is defined as

"Number of REGISTER_SLAVE attempts. In practice the number of times slaves has tried to connect to the master. "

https://mariadb.com/kb/en/replication-and-binary-log-status-variables/#slave_connections

It is a counter, which will not be reseted, if the server is no master anymore, so this will not safely detects a master.

 
# returns a pair of bools
# the first indicates whether the node is the master
# the second indicates if the calling functions retry loop should continue
def _is_master(node, root):
    ces_node = root.find("./CrossEngineSupport")
    username = ces_node.find("./User").text
    password = ces_node.find("./Password").text
 
    if username is None:
        return False, False
 
    cmd = (f"mariadb -h {node} -u '{username}' --password='{password}' -sN -e \
            \"SELECT VARIABLE_VALUE FROM information_schema.GLOBAL_STATUS WHERE VARIABLE_NAME = 'SLAVE_CONNECTIONS';\"")
 
    ret = subprocess.run(cmd, stdout=subprocess.PIPE, shell = True)
    if ret.returncode == 0:
        response = ret.stdout.decode("utf-8").strip()
        if response > '0':
            return True, False
    else:
        return False, False
    return False, True

Maybe the suggestion from Todd in MCOL-4289 is more safe,

SELECT COUNT(1) AS `slave_threads`
 
FROM `information_schema`.`PROCESSLIST`
 
WHERE `USER`='system user'
 
  AND `COMMAND` LIKE 'Slave%';



 Comments   
Comment by Richard Stracke [ 2021-02-26 ]

SLAVE_CONNECTIONS counts calls of COM_REGISTER_SLAVE,

// Some comments here
public String getFoo()
{
    return foo;
}

Added here;

661a6d8

I see no codepart, where it ever will be decreased, also reset status; will not help.

COM_REGISTER_SLAVE

Generated at Thu Feb 08 02:51:14 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.