Search in sources :

Example 11 with InstallViewMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage in project geode by apache.

the class GMSJoinLeave method sendView.

private boolean sendView(NetView view, boolean preparing, ViewReplyProcessor viewReplyProcessor) throws InterruptedException {
    int id = view.getViewId();
    InstallViewMessage msg = new InstallViewMessage(view, services.getAuthenticator().getCredentials(this.localAddress), preparing);
    Set<InternalDistributedMember> recips = new HashSet<>(view.getMembers());
    // a recent member was seen not to receive a new view - I think this is why
    // recips.removeAll(newMembers); // new members get the view in a JoinResponseMessage
    // no need to send it to ourselves
    recips.remove(this.localAddress);
    Set<InternalDistributedMember> responders = recips;
    if (!view.getCrashedMembers().isEmpty()) {
        recips = new HashSet<>(recips);
        recips.addAll(view.getCrashedMembers());
    }
    if (preparing) {
        this.preparedView = view;
    } else {
        // if another server is the coordinator - GEODE-870
        if (isCoordinator && !localAddress.equals(view.getCoordinator()) && getViewCreator() != null) {
            markViewCreatorForShutdown = true;
            this.isCoordinator = false;
        }
        installView(view);
    }
    if (recips.isEmpty()) {
        if (!preparing) {
            logger.info("no recipients for new view aside from myself");
        }
        return true;
    }
    logger.info((preparing ? "preparing" : "sending") + " new view " + view);
    msg.setRecipients(recips);
    Set<InternalDistributedMember> pendingLeaves = getPendingRequestIDs(LEAVE_REQUEST_MESSAGE);
    Set<InternalDistributedMember> pendingRemovals = getPendingRequestIDs(REMOVE_MEMBER_REQUEST);
    pendingRemovals.removeAll(view.getCrashedMembers());
    viewReplyProcessor.initialize(id, responders);
    viewReplyProcessor.processPendingRequests(pendingLeaves, pendingRemovals);
    addPublicKeysToView(view);
    services.getMessenger().send(msg);
    // only wait for responses during preparation
    if (preparing) {
        logger.debug("waiting for view responses");
        Set<InternalDistributedMember> failedToRespond = viewReplyProcessor.waitForResponses();
        logger.info("finished waiting for responses to view preparation");
        InternalDistributedMember conflictingViewSender = viewReplyProcessor.getConflictingViewSender();
        NetView conflictingView = viewReplyProcessor.getConflictingView();
        if (conflictingView != null) {
            logger.warn("received a conflicting membership view from " + conflictingViewSender + " during preparation: " + conflictingView);
            return false;
        }
        if (!failedToRespond.isEmpty() && (!services.getCancelCriterion().isCancelInProgress())) {
            logger.warn("these members failed to respond to the view change: " + failedToRespond);
            return false;
        }
    }
    return true;
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) HashSet(java.util.HashSet)

Example 12 with InstallViewMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage in project geode by apache.

the class GMSJoinLeaveJUnitTest method testBecomeParticipantThroughViewChange.

@Test
public void testBecomeParticipantThroughViewChange() throws Exception {
    initMocks();
    prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId));
    NetView oldView = gmsJoinLeave.getView();
    oldView.add(gmsJoinLeaveMemberId);
    InternalDistributedMember creator = oldView.getCreator();
    GMSJoinLeaveTestHelper.becomeCoordinatorForTest(gmsJoinLeave);
    NetView view = new NetView(2, gmsJoinLeave.getView().getViewId() + 1);
    view.setCreator(creator);
    view.add(creator);
    view.add(gmsJoinLeaveMemberId);
    InstallViewMessage msg = getInstallViewMessage(view, creator, false);
    msg.setSender(creator);
    gmsJoinLeave.processMessage(msg);
    assertTrue("Expected it to stop being coordinator", !gmsJoinLeave.isCoordinator());
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 13 with InstallViewMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage in project geode by apache.

the class GMSJoinLeaveJUnitTest method testNetworkPartitionDetected.

@Test
public void testNetworkPartitionDetected() throws IOException {
    initMocks(true);
    prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId));
    // set up a view with sufficient members, then create a new view
    // where enough weight is lost to cause a network partition
    List<InternalDistributedMember> mbrs = new LinkedList<>();
    mbrs.add(mockMembers[0]);
    mbrs.add(mockMembers[1]);
    mbrs.add(mockMembers[2]);
    mbrs.add(gmsJoinLeaveMemberId);
    ((GMSMember) mockMembers[1].getNetMember()).setMemberWeight((byte) 20);
    NetView newView = new NetView(mockMembers[0], gmsJoinLeave.getView().getViewId() + 1, mbrs);
    InstallViewMessage installViewMessage = getInstallViewMessage(newView, credentials, false);
    gmsJoinLeave.processMessage(installViewMessage);
    Set<InternalDistributedMember> crashes = new HashSet<>();
    crashes.add(mockMembers[1]);
    crashes.add(mockMembers[2]);
    mbrs = new LinkedList<>(mbrs);
    mbrs.remove(mockMembers[1]);
    mbrs.remove(mockMembers[2]);
    NetView partitionView = new NetView(mockMembers[0], newView.getViewId() + 1, mbrs, Collections.emptySet(), crashes);
    installViewMessage = getInstallViewMessage(partitionView, credentials, false);
    gmsJoinLeave.processMessage(installViewMessage);
    verify(manager).forceDisconnect(isA(String.class));
    verify(manager).quorumLost(crashes, newView);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) NetView(org.apache.geode.distributed.internal.membership.NetView) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 14 with InstallViewMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage in project geode by apache.

the class GMSJoinLeaveJUnitTest method testViewWithoutMemberInitiatesForcedDisconnect.

@Test
public void testViewWithoutMemberInitiatesForcedDisconnect() throws Exception {
    initMocks();
    GMSJoinLeaveTestHelper.becomeCoordinatorForTest(gmsJoinLeave);
    List<InternalDistributedMember> members = Arrays.asList(mockMembers);
    NetView v = new NetView(mockMembers[0], 2, members);
    InstallViewMessage message = getInstallViewMessage(v, null, false);
    gmsJoinLeave.processMessage(message);
    verify(manager).forceDisconnect(isA(String.class));
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 15 with InstallViewMessage

use of org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage in project geode by apache.

the class GMSJoinLeaveJUnitTest method testNoViewAckCausesRemovalMessage.

@Test
public void testNoViewAckCausesRemovalMessage() throws Exception {
    initMocks(true);
    when(healthMonitor.checkIfAvailable(isA(InternalDistributedMember.class), isA(String.class), isA(Boolean.class))).thenReturn(false);
    prepareAndInstallView(mockMembers[0], createMemberList(mockMembers[0], gmsJoinLeaveMemberId));
    NetView oldView = gmsJoinLeave.getView();
    NetView newView = new NetView(oldView, oldView.getViewId() + 1);
    // the new view will remove the old coordinator (normal shutdown) and add a new member
    // who will not ack the view. This should cause it to be removed from the system
    // with a RemoveMemberMessage
    newView.add(mockMembers[2]);
    newView.remove(mockMembers[0]);
    InstallViewMessage installViewMessage = getInstallViewMessage(newView, credentials, false);
    gmsJoinLeave.processMessage(installViewMessage);
    // this test's member-timeout * 3
    Awaitility.await().atMost(6, SECONDS).until(() -> gmsJoinLeave.getView().getViewId() != oldView.getViewId());
    assertTrue(gmsJoinLeave.isCoordinator());
    // wait for suspect processing
    verify(healthMonitor, timeout(10000).atLeast(1)).checkIfAvailable(isA(DistributedMember.class), isA(String.class), isA(Boolean.class));
// verify(messenger, atLeast(1)).send(isA(RemoveMemberMessage.class));
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

InstallViewMessage (org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)16 NetView (org.apache.geode.distributed.internal.membership.NetView)15 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)12 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)12 Test (org.junit.Test)12 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)10 LinkedList (java.util.LinkedList)4 HashSet (java.util.HashSet)3 GMSMember (org.apache.geode.distributed.internal.membership.gms.GMSMember)2 ViewAckMessage (org.apache.geode.distributed.internal.membership.gms.messages.ViewAckMessage)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 Properties (java.util.Properties)1 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)1 Manager (org.apache.geode.distributed.internal.membership.gms.interfaces.Manager)1 ViewCreator (org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave.ViewCreator)1 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)1 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)1