Page MenuHomePhabricator
Paste P96521

(An Untitled Masterwork)
ActivePublic

Authored by CWilliams-WMF on Thu, Sep 24, 7:53 AM.
Project Tags
None
Referenced Files
F104573643: raw-paste-data.txt
Thu, Sep 24, 7:53 AM
Subscribers
None
#!/usr/bin/env python3
def get_needs_retry(expected, status):
return [
key for key in ["Slave_IO_Running", "Slave_SQL_Running"]
if status[key] != expected[key] and status[key] in ["Connecting", "Preparing", "No"]
]
expected = {
"Master_Host": "host1",
"Master_User": "user1",
"Master_Port": 3306,
"Slave_IO_Running": "Yes",
"Slave_SQL_Running": "Yes",
"Last_IO_Errno": 0,
"Last_SQL_Errno": 0,
}
status = {
"Master_Host": "host1",
"Master_User": "user1",
"Master_Port": 3306,
"Slave_IO_Running": "No",
"Slave_SQL_Running": "No",
"Last_IO_Errno": 0,
"Last_SQL_Errno": 0,
}
print("Neither thread running")
print(f"{get_needs_retry(expected, status)}\n")
status = {
"Master_Host": "host1",
"Master_User": "user1",
"Master_Port": 3306,
"Slave_IO_Running": "Connecting",
"Slave_SQL_Running": "No",
"Last_IO_Errno": 0,
"Last_SQL_Errno": 0,
}
print("IO thread connnecting")
print(f"{get_needs_retry(expected, status)}\n")
status = {
"Master_Host": "host1",
"Master_User": "user1",
"Master_Port": 3306,
"Slave_IO_Running": "Preparing",
"Slave_SQL_Running": "No",
"Last_IO_Errno": 0,
"Last_SQL_Errno": 0,
}
print("IO thread preparing")
print(f"{get_needs_retry(expected, status)}\n")
status = {
"Master_Host": "host1",
"Master_User": "user1",
"Master_Port": 3306,
"Slave_IO_Running": "Yes",
"Slave_SQL_Running": "No",
"Last_IO_Errno": 0,
"Last_SQL_Errno": 0,
}
print("IO thread running, SQL thread stopped")
print(f"{get_needs_retry(expected, status)}\n")
status = {
"Master_Host": "host1",
"Master_User": "user1",
"Master_Port": 3306,
"Slave_IO_Running": "Yes",
"Slave_SQL_Running": "Preparing",
"Last_IO_Errno": 0,
"Last_SQL_Errno": 0,
}
print("SQL thread preparing")
print(f"{get_needs_retry(expected, status)}\n")
status = {
"Master_Host": "host1",
"Master_User": "user1",
"Master_Port": 3306,
"Slave_IO_Running": "Yes",
"Slave_SQL_Running": "Yes",
"Last_IO_Errno": 0,
"Last_SQL_Errno": 0,
}
print("Both threads running")
print(f"{get_needs_retry(expected, status)}\n")

Event Timeline

❯ python3 /tmp/test.py
Neither thread running
['Slave_IO_Running', 'Slave_SQL_Running']

IO thread connnecting
['Slave_IO_Running', 'Slave_SQL_Running']

IO thread preparing
['Slave_IO_Running', 'Slave_SQL_Running']

IO thread running, SQL thread stopped
['Slave_SQL_Running']

SQL thread preparing
['Slave_SQL_Running']

Both threads running
[]