Search in sources :

Example 1 with ViewAckMessage

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

the class GMSJoinLeave method processViewMessage.

private void processViewMessage(final InstallViewMessage m) {
    NetView view = m.getView();
    // If our current view doesn't contaion sender then we wanrt to ignore that view.
    if (currentView != null && !currentView.contains(m.getSender())) {
        // this may happen when we locator re-join and it take over coordinator's responsibility.
        if (this.preparedView == null || !this.preparedView.contains(m.getSender())) {
            logger.info("Ignoring the view {} from member {}, which is not in my current view {} ", view, m.getSender(), currentView);
            return;
        }
    }
    if (currentView != null && view.getViewId() < currentView.getViewId()) {
        // ignore old views
        ackView(m);
        return;
    }
    boolean viewContainsMyUnjoinedAddress = false;
    if (!this.isJoined) {
        // should install the view so join() can finish its work
        for (InternalDistributedMember mbr : view.getMembers()) {
            if (localAddress.compareTo(mbr) == 0) {
                viewContainsMyUnjoinedAddress = true;
                break;
            }
        }
    }
    if (m.isPreparing()) {
        if (this.preparedView != null && this.preparedView.getViewId() >= view.getViewId()) {
            services.getMessenger().send(new ViewAckMessage(m.getSender(), this.preparedView));
        } else {
            this.preparedView = view;
            if (viewContainsMyUnjoinedAddress) {
                // this will notifyAll the joinResponse
                installView(view);
            }
            ackView(m);
        }
    } else {
        // !preparing
        if (isJoined && currentView != null && !view.contains(this.localAddress)) {
            logger.fatal("This member is no longer in the membership view.  My ID is {} and the new view is {}", localAddress, view);
            forceDisconnect("This node is no longer in the membership view");
        } else {
            if (isJoined || viewContainsMyUnjoinedAddress) {
                installView(view);
            }
            if (!m.isRebroadcast()) {
                // no need to ack a rebroadcast view
                ackView(m);
            }
        }
    }
}
Also used : ViewAckMessage(org.apache.geode.distributed.internal.membership.gms.messages.ViewAckMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView)

Example 2 with ViewAckMessage

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

the class GMSJoinLeaveJUnitTest method testPreparedViewFoundDuringBecomeCoordinator.

@Test
public void testPreparedViewFoundDuringBecomeCoordinator() throws Exception {
    initMocks(false);
    prepareAndInstallView(gmsJoinLeaveMemberId, createMemberList(gmsJoinLeaveMemberId, mockMembers[0]));
    // a new member is joining
    NetView preparedView = new NetView(gmsJoinLeave.getView(), gmsJoinLeave.getView().getViewId() + 5);
    mockMembers[1].setVmViewId(preparedView.getViewId());
    preparedView.add(mockMembers[1]);
    InstallViewMessage msg = getInstallViewMessage(preparedView, null, true);
    gmsJoinLeave.processMessage(msg);
    GMSJoinLeaveTestHelper.becomeCoordinatorForTest(gmsJoinLeave);
    Thread.sleep(2000);
    ViewCreator vc = gmsJoinLeave.getViewCreator();
    int viewId = 0;
    if (gmsJoinLeave.getPreparedView() == null) {
        viewId = gmsJoinLeave.getView().getViewId();
    } else {
        viewId = gmsJoinLeave.getPreparedView().getViewId();
    }
    ViewAckMessage vack = new ViewAckMessage(gmsJoinLeaveMemberId, viewId, true);
    vack.setSender(mockMembers[0]);
    gmsJoinLeave.processMessage(vack);
    vack = new ViewAckMessage(gmsJoinLeaveMemberId, viewId, true);
    vack.setSender(mockMembers[1]);
    gmsJoinLeave.processMessage(vack);
    vack = new ViewAckMessage(gmsJoinLeaveMemberId, viewId, true);
    vack.setSender(gmsJoinLeaveMemberId);
    gmsJoinLeave.processMessage(vack);
    Awaitility.await("view creator finishes").atMost(30, SECONDS).until(() -> vc.waiting);
    NetView newView = gmsJoinLeave.getView();
    System.out.println("new view is " + newView);
    assertTrue(newView.contains(mockMembers[1]));
    assertTrue(newView.getViewId() > preparedView.getViewId());
}
Also used : ViewCreator(org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave.ViewCreator) ViewAckMessage(org.apache.geode.distributed.internal.membership.gms.messages.ViewAckMessage) 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)

Aggregations

NetView (org.apache.geode.distributed.internal.membership.NetView)2 ViewAckMessage (org.apache.geode.distributed.internal.membership.gms.messages.ViewAckMessage)2 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 ViewCreator (org.apache.geode.distributed.internal.membership.gms.membership.GMSJoinLeave.ViewCreator)1 InstallViewMessage (org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)1 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)1 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)1 Test (org.junit.Test)1