@@ -485,13 +485,34 @@ private void updateReplConnections(List<InetSocketAddress> addrs) throws IOExcep
485485 // move operation slave -> master.
486486 taskList .add (new MoveOperationTask (
487487 oldSlaveNode , oldMasterNode , false ));
488+ // clear the masterCandidate if the removed slave is the masterCandidate.
489+ if (oldGroup .getMasterCandidate () == oldSlaveNode ) {
490+ oldGroup .clearMasterCandidate ();
491+ }
488492 }
489493 }
490494 } else if (oldSlaveAddrs .contains (newMasterAddr )) {
491495 if (newSlaveAddrs .contains (oldMasterAddr )) {
492496 // Switchover
493- if (oldGroup .getMasterCandidate () != null ) {
497+ MemcachedNode oldMasterCandidate = oldGroup .getMasterCandidate ();
498+ if (oldMasterCandidate != null ) {
499+ ArcusReplNodeAddress masterFromZk = (ArcusReplNodeAddress ) oldGroup
500+ .getSlaveNodeBy (newMasterAddr .getIPPort ()).getSocketAddress ();
494501 changeRoleGroups .add (oldGroup );
502+ if (!masterFromZk .isSameAddress (
503+ ((ArcusReplNodeAddress ) oldMasterCandidate .getSocketAddress ()))) {
504+ /**
505+ * Moves ops from oldMasterCandidate set by cache server to newMasterCandidate.
506+ * Handling the below case.
507+ * old group : [oldMaster, oldSlave1, oldSlave2]
508+ * old group after switchover response :
509+ * [oldMaster, oldSlave1-masterCandidate, oldSlave2]
510+ * new group from zk cache list: [slave1, X, newMaster]
511+ */
512+ oldGroup .setMasterCandidateByAddr (newMasterAddr .getIPPort ());
513+ taskList .add (new MoveOperationTask (
514+ oldMasterCandidate , oldGroup .getMasterCandidate (), false ));
515+ }
495516 } else {
496517 // ZK event occurs before cache server response.
497518 oldGroup .setMasterCandidateByAddr (newMasterAddr .getIPPort ());
0 commit comments