Search in sources :

Example 1 with ViewId

use of org.jgroups.ViewId in project geode by apache.

the class JGroupsMessenger method start.

@Override
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
public void start() {
    // create the configuration XML string for JGroups
    String properties = this.jgStackConfig;
    long start = System.currentTimeMillis();
    // start the jgroups channel and establish the membership ID
    boolean reconnecting = false;
    try {
        Object oldChannel = services.getConfig().getTransport().getOldDSMembershipInfo();
        if (oldChannel != null) {
            logger.debug("Reusing JGroups channel from previous system", properties);
            myChannel = (JChannel) oldChannel;
            // scrub the old channel
            ViewId vid = new ViewId(new JGAddress(), 0);
            View jgv = new View(vid, new ArrayList<>());
            this.myChannel.down(new Event(Event.VIEW_CHANGE, jgv));
            UUID logicalAddress = (UUID) myChannel.getAddress();
            if (logicalAddress instanceof JGAddress) {
                ((JGAddress) logicalAddress).setVmViewId(-1);
            }
            reconnecting = true;
        } else {
            logger.debug("JGroups configuration: {}", properties);
            checkForIPv6();
            InputStream is = new ByteArrayInputStream(properties.getBytes("UTF-8"));
            myChannel = new JChannel(is);
        }
    } catch (Exception e) {
        throw new GemFireConfigException("unable to create jgroups channel", e);
    }
    // give the stats to the jchannel statistics recorder
    StatRecorder sr = (StatRecorder) myChannel.getProtocolStack().findProtocol(StatRecorder.class);
    if (sr != null) {
        sr.setServices(services);
    }
    Transport transport = (Transport) myChannel.getProtocolStack().getTransport();
    transport.setMessenger(this);
    nackack2HeaderId = ClassConfigurator.getProtocolId(NAKACK2.class);
    try {
        myChannel.setReceiver(null);
        myChannel.setReceiver(new JGroupsReceiver());
        if (!reconnecting) {
            // apache g***** (whatever we end up calling it)
            myChannel.connect("AG");
        }
    } catch (Exception e) {
        myChannel.close();
        throw new SystemConnectException("unable to create jgroups channel", e);
    }
    if (JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK) {
        JGroupsMessenger.THROW_EXCEPTION_ON_START_HOOK = false;
        throw new SystemConnectException("failing for test");
    }
    establishLocalAddress();
    logger.info("JGroups channel {} (took {}ms)", (reconnecting ? "reinitialized" : "created"), System.currentTimeMillis() - start);
}
Also used : JChannel(org.jgroups.JChannel) ByteArrayInputStream(java.io.ByteArrayInputStream) VersionedDataInputStream(org.apache.geode.internal.VersionedDataInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) NetView(org.apache.geode.distributed.internal.membership.NetView) View(org.jgroups.View) 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) NAKACK2(org.jgroups.protocols.pbcast.NAKACK2) ByteArrayInputStream(java.io.ByteArrayInputStream) GemFireConfigException(org.apache.geode.GemFireConfigException) ViewId(org.jgroups.ViewId) Event(org.jgroups.Event) UUID(org.jgroups.util.UUID) SystemConnectException(org.apache.geode.SystemConnectException)

Example 2 with ViewId

use of org.jgroups.ViewId in project geode by apache.

the class JGroupsMessenger method installView.

@Override
public void installView(NetView v) {
    this.view = v;
    if (this.jgAddress.getVmViewId() < 0) {
        this.jgAddress.setVmViewId(this.localAddress.getVmViewId());
    }
    List<JGAddress> mbrs = new ArrayList<>(v.size());
    mbrs.addAll(v.getMembers().stream().map(JGAddress::new).collect(Collectors.toList()));
    ViewId vid = new ViewId(new JGAddress(v.getCoordinator()), v.getViewId());
    View jgv = new View(vid, new ArrayList<>(mbrs));
    logger.trace("installing JGroups view: {}", jgv);
    this.myChannel.down(new Event(Event.VIEW_CHANGE, jgv));
    addressesWithIoExceptionsProcessed.clear();
    if (encrypt != null) {
        encrypt.installView(v);
    }
    synchronized (scheduledMcastSeqnos) {
        for (DistributedMember mbr : v.getCrashedMembers()) {
            scheduledMcastSeqnos.remove(mbr);
        }
        for (DistributedMember mbr : v.getShutdownMembers()) {
            scheduledMcastSeqnos.remove(mbr);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ViewId(org.jgroups.ViewId) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) Event(org.jgroups.Event) NetView(org.apache.geode.distributed.internal.membership.NetView) View(org.jgroups.View)

Example 3 with ViewId

use of org.jgroups.ViewId in project JGroups by belaban.

the class ViewTest method testEquals2.

public void testEquals2() {
    View v1 = new View(new ViewId(a, 12345), new ArrayList<>(members));
    View v2 = new View(a, 12345, new ArrayList<>(members));
    assert v1.equals(v2);
    View v3 = new View(a, 12543, new ArrayList<>(members));
    assert !v1.equals(v3);
}
Also used : ViewId(org.jgroups.ViewId) View(org.jgroups.View)

Example 4 with ViewId

use of org.jgroups.ViewId in project JGroups by belaban.

the class ViewIdTest method setUp.

@BeforeClass
void setUp() throws UnknownHostException {
    v1 = new ViewId(Util.createRandomAddress("A"), 22);
    v2 = new ViewId(Util.createRandomAddress("B"), 21);
    v3 = v1.copy();
    v4 = new ViewId(Util.createRandomAddress("C"), 22);
}
Also used : ViewId(org.jgroups.ViewId) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with ViewId

use of org.jgroups.ViewId in project JGroups by belaban.

the class LargeMergeTest method testClusterFormationAfterMerge.

public void testClusterFormationAfterMerge() {
    System.out.println("\nEnabling message traffic between members to start the merge");
    for (JChannel ch : channels) {
        DISCARD discard = ch.getProtocolStack().findProtocol(DISCARD.class);
        discard.discardAll(false);
    }
    boolean merge_completed = true;
    for (int i = 0; i < NUM; i++) {
        merge_completed = true;
        System.out.println();
        Map<ViewId, Integer> views = new HashMap<>();
        for (JChannel ch : channels) {
            ViewId view_id = ch.getView().getViewId();
            Integer val = views.get(view_id);
            views.put(view_id, val == null ? 1 : val + 1);
            int size = ch.getView().size();
            if (size != NUM)
                merge_completed = false;
        }
        if (i++ > 0) {
            int num_singleton_views = 0;
            for (Map.Entry<ViewId, Integer> entry : views.entrySet()) {
                if (entry.getValue() == 1)
                    num_singleton_views++;
                else {
                    System.out.println("==> " + entry.getKey() + ": " + entry.getValue() + " members");
                }
            }
            if (num_singleton_views > 0)
                System.out.println("==> " + num_singleton_views + " singleton views");
            System.out.println("------------------\n" + getStats());
        }
        if (merge_completed)
            break;
        Util.sleep(5000);
    }
    if (!merge_completed) {
        System.out.println("\nFinal cluster:");
        for (JChannel ch : channels) {
            int size = ch.getView().size();
            System.out.println(ch.getAddress() + ": " + size + " members - " + (size == NUM ? "OK" : "FAIL"));
        }
    }
    for (JChannel ch : channels) {
        int size = ch.getView().size();
        assert size == NUM : "Channel has " + size + " members, but should have " + NUM;
    }
}
Also used : JChannel(org.jgroups.JChannel) HashMap(java.util.HashMap) ViewId(org.jgroups.ViewId) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ViewId (org.jgroups.ViewId)6 View (org.jgroups.View)3 NetView (org.apache.geode.distributed.internal.membership.NetView)2 Event (org.jgroups.Event)2 JChannel (org.jgroups.JChannel)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)1 GemFireConfigException (org.apache.geode.GemFireConfigException)1 GemFireIOException (org.apache.geode.GemFireIOException)1 SystemConnectException (org.apache.geode.SystemConnectException)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)1