Search in sources :

Example 61 with NetView

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

the class GMSMembershipManager method directChannelSend.

/**
   * Perform the grossness associated with sending a message over a DirectChannel
   *
   * @param destinations the list of destinations
   * @param content the message
   * @param theStats the statistics object to update
   * @return all recipients who did not receive the message (null if all received it)
   * @throws NotSerializableException if the message is not serializable
   */
protected Set<InternalDistributedMember> directChannelSend(InternalDistributedMember[] destinations, DistributionMessage content, DMStats theStats) throws NotSerializableException {
    boolean allDestinations;
    InternalDistributedMember[] keys;
    if (content.forAll()) {
        allDestinations = true;
        latestViewReadLock.lock();
        try {
            List<InternalDistributedMember> keySet = latestView.getMembers();
            keys = new InternalDistributedMember[keySet.size()];
            keys = keySet.toArray(keys);
        } finally {
            latestViewReadLock.unlock();
        }
    } else {
        allDestinations = false;
        keys = destinations;
    }
    int sentBytes;
    try {
        sentBytes = directChannel.send(this, keys, content, this.services.getConfig().getDistributionConfig().getAckWaitThreshold(), this.services.getConfig().getDistributionConfig().getAckSevereAlertThreshold());
        if (theStats != null) {
            theStats.incSentBytes(sentBytes);
        }
        if (sentBytes == 0) {
            if (services.getCancelCriterion().isCancelInProgress()) {
                throw new DistributedSystemDisconnectedException();
            }
        }
    } catch (DistributedSystemDisconnectedException ex) {
        if (services.getShutdownCause() != null) {
            throw new DistributedSystemDisconnectedException("DistributedSystem is shutting down", services.getShutdownCause());
        } else {
            // see bug 41416
            throw ex;
        }
    } catch (ConnectExceptions ex) {
        // Check if the connect exception is due to system shutting down.
        if (shutdownInProgress()) {
            if (services.getShutdownCause() != null) {
                throw new DistributedSystemDisconnectedException("DistributedSystem is shutting down", services.getShutdownCause());
            } else {
                throw new DistributedSystemDisconnectedException();
            }
        }
        if (allDestinations)
            return null;
        // We
        List<InternalDistributedMember> members = (List<InternalDistributedMember>) ex.getMembers();
        // need
        // to
        // return
        // this
        // list
        // of
        // failures
        // SANITY CHECK: If we fail to send a message to an existing member
        // of the view, we have a serious error (bug36202).
        // grab a recent view, excluding shunned
        NetView view = services.getJoinLeave().getView();
        // members
        // Iterate through members and causes in tandem :-(
        Iterator it_mem = members.iterator();
        Iterator it_causes = ex.getCauses().iterator();
        while (it_mem.hasNext()) {
            InternalDistributedMember member = (InternalDistributedMember) it_mem.next();
            Throwable th = (Throwable) it_causes.next();
            if (!view.contains(member) || (th instanceof ShunnedMemberException)) {
                continue;
            }
            logger.fatal(LocalizedMessage.create(LocalizedStrings.GroupMembershipService_FAILED_TO_SEND_MESSAGE_0_TO_MEMBER_1_VIEW_2, new Object[] { content, member, view }), th);
        // Assert.assertTrue(false, "messaging contract failure");
        }
        return new HashSet<>(members);
    }// catch ConnectionExceptions
     catch (ToDataException | CancelException e) {
        throw e;
    } catch (IOException e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Membership: directChannelSend caught exception: {}", e.getMessage(), e);
        }
        if (e instanceof NotSerializableException) {
            throw (NotSerializableException) e;
        }
    } catch (RuntimeException | Error e) {
        if (logger.isDebugEnabled()) {
            logger.debug("Membership: directChannelSend caught exception: {}", e.getMessage(), e);
        }
        throw e;
    }
    return null;
}
Also used : ShunnedMemberException(org.apache.geode.distributed.internal.direct.ShunnedMemberException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) ConnectExceptions(org.apache.geode.internal.tcp.ConnectExceptions) NetView(org.apache.geode.distributed.internal.membership.NetView) InternalGemFireError(org.apache.geode.InternalGemFireError) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ToDataException(org.apache.geode.ToDataException) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) CancelException(org.apache.geode.CancelException)

Example 62 with NetView

use of org.apache.geode.distributed.internal.membership.NetView 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 63 with NetView

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

the class GMSMembershipManager method processView.

/**
   * Analyze a given view object, generate events as appropriate
   */
protected void processView(long newViewId, NetView newView) {
    // Sanity check...
    if (logger.isDebugEnabled()) {
        StringBuilder msg = new StringBuilder(200);
        msg.append("Membership: Processing view ");
        msg.append(newView);
        msg.append("} on ").append(address.toString());
        logger.debug(msg);
        if (!newView.contains(address)) {
            logger.info(LocalizedMessage.create(LocalizedStrings.GroupMembershipService_THE_MEMBER_WITH_ID_0_IS_NO_LONGER_IN_MY_OWN_VIEW_1, new Object[] { address, newView }));
        }
    }
    // We perform the update under a global lock so that other
    // incoming events will not be lost in terms of our global view.
    latestViewWriteLock.lock();
    try {
        // first determine the version for multicast message serialization
        Version version = Version.CURRENT;
        for (final Entry<InternalDistributedMember, Long> internalDistributedMemberLongEntry : surpriseMembers.entrySet()) {
            InternalDistributedMember mbr = internalDistributedMemberLongEntry.getKey();
            Version itsVersion = mbr.getVersionObject();
            if (itsVersion != null && version.compareTo(itsVersion) < 0) {
                version = itsVersion;
            }
        }
        for (InternalDistributedMember mbr : newView.getMembers()) {
            Version itsVersion = mbr.getVersionObject();
            if (itsVersion != null && itsVersion.compareTo(version) < 0) {
                version = mbr.getVersionObject();
            }
        }
        disableMulticastForRollingUpgrade = !version.equals(Version.CURRENT);
        if (newViewId < latestViewId) {
            // ignore this view since it is old news
            return;
        }
        // Save previous view, for delta analysis
        NetView priorView = latestView;
        // update the view to reflect our changes, so that
        // callbacks will see the new (updated) view.
        latestViewId = newViewId;
        latestView = new NetView(newView, newView.getViewId());
        // look for additions
        for (int i = 0; i < newView.getMembers().size(); i++) {
            // additions
            InternalDistributedMember m = newView.getMembers().get(i);
            // Once a member has been seen via a view, remove them from the
            // newborn set. Replace the netmember of the surpriseMember ID
            // in case it was a partial ID and is being retained by DistributionManager
            // or some other object
            boolean wasSurprise = surpriseMembers.containsKey(m);
            if (wasSurprise) {
                for (Iterator<Map.Entry<InternalDistributedMember, Long>> iterator = surpriseMembers.entrySet().iterator(); iterator.hasNext(); ) {
                    Entry<InternalDistributedMember, Long> entry = iterator.next();
                    if (entry.getKey().equals(m)) {
                        entry.getKey().setNetMember(m.getNetMember());
                        iterator.remove();
                        break;
                    }
                }
            }
            // if it's in a view, it's no longer suspect
            suspectedMembers.remove(m);
            if (priorView.contains(m) || wasSurprise) {
                // already seen
                continue;
            }
            // unblock any waiters for this particular member.
            // i.e. signal any waiting threads in tcpconduit.
            String authInit = this.services.getConfig().getDistributionConfig().getSecurityPeerAuthInit();
            boolean isSecure = authInit != null && authInit.length() != 0;
            if (isSecure) {
                CountDownLatch currentLatch;
                if ((currentLatch = memberLatch.get(m)) != null) {
                    currentLatch.countDown();
                }
            }
            if (shutdownInProgress()) {
                addShunnedMember(m);
                // no additions processed after shutdown begins
                continue;
            } else {
                // bug #45158 - no longer shun a process that is now in
                boolean wasShunned = endShun(m);
                // view
                if (wasShunned && logger.isDebugEnabled()) {
                    logger.debug("No longer shunning {} as it is in the current membership view", m);
                }
            }
            logger.info(LocalizedMessage.create(LocalizedStrings.GroupMembershipService_MEMBERSHIP_PROCESSING_ADDITION__0_, m));
            try {
                listener.newMemberConnected(m);
            } catch (VirtualMachineError err) {
                SystemFailure.initiateFailure(err);
                // now, so don't let this thread continue.
                throw err;
            } catch (DistributedSystemDisconnectedException e) {
            // don't log shutdown exceptions
            } catch (Throwable t) {
                // Whenever you catch Error or Throwable, you must also
                // catch VirtualMachineError (see above). However, there is
                // _still_ a possibility that you are dealing with a cascading
                // error condition, so you also need to check to see if the JVM
                // is still usable:
                SystemFailure.checkFailure();
                logger.info(LocalizedMessage.create(LocalizedStrings.GroupMembershipService_MEMBERSHIP_FAULT_WHILE_PROCESSING_VIEW_ADDITION_OF__0, m), t);
            }
        }
        // look for departures
        for (int i = 0; i < priorView.getMembers().size(); i++) {
            // departures
            InternalDistributedMember m = priorView.getMembers().get(i);
            if (newView.contains(m)) {
                // still alive
                continue;
            }
            if (surpriseMembers.containsKey(m)) {
                // member has not yet appeared in a view
                continue;
            }
            try {
                removeWithViewLock(m, newView.getCrashedMembers().contains(m) || suspectedMembers.containsKey(m), "departed membership view");
            } catch (VirtualMachineError err) {
                SystemFailure.initiateFailure(err);
                // now, so don't let this thread continue.
                throw err;
            } catch (Throwable t) {
                // Whenever you catch Error or Throwable, you must also
                // catch VirtualMachineError (see above). However, there is
                // _still_ a possibility that you are dealing with a cascading
                // error condition, so you also need to check to see if the JVM
                // is still usable:
                SystemFailure.checkFailure();
                logger.info(LocalizedMessage.create(LocalizedStrings.GroupMembershipService_MEMBERSHIP_FAULT_WHILE_PROCESSING_VIEW_REMOVAL_OF__0, m), t);
            }
        }
        // departures
        // expire surprise members, add others to view
        long oldestAllowed = System.currentTimeMillis() - this.surpriseMemberTimeout;
        for (Iterator<Map.Entry<InternalDistributedMember, Long>> it = surpriseMembers.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry<InternalDistributedMember, Long> entry = it.next();
            Long birthtime = entry.getValue();
            if (birthtime.longValue() < oldestAllowed) {
                it.remove();
                InternalDistributedMember m = entry.getKey();
                logger.info(LocalizedMessage.create(LocalizedStrings.GroupMembershipService_MEMBERSHIP_EXPIRING_MEMBERSHIP_OF_SURPRISE_MEMBER_0, m));
                removeWithViewLock(m, true, "not seen in membership view in " + this.surpriseMemberTimeout + "ms");
            } else {
                if (!latestView.contains(entry.getKey())) {
                    latestView.add(entry.getKey());
                }
            }
        }
        // expire suspected members
        /*
       * the timeout interval for suspected members
       */
        final long suspectMemberTimeout = 180000;
        oldestAllowed = System.currentTimeMillis() - suspectMemberTimeout;
        for (Iterator it = suspectedMembers.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry entry = (Map.Entry) it.next();
            Long birthtime = (Long) entry.getValue();
            if (birthtime.longValue() < oldestAllowed) {
                it.remove();
            }
        }
        try {
            listener.viewInstalled(latestView);
        } catch (DistributedSystemDisconnectedException se) {
        }
    } finally {
        latestViewWriteLock.unlock();
    }
}
Also used : Entry(java.util.Map.Entry) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) NetView(org.apache.geode.distributed.internal.membership.NetView) CountDownLatch(java.util.concurrent.CountDownLatch) Entry(java.util.Map.Entry) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Version(org.apache.geode.internal.Version) Iterator(java.util.Iterator) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 64 with NetView

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

the class GMSJoinLeave method getMemberID.

@Override
public InternalDistributedMember getMemberID(NetMember jgId) {
    NetView v = currentView;
    InternalDistributedMember ret = null;
    if (v != null) {
        ret = getMemId(jgId, v.getMembers());
    }
    if (ret == null) {
        v = preparedView;
        if (v != null) {
            ret = getMemId(jgId, v.getMembers());
        }
    }
    if (ret == null) {
        return new InternalDistributedMember(jgId);
    }
    return ret;
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) NetView(org.apache.geode.distributed.internal.membership.NetView)

Example 65 with NetView

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

the class GMSJoinLeaveJUnitTest method installView.

private void installView(int viewId, InternalDistributedMember coordinator, List<InternalDistributedMember> members) throws IOException {
    // prepare the view
    NetView netView = new NetView(coordinator, viewId, members);
    InstallViewMessage installViewMessage = getInstallViewMessage(netView, credentials, false);
    gmsJoinLeave.processMessage(installViewMessage);
// verify(messenger).send(isA(ViewAckMessage.class));
}
Also used : NetView(org.apache.geode.distributed.internal.membership.NetView) InstallViewMessage(org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)

Aggregations

NetView (org.apache.geode.distributed.internal.membership.NetView)101 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)65 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)59 Test (org.junit.Test)59 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)57 HashSet (java.util.HashSet)25 InstallViewMessage (org.apache.geode.distributed.internal.membership.gms.messages.InstallViewMessage)18 Message (org.jgroups.Message)14 ArrayList (java.util.ArrayList)12 JoinResponseMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinResponseMessage)10 UnitTest (org.apache.geode.test.junit.categories.UnitTest)10 LinkedList (java.util.LinkedList)9 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)9 IOException (java.io.IOException)8 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)8 Properties (java.util.Properties)7 FindCoordinatorResponse (org.apache.geode.distributed.internal.membership.gms.locator.FindCoordinatorResponse)7 CancelException (org.apache.geode.CancelException)6 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)6 JoinRequestMessage (org.apache.geode.distributed.internal.membership.gms.messages.JoinRequestMessage)6