Search in sources :

Example 6 with DISCARD

use of org.jgroups.protocols.DISCARD in project wildfly by wildfly.

the class PartitionServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    boolean partition = Boolean.valueOf(request.getParameter(PARTITION));
    this.log("Simulating network partitions? " + partition);
    try {
        if (partition) {
            // Store views for future merge event
            GMS gms = this.channel.getProtocolStack().findProtocol(GMS.class);
            mergeViews = new HashMap<>();
            this.channel.getView().getMembers().forEach(address -> mergeViews.put(address, View.create(address, gms.getViewId().getId() + 1, address)));
            // Wait a few seconds to ensure everyone stored a full view
            Thread.sleep(VIEWS_TIMEOUT);
            // Simulate partitions by injecting DISCARD protocol
            DISCARD discard = new DISCARD();
            discard.setDiscardAll(true);
            this.channel.getProtocolStack().insertProtocol(discard, ProtocolStack.Position.ABOVE, TP.class);
            // Speed up partitioning
            View view = View.create(this.channel.getAddress(), gms.getViewId().getId() + 1, this.channel.getAddress());
            gms.installView(view);
        } else {
            this.channel.getProtocolStack().removeProtocol(DISCARD.class);
            // Wait a few seconds for the other node to remove DISCARD so it does not discard our MERGE request
            Thread.sleep(VIEWS_TIMEOUT);
            // Since the coordinator is determined by ordering the address in org.jgroups.protocols.pbcast.Merger#determineMergeLeader
            // let just all nodes send the merge..
            this.log("Passing event up the stack: " + new Event(Event.MERGE, mergeViews));
            GMS gms = this.channel.getProtocolStack().findProtocol(GMS.class);
            gms.up(new Event(Event.MERGE, mergeViews));
            mergeViews = null;
        }
        response.getWriter().write("Success");
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    } catch (Exception e) {
        throw new ServletException(e);
    }
}
Also used : ServletException(javax.servlet.ServletException) DISCARD(org.jgroups.protocols.DISCARD) Event(org.jgroups.Event) GMS(org.jgroups.protocols.pbcast.GMS) View(org.jgroups.View) ServletException(javax.servlet.ServletException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException)

Example 7 with DISCARD

use of org.jgroups.protocols.DISCARD in project JGroups by belaban.

the class MergeTest3 method createChannel.

protected static JChannel createChannel(String name) throws Exception {
    JChannel retval = new JChannel(new SHARED_LOOPBACK(), new DISCARD().discardAll(true), new SHARED_LOOPBACK_PING(), new NAKACK2().useMcastXmit(false).logDiscardMessages(false).logNotFoundMessages(false), new UNICAST3(), new STABLE().setMaxBytes(50000), new GMS().printLocalAddress(false).setJoinTimeout(1).setLeaveTimeout(100).setMergeTimeout(5000).logViewWarnings(false).setViewAckCollectionTimeout(50).logCollectMessages(false)).name(name);
    retval.connect("MergeTest3");
    JmxConfigurator.registerChannel(retval, Util.getMBeanServer(), name, retval.getClusterName(), true);
    return retval;
}
Also used : SHARED_LOOPBACK(org.jgroups.protocols.SHARED_LOOPBACK) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) DISCARD(org.jgroups.protocols.DISCARD) SHARED_LOOPBACK_PING(org.jgroups.protocols.SHARED_LOOPBACK_PING) STABLE(org.jgroups.protocols.pbcast.STABLE) GMS(org.jgroups.protocols.pbcast.GMS) UNICAST3(org.jgroups.protocols.UNICAST3)

Example 8 with DISCARD

use of org.jgroups.protocols.DISCARD in project JGroups by belaban.

the class MergeTest3 method testMergeWithMissingMergeResponse.

public void testMergeWithMissingMergeResponse() throws TimeoutException {
    createPartition(a, b, c);
    createPartition(d, e, f);
    System.out.println("Views are:");
    for (JChannel ch : Arrays.asList(a, b, c, d, e, f)) System.out.println(ch.getAddress() + ": " + ch.getView());
    JChannel merge_leader = findMergeLeader(a, b, c, d, e, f);
    List<Address> first_partition = getMembers(a, b, c);
    List<Address> second_partition = getMembers(d, e, f);
    Collections.sort(first_partition);
    // remove the coord
    Address first_coord = first_partition.remove(0);
    Address busy_first = first_partition.get(0);
    Collections.sort(second_partition);
    Address second_coord = second_partition.remove(0);
    Address busy_second = second_partition.get(second_partition.size() - 1);
    System.out.println("\nMerge leader: " + merge_leader.getAddress() + "\nBusy members: " + Arrays.asList(busy_first, busy_second));
    MergeId busy_merge_id = MergeId.create(a.getAddress());
    setMergeIdIn(busy_first, busy_merge_id);
    setMergeIdIn(busy_second, busy_merge_id);
    for (JChannel ch : channels) {
        // excluding faulty member, as it still discards messages
        assert ch.getView().size() == 3;
        GMS gms = ch.getProtocolStack().findProtocol(GMS.class);
        gms.setJoinTimeout(3000);
        DISCARD discard = ch.getProtocolStack().findProtocol(DISCARD.class);
        discard.discardAll(false);
    }
    System.out.println("Injecting MERGE event into merge leader " + merge_leader.getAddress());
    GMS gms = merge_leader.getProtocolStack().findProtocol(GMS.class);
    int i = 10;
    do {
        Map<Address, View> merge_views = new HashMap<>(6);
        merge_views.put(first_coord, findChannel(first_coord).getView());
        merge_views.put(second_coord, findChannel(second_coord).getView());
        gms.up(new Event(Event.MERGE, merge_views));
        boolean done = true;
        System.out.println();
        for (JChannel ch : channels) {
            System.out.println("==> " + ch.getAddress() + ": " + ch.getView());
            Address addr = ch.getAddress();
            if (addr.equals(busy_first) || addr.equals(busy_second)) {
                if (ch.getView().size() != 3)
                    done = false;
            } else if (ch.getView().size() != 4)
                done = false;
        }
        if (done)
            break;
        Util.sleep(2000);
    } while (--i >= 0);
    for (JChannel ch : channels) {
        if (ch.getAddress().equals(busy_first) || ch.getAddress().equals(busy_second))
            assert ch.getView().size() == 3;
        else
            assert ch.getView().size() == 4 : ch.getAddress() + "'s view: " + ch.getView();
    }
    System.out.println("\n************************ Now merging the entire cluster ****************");
    cancelMerge(busy_first);
    cancelMerge(busy_second);
    System.out.println("Injecting MERGE event into merge leader " + merge_leader.getAddress());
    Map<Address, View> merge_views = new HashMap<>(6);
    i = 10;
    do {
        merge_views = new HashMap<>(6);
        merge_views.put(merge_leader.getAddress(), merge_leader.getView());
        merge_views.put(busy_first, findChannel(busy_first).getView());
        merge_views.put(busy_second, findChannel(busy_second).getView());
        gms.up(new Event(Event.MERGE, merge_views));
        if (Stream.of(channels).allMatch(c -> c.getView().size() == 6))
            break;
        Util.sleep(2000);
    } while (--i >= 0);
    System.out.printf("channels:\n%s\n", Stream.of(channels).map(c -> String.format("%s: %s", c.getAddress(), c.getView())).collect(Collectors.joining("\n")));
    assert Stream.of(channels).allMatch(c -> c.getView().size() == channels.length);
}
Also used : MergeId(org.jgroups.util.MergeId) GMS(org.jgroups.protocols.pbcast.GMS) DISCARD(org.jgroups.protocols.DISCARD)

Example 9 with DISCARD

use of org.jgroups.protocols.DISCARD in project JGroups by belaban.

the class OOBTest method testRegularAndOOBUnicasts.

/**
 * Tests sending 1, 2 (OOB) and 3, where they are received in the order 1, 3, 2. Message 3 should not get delivered
 * until message 4 is received (http://jira.jboss.com/jira/browse/JGRP-780)
 */
public void testRegularAndOOBUnicasts() throws Exception {
    DISCARD discard = new DISCARD();
    ProtocolStack stack = a.getProtocolStack();
    stack.insertProtocol(discard, ProtocolStack.Position.BELOW, Util.getUnicastProtocols());
    Address dest = b.getAddress();
    Message m1 = new BytesMessage(dest, 1);
    Message m2 = new BytesMessage(dest, 2).setFlag(Message.Flag.OOB);
    Message m3 = new BytesMessage(dest, 3);
    MyReceiver receiver = new MyReceiver("B");
    b.setReceiver(receiver);
    a.send(m1);
    discard.dropDownUnicasts(1);
    a.send(m2);
    a.send(m3);
    Collection<Integer> list = receiver.getMsgs();
    int count = 10;
    while (list.size() < 3 && --count > 0) {
        // time for potential retransmission
        Util.sleep(500);
        sendStableMessages(a, b);
    }
    assert list.size() == 3 : "list is " + list;
    assert list.contains(1) && list.contains(2) && list.contains(3);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DISCARD(org.jgroups.protocols.DISCARD) ProtocolStack(org.jgroups.stack.ProtocolStack)

Example 10 with DISCARD

use of org.jgroups.protocols.DISCARD in project JGroups by belaban.

the class LastMessageDroppedTest method testLastMessageAndLastSeqnoDropped.

/**
 * Tests the case where the last message is dropped, and the ensuing LAST_SEQNO message is also dropped. STABLE with
 * a timeout of 5s should make sure that B eventually does get message 3.
 */
public void testLastMessageAndLastSeqnoDropped() throws Exception {
    DISCARD discard = new DISCARD();
    ProtocolStack stack = a.getProtocolStack();
    stack.insertProtocol(discard, ProtocolStack.Position.BELOW, NAKACK2.class);
    MyReceiver receiver = new MyReceiver();
    b.setReceiver(receiver);
    a.send(null, 1);
    a.send(null, 2);
    // drop the next multicast
    discard.dropDownMulticasts(1);
    stack.insertProtocol(new LastSeqnoDropper(1), ProtocolStack.Position.BELOW, NAKACK2.class);
    a.send(null, 3);
    Collection<Integer> list = receiver.getMsgs();
    for (int i = 0; i < 20 && list.size() < 3; i++) {
        System.out.println("list=" + list);
        Util.sleep(1000);
    }
    System.out.println("list=" + list);
    assert list.size() == 3 : "list=" + list;
}
Also used : DISCARD(org.jgroups.protocols.DISCARD) ProtocolStack(org.jgroups.stack.ProtocolStack)

Aggregations

DISCARD (org.jgroups.protocols.DISCARD)11 ProtocolStack (org.jgroups.stack.ProtocolStack)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 GMS (org.jgroups.protocols.pbcast.GMS)4 SHARED_LOOPBACK (org.jgroups.protocols.SHARED_LOOPBACK)2 SHARED_LOOPBACK_PING (org.jgroups.protocols.SHARED_LOOPBACK_PING)2 UNICAST3 (org.jgroups.protocols.UNICAST3)2 NAKACK2 (org.jgroups.protocols.pbcast.NAKACK2)2 STABLE (org.jgroups.protocols.pbcast.STABLE)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1 Properties (java.util.Properties)1 ServletException (javax.servlet.ServletException)1 Event (org.jgroups.Event)1 View (org.jgroups.View)1 MergeId (org.jgroups.util.MergeId)1 Test (org.testng.annotations.Test)1