Skip to content

Commit

Permalink
GEODE-3052 Need to reset isCoordinator flag in GMSLocator.
Browse files Browse the repository at this point in the history
isCoordinator flag ensures that this process is becoming the
coordinator thus other process should join this process. But
when network parttion happens, we were not resetting this flag.

Now we reset isCoordinator flag when viewCreator thread shutdowns.

added unit test for it.
  • Loading branch information
Hitesh Khamesra committed Jul 14, 2017
1 parent 9905794 commit 15a3b5a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ public Object processRequest(Object request) throws IOException {
logger.info("This member is becoming coordinator");
v = null;
}
logger.debug("this member is becoming coordinator from view {} ", fromView);
}
byte[] coordPk = null;
if (v != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1541,11 +1541,6 @@ private void stopCoordinatorServices() {
if (viewCreator != null && !viewCreator.isShutdown()) {
logger.debug("Shutting down ViewCreator");
viewCreator.shutdown();
org.apache.geode.distributed.internal.membership.gms.interfaces.Locator locator =
services.getLocator();
if (locator != null) {
locator.setIsCoordinator(false);
}
try {
viewCreator.join(1000);
} catch (InterruptedException e) {
Expand Down Expand Up @@ -2209,6 +2204,11 @@ public void run() {
} finally {
shutdown = true;
informToPendingJoinRequests();
org.apache.geode.distributed.internal.membership.gms.interfaces.Locator locator =
services.getLocator();
if (locator != null) {
locator.setIsCoordinator(false);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.geode.distributed.internal.membership.gms.Services.Stopper;
import org.apache.geode.distributed.internal.membership.gms.interfaces.Authenticator;
import org.apache.geode.distributed.internal.membership.gms.interfaces.HealthMonitor;
import org.apache.geode.distributed.internal.membership.gms.interfaces.Locator;
import org.apache.geode.distributed.internal.membership.gms.interfaces.Manager;
import org.apache.geode.distributed.internal.membership.gms.interfaces.Messenger;
import org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorRequest;
Expand Down Expand Up @@ -99,6 +100,7 @@ public class GMSJoinLeaveJUnitTest {
private GMSJoinLeave gmsJoinLeave;
private Manager manager;
private Stopper stopper;
private TestLocator testLocator;
private InternalDistributedMember removeMember = null;
private InternalDistributedMember leaveMember = null;

Expand Down Expand Up @@ -145,6 +147,9 @@ public void initMocks(boolean enableNetworkPartition, boolean useTestGMSJoinLeav
when(services.getManager()).thenReturn(manager);
when(services.getHealthMonitor()).thenReturn(healthMonitor);

testLocator = new TestLocator();
when(services.getLocator()).thenReturn(testLocator);

Timer t = new Timer(true);
when(services.getTimer()).thenReturn(t);

Expand Down Expand Up @@ -172,6 +177,24 @@ public void tearDown() throws Exception {
}
}

static class TestLocator implements Locator {

boolean isCoordinator;

@Override
public void installView(NetView v) {}

@Override
public void setIsCoordinator(boolean isCoordinator) {
this.isCoordinator = isCoordinator;
}

public boolean isCoordinator() {
return isCoordinator;
}

}

@Test
public void testFindCoordinatorInView() throws Exception {
initMocks();
Expand Down Expand Up @@ -1131,9 +1154,12 @@ public void testViewNotSentWhenShuttingDown() throws Exception {
gmsJoinLeave.processMessage(msg);
}

assertTrue(testLocator.isCoordinator);

Awaitility.await("waiting for view creator to stop").atMost(5000, MILLISECONDS)
.until(() -> !gmsJoinLeave.getViewCreator().isAlive());
assertEquals(1, gmsJoinLeave.getView().getViewId());
assertFalse(testLocator.isCoordinator);

} finally {
System.getProperties().remove(GMSJoinLeave.BYPASS_DISCOVERY_PROPERTY);
Expand Down

0 comments on commit 15a3b5a

Please sign in to comment.