Search in sources :

Example 1 with TraceException

use of org.infinispan.commons.util.logging.TraceException in project infinispan by infinispan.

the class JGroupsBackupResponse method waitForBackupToFinish.

@Override
public void waitForBackupToFinish() throws Exception {
    long deductFromTimeout = timeService.timeDuration(sendTimeNanos, MILLISECONDS);
    errors = new HashMap<>(backupCalls.size());
    long elapsedTime = 0;
    boolean hasSyncBackups = false;
    for (Map.Entry<XSiteBackup, CompletableFuture<ValidResponse>> entry : backupCalls.entrySet()) {
        XSiteBackup xSiteBackup = entry.getKey();
        if (!xSiteBackup.isSync()) {
            continue;
        }
        hasSyncBackups = true;
        long timeout = xSiteBackup.getTimeout();
        String siteName = xSiteBackup.getSiteName();
        if (timeout > 0) {
            // 0 means wait forever
            timeout -= deductFromTimeout;
            timeout -= elapsedTime;
            if (timeout <= 0 && !entry.getValue().isDone()) {
                log.tracef("Timeout period %d exhausted with site %s", xSiteBackup.getTimeout(), siteName);
                errors.put(siteName, newTimeoutException(xSiteBackup.getTimeout(), xSiteBackup));
                addCommunicationError(siteName);
                continue;
            }
        }
        long startNanos = timeService.time();
        Response response = null;
        try {
            response = entry.getValue().get(timeout, MILLISECONDS);
        } catch (java.util.concurrent.TimeoutException te) {
            errors.put(siteName, newTimeoutException(xSiteBackup.getTimeout(), xSiteBackup));
            addCommunicationError(siteName);
        } catch (ExecutionException ue) {
            Throwable cause = ue.getCause();
            cause.addSuppressed(new TraceException());
            log.tracef(cause, "Communication error with site %s", siteName);
            errors.put(siteName, filterException(cause));
            addCommunicationError(siteName);
        } finally {
            elapsedTime += timeService.timeDuration(startNanos, MILLISECONDS);
        }
        log.tracef("Received response from site %s: %s", siteName, response);
    }
    if (hasSyncBackups) {
        timeElapsedConsumer.accept(timeService.timeDuration(sendTimeNanos, MILLISECONDS));
    }
}
Also used : XSiteBackup(org.infinispan.xsite.XSiteBackup) Util.formatString(org.infinispan.commons.util.Util.formatString) BackupResponse(org.infinispan.remoting.transport.BackupResponse) Response(org.infinispan.remoting.responses.Response) ValidResponse(org.infinispan.remoting.responses.ValidResponse) TraceException(org.infinispan.commons.util.logging.TraceException) CompletableFuture(java.util.concurrent.CompletableFuture) ExecutionException(java.util.concurrent.ExecutionException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with TraceException

use of org.infinispan.commons.util.logging.TraceException in project infinispan by infinispan.

the class JGroupsTransport method invokeRemotely.

@Override
@Deprecated
public Map<Address, Response> invokeRemotely(Map<Address, ReplicableCommand> commands, ResponseMode mode, long timeout, ResponseFilter responseFilter, DeliverOrder deliverOrder, boolean anycast) throws Exception {
    if (commands == null || commands.isEmpty()) {
        // don't send if recipients list is empty
        log.trace("Destination list is empty: no need to send message");
        return Collections.emptyMap();
    }
    if (mode.isSynchronous()) {
        MapResponseCollector collector = MapResponseCollector.validOnly(commands.size());
        CompletionStage<Map<Address, Response>> request = invokeCommands(commands.keySet(), commands::get, collector, deliverOrder, timeout, TimeUnit.MILLISECONDS);
        try {
            return CompletableFutures.await(request.toCompletableFuture());
        } catch (ExecutionException e) {
            Throwable cause = e.getCause();
            cause.addSuppressed(new TraceException());
            throw Util.rewrapAsCacheException(cause);
        }
    } else {
        commands.forEach((a, command) -> {
            logCommand(command, a);
            sendCommand(a, command, Request.NO_REQUEST_ID, deliverOrder, true, true);
        });
        return Collections.emptyMap();
    }
}
Also used : TraceException(org.infinispan.commons.util.logging.TraceException) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MapResponseCollector(org.infinispan.remoting.transport.impl.MapResponseCollector) FilterMapResponseCollector(org.infinispan.remoting.transport.impl.FilterMapResponseCollector) SingletonMapResponseCollector(org.infinispan.remoting.transport.impl.SingletonMapResponseCollector)

Example 3 with TraceException

use of org.infinispan.commons.util.logging.TraceException in project infinispan by infinispan.

the class RemoteInnerPublisherHandler method handleThrowableInResponse.

@Override
protected void handleThrowableInResponse(Throwable t, Map.Entry<SocketAddress, IntSet> target) {
    if (t instanceof TransportException || t instanceof RemoteIllegalLifecycleStateException) {
        log.throwableDuringPublisher(t);
        if (log.isTraceEnabled()) {
            IntSet targetSegments = target.getValue();
            if (targetSegments != null) {
                log.tracef("There are still outstanding segments %s that will need to be retried", targetSegments);
            }
        }
        publisher.erroredServer(target.getKey());
        // Try next target if possible
        targetComplete();
        accept(0);
    } else {
        t.addSuppressed(new TraceException());
        super.handleThrowableInResponse(t, target);
    }
}
Also used : TraceException(org.infinispan.commons.util.logging.TraceException) IntSet(org.infinispan.commons.util.IntSet) RemoteIllegalLifecycleStateException(org.infinispan.client.hotrod.exceptions.RemoteIllegalLifecycleStateException) TransportException(org.infinispan.client.hotrod.exceptions.TransportException)

Example 4 with TraceException

use of org.infinispan.commons.util.logging.TraceException in project infinispan by infinispan.

the class Transport method invokeRemotely.

/**
 * @deprecated Since 9.2, please use {@link #invokeRemotelyAsync(Collection, ReplicableCommand, ResponseMode, long, ResponseFilter, DeliverOrder, boolean)} instead.
 */
@Deprecated
default Map<Address, Response> invokeRemotely(Map<Address, ReplicableCommand> rpcCommands, ResponseMode mode, long timeout, ResponseFilter responseFilter, DeliverOrder deliverOrder, boolean anycast) throws Exception {
    // This overload didn't have an async version, so implement it on top of the regular invokeRemotelyAsync
    Map<Address, Response> result = new ConcurrentHashMap<>(rpcCommands.size());
    ResponseFilter partResponseFilter = new ResponseFilter() {

        @Override
        public boolean isAcceptable(Response response, Address sender) {
            // Guarantee collector.addResponse() isn't called concurrently
            synchronized (result) {
                result.put(sender, response);
                return responseFilter.isAcceptable(response, sender);
            }
        }

        @Override
        public boolean needMoreResponses() {
            return responseFilter.needMoreResponses();
        }
    };
    List<CompletableFuture<Map<Address, Response>>> futures = new ArrayList<>(rpcCommands.size());
    for (Map.Entry<Address, ReplicableCommand> e : rpcCommands.entrySet()) {
        futures.add(invokeRemotelyAsync(Collections.singleton(e.getKey()), e.getValue(), mode, timeout, partResponseFilter, deliverOrder, anycast));
    }
    try {
        // no need to set a timeout for the future. The rpc invocation is guaranteed to complete within the timeout
        // milliseconds
        CompletableFutures.await(CompletableFuture.allOf(futures.toArray(new CompletableFuture[rpcCommands.size()])));
        return result;
    } catch (ExecutionException e) {
        Throwable cause = e.getCause();
        cause.addSuppressed(new TraceException());
        throw Util.rewrapAsCacheException(cause);
    }
}
Also used : ReplicableCommand(org.infinispan.commands.ReplicableCommand) ArrayList(java.util.ArrayList) Response(org.infinispan.remoting.responses.Response) TraceException(org.infinispan.commons.util.logging.TraceException) CompletableFuture(java.util.concurrent.CompletableFuture) ResponseFilter(org.infinispan.remoting.rpc.ResponseFilter) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

TraceException (org.infinispan.commons.util.logging.TraceException)4 Map (java.util.Map)3 ExecutionException (java.util.concurrent.ExecutionException)3 HashMap (java.util.HashMap)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Response (org.infinispan.remoting.responses.Response)2 ArrayList (java.util.ArrayList)1 RemoteIllegalLifecycleStateException (org.infinispan.client.hotrod.exceptions.RemoteIllegalLifecycleStateException)1 TransportException (org.infinispan.client.hotrod.exceptions.TransportException)1 ReplicableCommand (org.infinispan.commands.ReplicableCommand)1 IntSet (org.infinispan.commons.util.IntSet)1 Util.formatString (org.infinispan.commons.util.Util.formatString)1 ValidResponse (org.infinispan.remoting.responses.ValidResponse)1 ResponseFilter (org.infinispan.remoting.rpc.ResponseFilter)1 BackupResponse (org.infinispan.remoting.transport.BackupResponse)1 FilterMapResponseCollector (org.infinispan.remoting.transport.impl.FilterMapResponseCollector)1 MapResponseCollector (org.infinispan.remoting.transport.impl.MapResponseCollector)1 SingletonMapResponseCollector (org.infinispan.remoting.transport.impl.SingletonMapResponseCollector)1 XSiteBackup (org.infinispan.xsite.XSiteBackup)1