Search in sources :

Example 6 with LeaveRequestMessage

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

the class GMSJoinLeave method leave.

@Override
public void leave() {
    synchronized (viewInstallationLock) {
        NetView view = currentView;
        isStopping = true;
        stopCoordinatorServices();
        if (view != null) {
            if (view.size() > 1) {
                List<InternalDistributedMember> coords = view.getPreferredCoordinators(Collections.emptySet(), localAddress, 5);
                logger.debug("Sending my leave request to {}", coords);
                LeaveRequestMessage m = new LeaveRequestMessage(coords, this.localAddress, "this member is shutting down");
                services.getMessenger().send(m);
            }
        // view.size
        }
    // view != null
    }
}
Also used : LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView)

Example 7 with LeaveRequestMessage

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

the class GMSJoinLeave method installView.

public void installView(NetView newView) {
    synchronized (viewInstallationLock) {
        if (currentView != null && currentView.getViewId() >= newView.getViewId()) {
            // old view - ignore it
            return;
        }
        logger.info("received new view: {}\nold view is: {}", newView, currentView);
        if (currentView == null && !this.isJoined) {
            boolean found = false;
            for (InternalDistributedMember mbr : newView.getMembers()) {
                if (this.localAddress.equals(mbr)) {
                    found = true;
                    this.birthViewId = mbr.getVmViewId();
                    this.localAddress.setVmViewId(this.birthViewId);
                    GMSMember me = (GMSMember) this.localAddress.getNetMember();
                    me.setBirthViewId(birthViewId);
                    break;
                }
            }
            if (!found) {
                logger.info("rejecting view (not yet joined)");
                return;
            }
        }
        if (isJoined && isNetworkPartition(newView, true)) {
            if (quorumRequired) {
                Set<InternalDistributedMember> crashes = newView.getActualCrashedMembers(currentView);
                forceDisconnect(LocalizedStrings.Network_partition_detected.toLocalizedString(crashes.size(), crashes));
                return;
            }
        }
        previousView = currentView;
        currentView = newView;
        preparedView = null;
        lastConflictingView = null;
        services.installView(newView);
        if (!isJoined) {
            logger.debug("notifying join thread");
            isJoined = true;
            synchronized (joinResponse) {
                joinResponse.notifyAll();
            }
        }
        if (!newView.getCreator().equals(this.localAddress)) {
            if (newView.shouldBeCoordinator(this.localAddress)) {
                becomeCoordinator();
            } else if (this.isCoordinator) {
                // stop being coordinator
                stopCoordinatorServices();
                this.isCoordinator = false;
            }
        }
        if (!this.isCoordinator) {
            // resend these
            synchronized (viewRequests) {
                for (Iterator<DistributionMessage> it = viewRequests.iterator(); it.hasNext(); ) {
                    DistributionMessage m = it.next();
                    if (m instanceof JoinRequestMessage) {
                        if (currentView.contains(((JoinRequestMessage) m).getMemberID())) {
                            it.remove();
                        }
                    } else if (m instanceof LeaveRequestMessage) {
                        if (!currentView.contains(((LeaveRequestMessage) m).getMemberID())) {
                            it.remove();
                        }
                    } else if (m instanceof RemoveMemberMessage) {
                        if (!currentView.contains(((RemoveMemberMessage) m).getMemberID())) {
                            it.remove();
                        }
                    }
                }
            }
        }
    }
    synchronized (removedMembers) {
        removeMembersFromCollectionIfNotInView(removedMembers, currentView);
    }
    synchronized (leftMembers) {
        removeMembersFromCollectionIfNotInView(leftMembers, currentView);
    }
}
Also used : LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) RemoveMemberMessage(org.apache.geode.distributed.internal.membership.gms.messages.RemoveMemberMessage) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)

Example 8 with LeaveRequestMessage

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

the class GMSJoinLeave method memberShutdown.

@Override
public void memberShutdown(DistributedMember mbr, String reason) {
    LeaveRequestMessage msg = new LeaveRequestMessage(Collections.singleton(this.localAddress), (InternalDistributedMember) mbr, reason);
    msg.setSender((InternalDistributedMember) mbr);
    processLeaveRequest(msg);
}
Also used : LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage)

Example 9 with LeaveRequestMessage

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

the class JGroupsMessengerJUnitTest method doTestMessageDeliveredToHandler.

private void doTestMessageDeliveredToHandler(boolean mcast) throws Exception {
    initMocks(mcast);
    MessageHandler mh = mock(MessageHandler.class);
    messenger.addHandler(JoinRequestMessage.class, mh);
    InternalDistributedMember addr = messenger.getMemberID();
    NetView v = new NetView(addr);
    when(joinLeave.getView()).thenReturn(v);
    InternalDistributedMember sender = createAddress(8888);
    JoinRequestMessage msg = new JoinRequestMessage(messenger.localAddress, sender, null, -1, 0);
    Message jmsg = messenger.createJGMessage(msg, messenger.jgAddress, Version.CURRENT_ORDINAL);
    interceptor.up(new Event(Event.MSG, jmsg));
    verify(mh, times(1)).processMessage(any(JoinRequestMessage.class));
    LeaveRequestMessage lmsg = new LeaveRequestMessage(messenger.localAddress, sender, "testing");
    when(joinLeave.getMemberID(any())).thenReturn(sender);
    jmsg = messenger.createJGMessage(lmsg, messenger.jgAddress, Version.CURRENT_ORDINAL);
    interceptor.up(new Event(Event.MSG, jmsg));
    verify(manager).processMessage(any(LeaveRequestMessage.class));
}
Also used : LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) MessageHandler(org.apache.geode.distributed.internal.membership.gms.interfaces.MessageHandler) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) SerialAckedMessage(org.apache.geode.distributed.internal.SerialAckedMessage) Message(org.jgroups.Message) NetView(org.apache.geode.distributed.internal.membership.NetView) Event(org.jgroups.Event) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)

Example 10 with LeaveRequestMessage

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

the class GMSJoinLeaveJUnitTest method testLeaveCausesForcedDisconnect.

@Test
public void testLeaveCausesForcedDisconnect() throws Exception {
    String reason = "testing";
    initMocks();
    prepareAndInstallView(gmsJoinLeaveMemberId, createMemberList(gmsJoinLeaveMemberId, mockMembers[0]));
    gmsJoinLeave.getView().add(mockMembers[1]);
    LeaveRequestMessage msg = new LeaveRequestMessage(gmsJoinLeave.getMemberID(), gmsJoinLeave.getMemberID(), reason);
    msg.setSender(mockMembers[1]);
    gmsJoinLeave.processMessage(msg);
    verify(manager).forceDisconnect(reason);
}
Also used : LeaveRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

LeaveRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.LeaveRequestMessage)10 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)5 Test (org.junit.Test)5 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)4 NetView (org.apache.geode.distributed.internal.membership.NetView)4 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)2 JoinRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)2 RemoveMemberMessage (org.apache.geode.distributed.internal.membership.gms.messages.RemoveMemberMessage)2 SerialAckedMessage (org.apache.geode.distributed.internal.SerialAckedMessage)1 GMSMember (org.apache.geode.distributed.internal.membership.gms.GMSMember)1 MessageHandler (org.apache.geode.distributed.internal.membership.gms.interfaces.MessageHandler)1 InstallViewMessage (org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)1 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)1 Event (org.jgroups.Event)1 Message (org.jgroups.Message)1