Search in sources :

Example 16 with DistributedSystemDisconnectedException

use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.

the class ConnectionTable method removeEndpoint.

protected void removeEndpoint(DistributedMember memberID, String reason, boolean notifyDisconnect) {
    if (this.closed) {
        return;
    }
    boolean needsRemoval = false;
    synchronized (this.orderedConnectionMap) {
        if (this.orderedConnectionMap.get(memberID) != null)
            needsRemoval = true;
    }
    if (!needsRemoval) {
        synchronized (this.unorderedConnectionMap) {
            if (this.unorderedConnectionMap.get(memberID) != null)
                needsRemoval = true;
        }
    }
    if (!needsRemoval) {
        ConcurrentMap cm = this.threadConnectionMap;
        if (cm != null) {
            ArrayList al = (ArrayList) cm.get(memberID);
            needsRemoval = al != null && al.size() > 0;
        }
    }
    if (needsRemoval) {
        InternalDistributedMember remoteAddress = null;
        synchronized (this.orderedConnectionMap) {
            Object c = this.orderedConnectionMap.remove(memberID);
            if (c instanceof Connection) {
                remoteAddress = ((Connection) c).getRemoteAddress();
            }
            closeCon(reason, c);
        }
        synchronized (this.unorderedConnectionMap) {
            Object c = this.unorderedConnectionMap.remove(memberID);
            if (remoteAddress == null && (c instanceof Connection)) {
                remoteAddress = ((Connection) c).getRemoteAddress();
            }
            closeCon(reason, c);
        }
        {
            ConcurrentMap cm = this.threadConnectionMap;
            if (cm != null) {
                ArrayList al = (ArrayList) cm.remove(memberID);
                if (al != null) {
                    synchronized (al) {
                        for (Iterator it = al.iterator(); it.hasNext(); ) {
                            Object c = it.next();
                            if (remoteAddress == null && (c instanceof Connection)) {
                                remoteAddress = ((Connection) c).getRemoteAddress();
                            }
                            closeCon(reason, c);
                        }
                        al.clear();
                    }
                }
            }
        }
        // close any sockets that are in the process of being connected
        Set toRemove = new HashSet();
        synchronized (connectingSockets) {
            for (Iterator it = connectingSockets.entrySet().iterator(); it.hasNext(); ) {
                Map.Entry entry = (Map.Entry) it.next();
                ConnectingSocketInfo info = (ConnectingSocketInfo) entry.getValue();
                if (info.peerAddress.equals(((InternalDistributedMember) memberID).getInetAddress())) {
                    toRemove.add(entry.getKey());
                    it.remove();
                }
            }
        }
        for (Iterator it = toRemove.iterator(); it.hasNext(); ) {
            Socket sock = (Socket) it.next();
            try {
                sock.close();
            } catch (IOException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug("caught exception while trying to close connecting socket for {}", memberID, e);
                }
            }
        }
        // close any receivers
        // avoid deadlock when a NIC has failed by closing connections outside
        // of the receivers sync (bug 38731)
        toRemove.clear();
        synchronized (this.receivers) {
            for (Iterator it = receivers.iterator(); it.hasNext(); ) {
                Connection con = (Connection) it.next();
                if (memberID.equals(con.getRemoteAddress())) {
                    it.remove();
                    toRemove.add(con);
                }
            }
        }
        for (Iterator it = toRemove.iterator(); it.hasNext(); ) {
            Connection con = (Connection) it.next();
            closeCon(reason, con);
        }
        if (notifyDisconnect) {
            // for a shutdown in progress and threw this exception:
            if (owner.getDM().shutdownInProgress()) {
                throw new DistributedSystemDisconnectedException("Shutdown in progress", owner.getDM().getMembershipManager().getShutdownCause());
            }
        }
        if (remoteAddress != null) {
            this.socketCloser.releaseResourcesForAddress(remoteAddress.toString());
        }
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) HashSet(java.util.HashSet) Set(java.util.Set) ConcurrentMap(java.util.concurrent.ConcurrentMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) Iterator(java.util.Iterator) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Socket(java.net.Socket) HashSet(java.util.HashSet)

Example 17 with DistributedSystemDisconnectedException

use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.

the class ConnectionTable method scheduleIdleTimeout.

/** schedule an idle-connection timeout task */
private void scheduleIdleTimeout(Connection conn) {
    if (conn == null) {
        // fix for bug 43529
        return;
    }
    // Set the idle timeout
    if (this.owner.idleConnectionTimeout != 0) {
        try {
            synchronized (this) {
                if (!this.closed) {
                    IdleConnTT task = new IdleConnTT(conn);
                    conn.setIdleTimeoutTask(task);
                    this.getIdleConnTimer().scheduleAtFixedRate(task, this.owner.idleConnectionTimeout, this.owner.idleConnectionTimeout);
                }
            }
        } catch (IllegalStateException e) {
            if (conn.isClosing()) {
                // causing the task to be canceled
                return;
            }
            logger.debug("Got an illegal state exception: {}", e.getMessage(), e);
            // Unfortunately, cancelInProgress() is not set until *after*
            // the shutdown message has been sent, so we need to check the
            // "closeInProgress" bit instead.
            owner.getCancelCriterion().checkCancelInProgress(null);
            Throwable cause = owner.getShutdownCause();
            if (cause == null) {
                cause = e;
            }
            throw new DistributedSystemDisconnectedException(LocalizedStrings.ConnectionTable_THE_DISTRIBUTED_SYSTEM_IS_SHUTTING_DOWN.toLocalizedString(), cause);
        }
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException)

Example 18 with DistributedSystemDisconnectedException

use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.

the class FunctionStreamingReplyMessage method toData.

@Override
public void toData(DataOutput out) throws IOException {
    super.toData(out);
    out.writeInt(this.msgNum);
    out.writeBoolean(this.lastMsg);
    out.writeInt(this.processorId);
    // soubhik. fix for ticket 40670
    try {
        DataSerializer.writeObject(this.result, out);
    } catch (Exception ex) {
        if (ex instanceof CancelException) {
            throw new DistributedSystemDisconnectedException(ex);
        }
        NotSerializableException ioEx = new NotSerializableException(this.result.getClass().getName());
        ioEx.initCause(ex);
        throw ioEx;
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) NotSerializableException(java.io.NotSerializableException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) ReplyException(org.apache.geode.distributed.internal.ReplyException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CancelException(org.apache.geode.CancelException)

Example 19 with DistributedSystemDisconnectedException

use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.

the class GlobalTransaction method getId.

/**
   * Read current {@link #DMid} and return it
   * 
   * @return current DMid
   */
private static String getId() {
    synchronized (DmidMutex) {
        InternalDistributedSystem ids = InternalDistributedSystem.getAnyInstance();
        if (ids == null) {
            throw new DistributedSystemDisconnectedException("No distributed system");
        }
        if (ids == IdsForId) {
            return DMid;
        }
        IdsForId = ids;
        DM dm = ids.getDistributionManager();
        DMid = dm.getId().toString();
        return DMid;
    }
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) DM(org.apache.geode.distributed.internal.DM) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem)

Example 20 with DistributedSystemDisconnectedException

use of org.apache.geode.distributed.DistributedSystemDisconnectedException in project geode by apache.

the class PersistentRecoveryOrderDUnitTest method testFinishIncompleteInitializationNoSend.

@Test
public void testFinishIncompleteInitializationNoSend() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    // Add a hook which will disconnect the DS before sending a prepare message
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof PrepareNewPersistentMemberMessage) {
                        DistributionMessageObserver.setInstance(null);
                        getSystem().disconnect();
                    }
                }

                @Override
                public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
                }
            });
        }
    });
    createPersistentRegion(vm0);
    putAnEntry(vm0);
    updateTheEntry(vm0);
    try {
        createPersistentRegion(vm1);
    } catch (Exception e) {
        if (!(e.getCause() instanceof DistributedSystemDisconnectedException)) {
            throw e;
        }
    }
    closeRegion(vm0);
    // This wait for VM0 to come back
    AsyncInvocation async1 = createPersistentRegionAsync(vm1);
    waitForBlockedInitialization(vm1);
    createPersistentRegion(vm0);
    async1.getResult();
    checkForEntry(vm1);
    vm0.invoke(new SerializableRunnable("check for offline members") {

        public void run() {
            Cache cache = getCache();
            DistributedRegion region = (DistributedRegion) cache.getRegion(REGION_NAME);
            PersistentMembershipView view = region.getPersistenceAdvisor().getMembershipView();
            DiskRegion dr = region.getDiskRegion();
            assertEquals(Collections.emptySet(), dr.getOfflineMembers());
            assertEquals(1, dr.getOnlineMembers().size());
        }
    });
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) RevokedPersistentDataException(org.apache.geode.cache.persistence.RevokedPersistentDataException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) AdminException(org.apache.geode.admin.AdminException) ConflictingPersistentDataException(org.apache.geode.cache.persistence.ConflictingPersistentDataException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) LockServiceDestroyedException(org.apache.geode.distributed.LockServiceDestroyedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PersistentReplicatesOfflineException(org.apache.geode.cache.persistence.PersistentReplicatesOfflineException) IOException(java.io.IOException) DiskRegion(org.apache.geode.internal.cache.DiskRegion) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)42 IOException (java.io.IOException)15 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)15 Test (org.junit.Test)9 CancelException (org.apache.geode.CancelException)7 ReplyException (org.apache.geode.distributed.internal.ReplyException)7 Iterator (java.util.Iterator)6 CacheClosedException (org.apache.geode.cache.CacheClosedException)6 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)6 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 Cache (org.apache.geode.cache.Cache)4 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)4 InternalCache (org.apache.geode.internal.cache.InternalCache)4 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)4 InterruptedIOException (java.io.InterruptedIOException)3