Start with 2 threads in python, Flag is used to record whether the currently running bp node is in the master, if it is true; otherwise it is false
- Continuously monitor the status of the bp-master. If the status is not ok, and the current running node is the master, the thread 1 hangs (con.wait()), and the thread 2 performs the switching;
- Thread 1 continues to perform monitoring to detect the status of the master bp. If the bp_master node is not ok, and the flag bit is false, it indicates that the standby node has been switched to, and no handover is required.
- When thread 1 continues to perform monitoring, if it finds that master is ok, and flag=false, it notifies thread 2 to switch back to master;
- Thread 1 continues to perform monitoring if master ok and flag=true, no switching is required.
After thread 2 gets the global lock: If master_bp is not ok and flag=true, directly select a slave and resume to complete the switch; If master_bp is ok, and flag=false, switch back to the master node;
- First, modify the urls of the master server and the slaver servers in the bp.json file
- Then run the script below:
python bpswitch.py bp.json