Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix potential deadlock when switching master frequently
Currently, the replication thread will wait for the worker exclusive guard stop before closing the db. But it now stops the worker from running new commands after acquiring the worker exclusive guard, and it might cause deadlock if switches at the same time. The following steps will show how it may happen: - T0: client A sent `slaveof MASTER_IP0 MASTER_PORT0`, then the replication thread was started and waiting for the exclusive guard. - T1: client B sent `slaveof MASTER_IP1 MASTER_PORT1` and `AddMaster` will stop the previous replication thread, which is waiting for the exclusive guard. But the exclusive guard is acquiring by the current thread. And the workaround is also straightforward, just stop workers from running new commands by enabling `is_loading_` to true before acquiring the lock in replication thread.
- Loading branch information