How do we make the following transactions atomic?
conn - is a connection to the old primary, which is being reset as replica now.
Python code
conn.execute('unlock tables')
conn.cursor().execute('stop slave')
conn.cursor().execute('reset master')
conn.autocommit = True
is set during conn
declaration
While running these commands. As soon as I run unlock tables
on old primary, due to stale connections there could be some transactions written to old primary database. Which are being purged when we run reset master
. These are audit transactions and not of much significance. However, before demoting primary to slave we need to make sure absolutely no transactions are written even if there are stale connections or DNS cache resolves to old primary.
Is there any way to run these commands atomic ? for example
conn.cursor().execute("unlock tables; stop slave; reset master", multi=True)
Would this ensure no transactions are written while we open up database to run command to stop slave and reset master ?
To lock database completely we need to run "Flush tables with read lock" (FTWRL). However, if we have FTWRL, we can't run write commands like stop slave.
lock tables
,stop slave
,reset master
aren't transaction capable. Only insert/delete/update/replace/select and the like are.