Search in sources :

Example 11 with GMSMember

use of org.apache.geode.distributed.internal.membership.gms.GMSMember 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 12 with GMSMember

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

the class GMSJoinLeave method started.

@Override
public void started() {
    this.localAddress = services.getMessenger().getMemberID();
    GMSMember mbr = (GMSMember) this.localAddress.getNetMember();
    if (services.getConfig().areLocatorsPreferredAsCoordinators()) {
        boolean preferred = false;
        if (services.getLocator() != null || Locator.hasLocator() || !services.getConfig().getDistributionConfig().getStartLocator().isEmpty() || localAddress.getVmKind() == DistributionManager.LOCATOR_DM_TYPE) {
            logger.info("This member is hosting a locator will be preferred as a membership coordinator");
            preferred = true;
        }
        mbr.setPreferredForCoordinator(preferred);
    } else {
        mbr.setPreferredForCoordinator(true);
    }
}
Also used : GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember)

Example 13 with GMSMember

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

the class JGroupsMessenger method handleJGroupsIOException.

/**
   * If JGroups is unable to send a message it may mean that the network is down. If so we need to
   * initiate suspect processing on the recipient.
   * <p>
   * see Transport._send()
   */
@SuppressWarnings("UnusedParameters")
public void handleJGroupsIOException(IOException e, Address dest) {
    if (services.getManager().shutdownInProgress()) {
        // shutdown
        return;
    }
    if (addressesWithIoExceptionsProcessed.contains(dest)) {
        return;
    }
    addressesWithIoExceptionsProcessed.add(dest);
    NetView v = this.view;
    JGAddress jgMbr = (JGAddress) dest;
    if (jgMbr != null && v != null) {
        List<InternalDistributedMember> members = v.getMembers();
        InternalDistributedMember recipient = null;
        for (InternalDistributedMember mbr : members) {
            GMSMember gmsMbr = ((GMSMember) mbr.getNetMember());
            if (jgMbr.getUUIDLsbs() == gmsMbr.getUuidLSBs() && jgMbr.getUUIDMsbs() == gmsMbr.getUuidMSBs() && jgMbr.getVmViewId() == gmsMbr.getVmViewId()) {
                recipient = mbr;
                break;
            }
        }
        if (recipient != null) {
            services.getHealthMonitor().suspect(recipient, "Unable to send messages to this member via JGroups");
        }
    }
}
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)

Example 14 with GMSMember

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

the class ClientCacheFactoryJUnitTest method testOldClientIDDeserialization.

@Test
public void testOldClientIDDeserialization() throws Exception {
    // during a HandShake a clientID is read w/o knowing the client's
    // version
    cc = new ClientCacheFactory().create();
    GemFireCacheImpl gfc = (GemFireCacheImpl) cc;
    InternalDistributedMember memberID = (InternalDistributedMember) cc.getDistributedSystem().getDistributedMember();
    GMSMember gmsID = (GMSMember) memberID.getNetMember();
    memberID.setVersionObjectForTest(Version.GFE_82);
    assertEquals(Version.GFE_82, memberID.getVersionObject());
    ClientProxyMembershipID clientID = ClientProxyMembershipID.getClientId(memberID);
    HeapDataOutputStream out = new HeapDataOutputStream(Version.GFE_82);
    DataSerializer.writeObject(clientID, out);
    DataInputStream in = new VersionedDataInputStream(new ByteArrayInputStream(out.toByteArray()), Version.CURRENT);
    ClientProxyMembershipID newID = DataSerializer.readObject(in);
    InternalDistributedMember newMemberID = (InternalDistributedMember) newID.getDistributedMember();
    assertEquals(Version.GFE_82, newMemberID.getVersionObject());
    assertEquals(Version.GFE_82, newID.getClientVersion());
    GMSMember newGmsID = (GMSMember) newMemberID.getNetMember();
    assertEquals(0, newGmsID.getUuidLSBs());
    assertEquals(0, newGmsID.getUuidMSBs());
    gmsID.setUUID(new UUID(1234l, 5678l));
    memberID.setVersionObjectForTest(Version.CURRENT);
    clientID = ClientProxyMembershipID.getClientId(memberID);
    out = new HeapDataOutputStream(Version.CURRENT);
    DataSerializer.writeObject(clientID, out);
    in = new VersionedDataInputStream(new ByteArrayInputStream(out.toByteArray()), Version.CURRENT);
    newID = DataSerializer.readObject(in);
    newMemberID = (InternalDistributedMember) newID.getDistributedMember();
    assertEquals(Version.CURRENT, newMemberID.getVersionObject());
    assertEquals(Version.CURRENT, newID.getClientVersion());
    newGmsID = (GMSMember) newMemberID.getNetMember();
    assertEquals(gmsID.getUuidLSBs(), newGmsID.getUuidLSBs());
    assertEquals(gmsID.getUuidMSBs(), newGmsID.getUuidMSBs());
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ByteArrayInputStream(java.io.ByteArrayInputStream) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) DataInputStream(java.io.DataInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) UUID(org.jgroups.util.UUID) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 15 with GMSMember

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

the class GMSHealthMonitor method doTCPCheckMember.

// Package protected for testing purposes
boolean doTCPCheckMember(InternalDistributedMember suspectMember, Socket clientSocket) {
    try {
        if (clientSocket.isConnected()) {
            clientSocket.setSoTimeout((int) services.getConfig().getMemberTimeout());
            InputStream in = clientSocket.getInputStream();
            DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
            GMSMember gmbr = (GMSMember) suspectMember.getNetMember();
            writeMemberToStream(gmbr, out);
            this.stats.incFinalCheckRequestsSent();
            this.stats.incTcpFinalCheckRequestsSent();
            logger.debug("Connected to suspect member - reading response");
            int b = in.read();
            if (logger.isDebugEnabled()) {
                logger.debug("Received {}", (b == OK ? "OK" : (b == ERROR ? "ERROR" : "unknown response: " + b)));
            }
            if (b >= 0) {
                this.stats.incFinalCheckResponsesReceived();
                this.stats.incTcpFinalCheckResponsesReceived();
            }
            if (b == OK) {
                TimeStamp ts = memberTimeStamps.get(suspectMember);
                if (ts != null) {
                    ts.setTime(System.currentTimeMillis());
                }
                return true;
            } else {
                // received ERROR
                return false;
            }
        } else {
            // cannot establish TCP connection with suspect member
            return false;
        }
    } catch (SocketTimeoutException e) {
        logger.debug("Final check TCP/IP connection timed out for suspect member {}", suspectMember);
        return false;
    } catch (IOException e) {
        logger.trace("Unexpected exception", e);
    }
    return false;
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) DataOutputStream(java.io.DataOutputStream) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) IOException(java.io.IOException)

Aggregations

GMSMember (org.apache.geode.distributed.internal.membership.gms.GMSMember)21 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)12 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)8 Test (org.junit.Test)8 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)7 NetView (org.apache.geode.distributed.internal.membership.NetView)4 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)4 UUID (org.jgroups.util.UUID)4 DataInputStream (java.io.DataInputStream)3 HashSet (java.util.HashSet)3 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 LinkedList (java.util.LinkedList)2 HighPriorityDistributionMessage (org.apache.geode.distributed.internal.HighPriorityDistributionMessage)2 InstallViewMessage (org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)2 JoinRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)2 HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)2 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1