Search in sources :

Example 16 with GridTimeoutObject

use of org.apache.ignite.internal.processors.timeout.GridTimeoutObject in project ignite by apache.

the class GridDhtAtomicCache method sendDeferredUpdateResponse.

/**
 * @param part Partition.
 * @param primaryId Primary ID.
 * @param futId Future ID.
 */
private void sendDeferredUpdateResponse(int part, UUID primaryId, long futId) {
    Map<UUID, GridDhtAtomicDeferredUpdateResponse> resMap = defRes.get();
    GridDhtAtomicDeferredUpdateResponse msg = resMap.get(primaryId);
    if (msg == null) {
        msg = new GridDhtAtomicDeferredUpdateResponse(ctx.cacheId(), new GridLongList(DEFERRED_UPDATE_RESPONSE_BUFFER_SIZE));
        if (DEFERRED_UPDATE_RESPONSE_TIMEOUT > 0) {
            GridTimeoutObject timeoutSnd = new DeferredUpdateTimeout(part, primaryId);
            msg.timeoutSender(timeoutSnd);
            ctx.time().addTimeoutObject(timeoutSnd);
        }
        resMap.put(primaryId, msg);
    }
    GridLongList futIds = msg.futureIds();
    assert futIds.size() < DEFERRED_UPDATE_RESPONSE_BUFFER_SIZE : futIds.size();
    futIds.add(futId);
    if (futIds.size() >= DEFERRED_UPDATE_RESPONSE_BUFFER_SIZE) {
        resMap.remove(primaryId);
        sendDeferredUpdateResponse(primaryId, msg);
    }
}
Also used : GridLongList(org.apache.ignite.internal.util.GridLongList) UUID(java.util.UUID) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject)

Example 17 with GridTimeoutObject

use of org.apache.ignite.internal.processors.timeout.GridTimeoutObject in project ignite by apache.

the class GridDhtPartitionDemander method forceRebalance.

/**
 * @return Rebalance future.
 */
IgniteInternalFuture<Boolean> forceRebalance() {
    GridTimeoutObject obj = lastTimeoutObj.getAndSet(null);
    if (obj != null)
        ctx.time().removeTimeoutObject(obj);
    final GridDhtPartitionsExchangeFuture exchFut = lastExchangeFut;
    if (exchFut != null) {
        if (log.isDebugEnabled())
            log.debug("Forcing rebalance event for future: " + exchFut);
        final GridFutureAdapter<Boolean> fut = new GridFutureAdapter<>();
        exchFut.listen(new CI1<IgniteInternalFuture<AffinityTopologyVersion>>() {

            @Override
            public void apply(IgniteInternalFuture<AffinityTopologyVersion> t) {
                if (t.error() == null) {
                    IgniteInternalFuture<Boolean> fut0 = ctx.exchange().forceRebalance(exchFut.exchangeId());
                    fut0.listen(new IgniteInClosure<IgniteInternalFuture<Boolean>>() {

                        @Override
                        public void apply(IgniteInternalFuture<Boolean> fut1) {
                            try {
                                fut.onDone(fut1.get());
                            } catch (Exception e) {
                                fut.onDone(e);
                            }
                        }
                    });
                } else
                    fut.onDone(t.error());
            }
        });
        return fut;
    } else if (log.isDebugEnabled())
        log.debug("Ignoring force rebalance request (no topology event happened yet).");
    return new GridFinishedFuture<>(true);
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridCacheEntryRemovedException(org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException) GridDhtInvalidPartitionException(org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtInvalidPartitionException) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) GridFinishedFuture(org.apache.ignite.internal.util.future.GridFinishedFuture) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure)

Example 18 with GridTimeoutObject

use of org.apache.ignite.internal.processors.timeout.GridTimeoutObject in project ignite by apache.

the class StartNodeCallableImpl method exec.

/**
 * Executes command using {@code exec} channel with setting encoding.
 *
 * @param ses SSH session.
 * @param cmd Command.
 * @param encoding Process output encoding, {@code null} for default charset encoding.
 * @return Output result.
 * @throws JSchException In case of SSH error.
 * @throws IOException If failed.
 */
private String exec(Session ses, final String cmd, String encoding) throws JSchException, IOException {
    ChannelExec ch = null;
    try {
        ch = (ChannelExec) ses.openChannel("exec");
        ch.setCommand(cmd);
        ch.connect();
        if (encoding == null)
            encoding = Charset.defaultCharset().name();
        GridTimeoutObject to = null;
        SB out = null;
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(ch.getInputStream(), encoding))) {
            String line;
            boolean first = true;
            while ((line = reader.readLine()) != null) {
                if (first)
                    out = new SB();
                else
                    out.a('\n');
                out.a(line);
                if (first) {
                    to = initTimer(cmd);
                    first = false;
                }
            }
        } catch (InterruptedIOException ignore) {
        // No-op.
        } finally {
            if (to != null) {
                boolean r = proc.removeTimeoutObject(to);
                assert r || to.endTime() <= U.currentTimeMillis() : "Timeout object was not removed: " + to;
            }
        }
        return out == null ? null : out.toString();
    } finally {
        if (ch != null && ch.isConnected())
            ch.disconnect();
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) ChannelExec(com.jcraft.jsch.ChannelExec) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Aggregations

GridTimeoutObject (org.apache.ignite.internal.processors.timeout.GridTimeoutObject)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)7 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)5 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)4 IgniteUuid (org.apache.ignite.lang.IgniteUuid)4 IOException (java.io.IOException)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 Map (java.util.Map)3 UUID (java.util.UUID)3 IgniteEx (org.apache.ignite.internal.IgniteEx)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 GridCacheEntryRemovedException (org.apache.ignite.internal.processors.cache.GridCacheEntryRemovedException)3 GridTimeoutObjectAdapter (org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter)3 EOFException (java.io.EOFException)2 FileNotFoundException (java.io.FileNotFoundException)2 Time (java.sql.Time)2 ArrayList (java.util.ArrayList)2