Search in sources :

Example 6 with GMSMember

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

the class JGroupsMessengerJUnitTest method createAddress.

/**
   * creates an InternalDistributedMember address that can be used with the doctored JGroups
   * channel. This includes a logical (UUID) address and a physical (IpAddress) address.
   * 
   * @param port the UDP port to use for the new address
   */
private InternalDistributedMember createAddress(int port) {
    GMSMember gms = new GMSMember("localhost", port);
    gms.setUUID(UUID.randomUUID());
    gms.setVmKind(DistributionManager.NORMAL_DM_TYPE);
    gms.setVersionOrdinal(Version.CURRENT_ORDINAL);
    return new InternalDistributedMember(gms);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember)

Example 7 with GMSMember

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

the class JGroupsMessengerJUnitTest method testMemberWeightIsSerialized.

@Test
public void testMemberWeightIsSerialized() throws Exception {
    HeapDataOutputStream out = new HeapDataOutputStream(500, Version.CURRENT);
    InternalDistributedMember mbr = createAddress(8888);
    ((GMSMember) mbr.getNetMember()).setMemberWeight((byte) 40);
    mbr.toData(out);
    DataInputStream in = new DataInputStream(new ByteArrayInputStream(out.toByteArray()));
    mbr = new InternalDistributedMember();
    mbr.fromData(in);
    assertEquals(40, mbr.getNetMember().getMemberWeight());
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ByteArrayInputStream(java.io.ByteArrayInputStream) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) DataInputStream(java.io.DataInputStream) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 8 with GMSMember

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

the class JGroupsMessenger method serializeMessage.

byte[] serializeMessage(DistributionMessage gfmsg, HeapDataOutputStream out_stream) throws IOException {
    GMSMember m = (GMSMember) this.localAddress.getNetMember();
    m.writeEssentialData(out_stream);
    DataSerializer.writeObject(gfmsg, out_stream);
    return out_stream.toByteArray();
}
Also used : GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember)

Example 9 with GMSMember

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

the class JGroupsMessenger method send.

private Set<InternalDistributedMember> send(DistributionMessage msg, boolean reliably) {
    // perform the same jgroups messaging as in 8.2's GMSMembershipManager.send() method
    // BUT: when marshalling messages we need to include the version of the product and
    // localAddress at the beginning of the message. These should be used in the receiver
    // code to create a versioned input stream, read the sender address, then read the message
    // and set its sender address
    DMStats theStats = services.getStatistics();
    NetView oldView = this.view;
    if (!myChannel.isConnected()) {
        logger.info("JGroupsMessenger channel is closed - messaging is not possible");
        throw new DistributedSystemDisconnectedException("Distributed System is shutting down");
    }
    filterOutgoingMessage(msg);
    // the message's processor if necessary
    if ((msg instanceof DirectReplyMessage) && msg.isDirectAck() && msg.getProcessorId() <= 0) {
        ((DirectReplyMessage) msg).registerProcessor();
    }
    InternalDistributedMember[] destinations = msg.getRecipients();
    boolean allDestinations = msg.forAll();
    boolean useMcast = false;
    if (services.getConfig().getTransport().isMcastEnabled()) {
        if (msg.getMulticast() || allDestinations) {
            useMcast = services.getManager().isMulticastAllowed();
        }
    }
    if (logger.isDebugEnabled() && reliably) {
        String recips = useMcast ? "multicast" : Arrays.toString(msg.getRecipients());
        logger.debug("sending via JGroups: [{}] recipients: {}", msg, recips);
    }
    JGAddress local = this.jgAddress;
    if (useMcast) {
        long startSer = theStats.startMsgSerialization();
        Message jmsg = createJGMessage(msg, local, Version.CURRENT_ORDINAL);
        theStats.endMsgSerialization(startSer);
        Exception problem;
        try {
            jmsg.setTransientFlag(TransientFlag.DONT_LOOPBACK);
            if (!reliably) {
                jmsg.setFlag(Message.Flag.NO_RELIABILITY);
            }
            theStats.incSentBytes(jmsg.getLength());
            logger.trace("Sending JGroups message: {}", jmsg);
            myChannel.send(jmsg);
        } catch (Exception e) {
            logger.debug("caught unexpected exception", e);
            Throwable cause = e.getCause();
            if (cause instanceof ForcedDisconnectException) {
                problem = (Exception) cause;
            } else {
                problem = e;
            }
            if (services.getShutdownCause() != null) {
                Throwable shutdownCause = services.getShutdownCause();
                // problem.
                if (shutdownCause instanceof ForcedDisconnectException) {
                    problem = (Exception) shutdownCause;
                } else {
                    Throwable ne = problem;
                    while (ne.getCause() != null) {
                        ne = ne.getCause();
                    }
                    ne.initCause(services.getShutdownCause());
                }
            }
            final String channelClosed = LocalizedStrings.GroupMembershipService_CHANNEL_CLOSED.toLocalizedString();
            // services.getManager().membershipFailure(channelClosed, problem);
            throw new DistributedSystemDisconnectedException(channelClosed, problem);
        }
    } else // useMcast
    {
        // ! useMcast
        int len = destinations.length;
        // explicit list of members
        List<GMSMember> calculatedMembers;
        // == calculatedMembers.len
        int calculatedLen;
        if (len == 1 && destinations[0] == DistributionMessage.ALL_RECIPIENTS) {
            // send to all
            // Grab a copy of the current membership
            NetView v = services.getJoinLeave().getView();
            // Construct the list
            calculatedLen = v.size();
            calculatedMembers = new LinkedList<GMSMember>();
            for (int i = 0; i < calculatedLen; i++) {
                InternalDistributedMember m = (InternalDistributedMember) v.get(i);
                calculatedMembers.add((GMSMember) m.getNetMember());
            }
        } else // send to all
        {
            // send to explicit list
            calculatedLen = len;
            calculatedMembers = new LinkedList<GMSMember>();
            for (int i = 0; i < calculatedLen; i++) {
                calculatedMembers.add((GMSMember) destinations[i].getNetMember());
            }
        }
        // send to explicit list
        Int2ObjectOpenHashMap<Message> messages = new Int2ObjectOpenHashMap<>();
        long startSer = theStats.startMsgSerialization();
        boolean firstMessage = true;
        for (GMSMember mbr : calculatedMembers) {
            short version = mbr.getVersionOrdinal();
            if (!messages.containsKey(version)) {
                Message jmsg = createJGMessage(msg, local, version);
                messages.put(version, jmsg);
                if (firstMessage) {
                    theStats.incSentBytes(jmsg.getLength());
                    firstMessage = false;
                }
            }
        }
        theStats.endMsgSerialization(startSer);
        Collections.shuffle(calculatedMembers);
        int i = 0;
        for (GMSMember mbr : calculatedMembers) {
            JGAddress to = new JGAddress(mbr);
            short version = mbr.getVersionOrdinal();
            Message jmsg = messages.get(version);
            Exception problem = null;
            try {
                Message tmp = (i < (calculatedLen - 1)) ? jmsg.copy(true) : jmsg;
                if (!reliably) {
                    jmsg.setFlag(Message.Flag.NO_RELIABILITY);
                }
                tmp.setDest(to);
                tmp.setSrc(this.jgAddress);
                logger.trace("Unicasting to {}", to);
                myChannel.send(tmp);
            } catch (Exception e) {
                problem = e;
            }
            if (problem != null) {
                Throwable cause = services.getShutdownCause();
                if (cause != null) {
                    // problem.
                    if (cause instanceof ForcedDisconnectException) {
                        problem = (Exception) cause;
                    } else {
                        Throwable ne = problem;
                        while (ne.getCause() != null) {
                            ne = ne.getCause();
                        }
                        ne.initCause(cause);
                    }
                }
                final String channelClosed = LocalizedStrings.GroupMembershipService_CHANNEL_CLOSED.toLocalizedString();
                // services.getManager().membershipFailure(channelClosed, problem);
                throw new DistributedSystemDisconnectedException(channelClosed, problem);
            }
        }
    // send individually
    }
    // (i.e., left the view), we signal it here.
    if (msg.forAll()) {
        return Collections.emptySet();
    }
    Set<InternalDistributedMember> result = new HashSet<>();
    NetView newView = this.view;
    if (newView != null && newView != oldView) {
        for (InternalDistributedMember d : destinations) {
            if (!newView.contains(d)) {
                logger.debug("messenger: member has left the view: {}  view is now {}", d, newView);
                result.add(d);
            }
        }
    }
    return result;
}
Also used : Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) DMStats(org.apache.geode.distributed.internal.DMStats) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) JoinRequestMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage) DirectReplyMessage(org.apache.geode.internal.cache.DirectReplyMessage) JoinResponseMessage(org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage) LocalizedMessage(org.apache.geode.internal.logging.log4j.LocalizedMessage) Message(org.jgroups.Message) HighPriorityDistributionMessage(org.apache.geode.distributed.internal.HighPriorityDistributionMessage) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember) NetView(org.apache.geode.distributed.internal.membership.NetView) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) GemFireIOException(org.apache.geode.GemFireIOException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) DirectReplyMessage(org.apache.geode.internal.cache.DirectReplyMessage) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) HashSet(java.util.HashSet)

Example 10 with GMSMember

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

the class JGroupsMessenger method deserializeMessage.

DistributionMessage deserializeMessage(DataInputStream in, short ordinal) throws ClassNotFoundException, IOException {
    GMSMember m = new GMSMember();
    m.readEssentialData(in);
    DistributionMessage result = (DistributionMessage) DataSerializer.readObject(in);
    setSender(result, m, ordinal);
    return result;
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) HighPriorityDistributionMessage(org.apache.geode.distributed.internal.HighPriorityDistributionMessage) GMSMember(org.apache.geode.distributed.internal.membership.gms.GMSMember)

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