Search in sources :

Example 1 with DistributionManager

use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.

the class PartitionedRegion method filterOldMembers.

/**
   * @param nodeToBuckets A map with InternalDistributedSystem as key and either HashSet or
   *        HashMap<Integer, HashSet> as value.
   * @return Map of <old members, set/map of bucket ids they host>.
   */
private HashMap filterOldMembers(HashMap nodeToBuckets) {
    DistributionManager dm = (DistributionManager) getDistributionManager();
    HashMap oldGuys = new HashMap();
    Set<InternalDistributedMember> oldMembers = new HashSet<InternalDistributedMember>(nodeToBuckets.keySet());
    dm.removeMembersWithSameOrNewerVersion(oldMembers, Version.CURRENT);
    Iterator<InternalDistributedMember> oldies = oldMembers.iterator();
    while (oldies.hasNext()) {
        InternalDistributedMember old = oldies.next();
        if (nodeToBuckets.containsKey(old)) {
            oldGuys.put(old, nodeToBuckets.remove(old));
        } else {
            oldies.remove();
        }
    }
    return oldGuys;
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) HashSet(java.util.HashSet)

Example 2 with DistributionManager

use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.

the class AbstractExecution method executeFunctionOnLocalPRNode.

public void executeFunctionOnLocalPRNode(final Function fn, final FunctionContext cx, final PartitionedRegionFunctionResultSender sender, DM dm, boolean isTx) {
    if (dm instanceof DistributionManager && !isTx) {
        if (ServerConnection.isExecuteFunctionOnLocalNodeOnly().byteValue() == 1) {
            // executed locally
            ServerConnection.executeFunctionOnLocalNodeOnly((byte) 3);
            executeFunctionLocally(fn, cx, sender, dm);
            if (!sender.isLastResultReceived() && fn.hasResult()) {
                ((InternalResultSender) sender).setException(new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(fn.getId())));
            }
        } else {
            final DistributionManager newDM = (DistributionManager) dm;
            newDM.getFunctionExcecutor().execute(new Runnable() {

                public void run() {
                    executeFunctionLocally(fn, cx, sender, newDM);
                    if (!sender.isLastResultReceived() && fn.hasResult()) {
                        ((InternalResultSender) sender).setException(new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(fn.getId())));
                    }
                }
            });
        }
    } else {
        executeFunctionLocally(fn, cx, sender, dm);
        if (!sender.isLastResultReceived() && fn.hasResult()) {
            ((InternalResultSender) sender).setException(new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(fn.getId())));
        }
    }
}
Also used : FunctionException(org.apache.geode.cache.execute.FunctionException) DistributionManager(org.apache.geode.distributed.internal.DistributionManager)

Example 3 with DistributionManager

use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.

the class Connection method readAck.

/**
   * @param msToWait number of milliseconds to wait for an ack. If 0 then wait forever.
   * @param msInterval interval between checks
   * @throws SocketTimeoutException if msToWait expires.
   * @throws ConnectionException if ack is not received (fixes bug 34312)
   */
public void readAck(final int msToWait, final long msInterval, final DirectReplyProcessor processor) throws SocketTimeoutException, ConnectionException {
    if (isSocketClosed()) {
        throw new ConnectionException(LocalizedStrings.Connection_CONNECTION_IS_CLOSED.toLocalizedString());
    }
    synchronized (this.stateLock) {
        this.connectionState = STATE_READING_ACK;
    }
    boolean origSocketInUse = this.socketInUse;
    this.socketInUse = true;
    MsgReader msgReader = null;
    DMStats stats = owner.getConduit().stats;
    final Version version = getRemoteVersion();
    try {
        if (useNIO()) {
            msgReader = new NIOMsgReader(this, version);
        } else {
            msgReader = new OioMsgReader(this, version);
        }
        Header header = msgReader.readHeader();
        ReplyMessage msg;
        int len;
        if (header.getNioMessageType() == NORMAL_MSG_TYPE) {
            msg = (ReplyMessage) msgReader.readMessage(header);
            len = header.getNioMessageLength();
        } else {
            MsgDestreamer destreamer = obtainMsgDestreamer(header.getNioMessageId(), version);
            while (header.getNioMessageType() == CHUNKED_MSG_TYPE) {
                msgReader.readChunk(header, destreamer);
                header = msgReader.readHeader();
            }
            msgReader.readChunk(header, destreamer);
            msg = (ReplyMessage) destreamer.getMessage();
            releaseMsgDestreamer(header.getNioMessageId(), destreamer);
            len = destreamer.size();
        }
        // I'd really just like to call dispatchMessage here. However,
        // that call goes through a bunch of checks that knock about
        // 10% of the performance. Since this direct-ack stuff is all
        // about performance, we'll skip those checks. Skipping them
        // should be legit, because we just sent a message so we know
        // the member is already in our view, etc.
        DistributionManager dm = (DistributionManager) owner.getDM();
        msg.setBytesRead(len);
        msg.setSender(remoteAddr);
        stats.incReceivedMessages(1L);
        stats.incReceivedBytes(msg.getBytesRead());
        stats.incMessageChannelTime(msg.resetTimestamp());
        msg.process(dm, processor);
    // dispatchMessage(msg, len, false);
    } catch (MemberShunnedException e) {
    // do nothing
    } catch (SocketTimeoutException timeout) {
        throw timeout;
    } catch (IOException e) {
        final String err = LocalizedStrings.Connection_ACK_READ_IO_EXCEPTION_FOR_0.toLocalizedString(this);
        if (!isSocketClosed()) {
            if (logger.isDebugEnabled() && !isIgnorableIOException(e)) {
                logger.debug(err, e);
            }
        }
        try {
            requestClose(err + ": " + e);
        } catch (Exception ex) {
        }
        throw new ConnectionException(LocalizedStrings.Connection_UNABLE_TO_READ_DIRECT_ACK_BECAUSE_0.toLocalizedString(e));
    } catch (ConnectionException e) {
        this.owner.getConduit().getCancelCriterion().checkCancelInProgress(e);
        throw e;
    } catch (Exception e) {
        this.owner.getConduit().getCancelCriterion().checkCancelInProgress(e);
        if (!isSocketClosed()) {
            logger.fatal(LocalizedMessage.create(LocalizedStrings.Connection_ACK_READ_EXCEPTION), e);
        }
        try {
            requestClose(LocalizedStrings.Connection_ACK_READ_EXCEPTION_0.toLocalizedString(e));
        } catch (Exception ex) {
        }
        throw new ConnectionException(LocalizedStrings.Connection_UNABLE_TO_READ_DIRECT_ACK_BECAUSE_0.toLocalizedString(e));
    } finally {
        stats.incProcessedMessages(1L);
        accessed();
        this.socketInUse = origSocketInUse;
        if (this.ackTimedOut) {
            logger.info(LocalizedMessage.create(LocalizedStrings.Connection_FINISHED_WAITING_FOR_REPLY_FROM_0, new Object[] { getRemoteAddress() }));
            this.ackTimedOut = false;
        }
        if (msgReader != null) {
            msgReader.close();
        }
    }
    synchronized (stateLock) {
        this.connectionState = STATE_RECEIVED_ACK;
    }
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CancelException(org.apache.geode.CancelException) CancelledKeyException(java.nio.channels.CancelledKeyException) InterruptedIOException(java.io.InterruptedIOException) SocketException(java.net.SocketException) CacheClosedException(org.apache.geode.cache.CacheClosedException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectException(java.net.ConnectException) ClosedChannelException(java.nio.channels.ClosedChannelException) IOException(java.io.IOException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ClosedSelectorException(java.nio.channels.ClosedSelectorException) SocketTimeoutException(java.net.SocketTimeoutException) Header(org.apache.geode.internal.tcp.MsgReader.Header) Version(org.apache.geode.internal.Version) DistributionManager(org.apache.geode.distributed.internal.DistributionManager)

Example 4 with DistributionManager

use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.

the class ShutdownAllRequest method send.

/**
   * Sends a shutdownAll request to all other members and performs local shutdownAll processing in
   * the waitingThreadPool.
   */
public static Set send(final DM dm, long timeout) {
    boolean hadCache = hasCache();
    DistributionManager dism = dm instanceof DistributionManager ? (DistributionManager) dm : null;
    InternalDistributedMember myId = dm.getDistributionManagerId();
    Set recipients = dm.getOtherNormalDistributionManagerIds();
    recipients.remove(myId);
    // now do shutdownall
    ShutdownAllRequest request = new ShutdownAllRequest();
    request.setRecipients(recipients);
    ShutDownAllReplyProcessor replyProcessor = new ShutDownAllReplyProcessor(dm, recipients);
    request.msgId = replyProcessor.getProcessorId();
    dm.putOutgoing(request);
    if (!InternalLocator.isDedicatedLocator()) {
        if (hadCache && dism != null) {
            AdminResponse response;
            try {
                request.setSender(myId);
                response = request.createResponse(dism);
            } catch (Exception ex) {
                if (logger.isDebugEnabled()) {
                    logger.debug("caught exception while processing shutdownAll locally", ex);
                }
                response = AdminFailureResponse.create(dism, myId, ex);
            }
            response.setSender(myId);
            replyProcessor.process(response);
        }
    }
    boolean interrupted = false;
    try {
        if (!replyProcessor.waitForReplies(timeout)) {
            return null;
        }
    } catch (ReplyException e) {
        if (!(e.getCause() instanceof CancelException)) {
            e.handleAsUnexpected();
        }
    } catch (CancelException ignore) {
    // expected
    } catch (InterruptedException ignore) {
        interrupted = true;
    }
    // wait until all the recipients send response, shut down itself (if not a locator)
    if (hadCache) {
        // because the cache is closed at GemFireCacheImpl.getInstance().shutDownAll()
        if (!InternalLocator.isDedicatedLocator()) {
            InternalDistributedSystem ids = dm.getSystem();
            if (ids.isConnected()) {
                ids.disconnect();
            }
        }
    }
    if (interrupted) {
        Thread.currentThread().interrupt();
    }
    try {
        Thread.sleep(3 * SLEEP_TIME_BEFORE_DISCONNECT_DS);
    } catch (InterruptedException ignore) {
    }
    return replyProcessor.getResults();
}
Also used : TreeSet(java.util.TreeSet) Set(java.util.Set) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) CancelException(org.apache.geode.CancelException) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) ReplyException(org.apache.geode.distributed.internal.ReplyException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 5 with DistributionManager

use of org.apache.geode.distributed.internal.DistributionManager in project geode by apache.

the class AlertAppender method append.

/**
   * This method is optimized with the assumption that at least one listener has set a level which
   * requires that the event be sent. This is ensured by modifying the appender's configuration
   * whenever a listener is added or removed.
   */
@Override
public void append(final LogEvent event) {
    if (this.alertingDisabled) {
        return;
    }
    // If already appending then don't send to avoid infinite recursion
    if ((alerting.get())) {
        return;
    }
    setIsAlerting(true);
    try {
        final boolean isDebugEnabled = logger.isDebugEnabled();
        if (isDebugEnabled) {
            logger.debug("Delivering an alert event: {}", event);
        }
        InternalDistributedSystem ds = this.systemRef.get();
        if (ds == null) {
            // Use info level to avoid triggering another alert
            logger.info("Did not append alert event because the distributed system is set to null.");
            return;
        }
        DistributionManager distMgr = (DistributionManager) ds.getDistributionManager();
        final int intLevel = logLevelToAlertLevel(event.getLevel().intLevel());
        final Date date = new Date(event.getTimeMillis());
        final String threadName = event.getThreadName();
        final String logMessage = event.getMessage().getFormattedMessage();
        final String stackTrace = ThreadUtils.stackTraceToString(event.getThrown(), true);
        final String connectionName = ds.getConfig().getName();
        for (Listener listener : this.listeners) {
            if (event.getLevel().intLevel() > listener.getLevel().intLevel()) {
                break;
            }
            try {
                AlertListenerMessage alertMessage = AlertListenerMessage.create(listener.getMember(), intLevel, date, connectionName, threadName, Thread.currentThread().getId(), logMessage, stackTrace);
                if (listener.getMember().equals(distMgr.getDistributionManagerId())) {
                    if (isDebugEnabled) {
                        logger.debug("Delivering local alert message: {}, {}, {}, {}, {}, [{}], [{}].", listener.getMember(), intLevel, date, connectionName, threadName, logMessage, stackTrace);
                    }
                    alertMessage.process(distMgr);
                } else {
                    if (isDebugEnabled) {
                        logger.debug("Delivering remote alert message: {}, {}, {}, {}, {}, [{}], [{}].", listener.getMember(), intLevel, date, connectionName, threadName, logMessage, stackTrace);
                    }
                    distMgr.putOutgoing(alertMessage);
                }
            } catch (ReenteredConnectException e) {
            // OK. We can't send to this recipient because we're in the middle of
            // trying to connect to it.
            }
        }
    } finally {
        setIsAlerting(false);
    }
}
Also used : ReenteredConnectException(org.apache.geode.internal.tcp.ReenteredConnectException) PropertyChangeListener(java.beans.PropertyChangeListener) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) AlertListenerMessage(org.apache.geode.internal.admin.remote.AlertListenerMessage) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Date(java.util.Date)

Aggregations

DistributionManager (org.apache.geode.distributed.internal.DistributionManager)60 Test (org.junit.Test)44 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)36 DistributionMessage (org.apache.geode.distributed.internal.DistributionMessage)29 DistributionMessageObserver (org.apache.geode.distributed.internal.DistributionMessageObserver)29 VM (org.apache.geode.test.dunit.VM)29 Host (org.apache.geode.test.dunit.Host)28 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)25 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)15 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)12 Cache (org.apache.geode.cache.Cache)11 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)11 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)11 IOException (java.io.IOException)9 IgnoredException (org.apache.geode.test.dunit.IgnoredException)9 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)9 Properties (java.util.Properties)8 UnitTest (org.apache.geode.test.junit.categories.UnitTest)8 RequestImageMessage (org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage)7 Region (org.apache.geode.cache.Region)6