Search in sources :

Example 11 with GridTimeoutObject

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

the class FileWriteAheadLogManager method scheduleNextInactivityPeriodElapsedCheck.

/**
 * Schedules next check of inactivity period expired. Based on current record update timestamp. At timeout method
 * does check of inactivity period and schedules new launch.
 */
private void scheduleNextInactivityPeriodElapsedCheck() {
    final long lastRecMs = lastRecordLoggedMs.get();
    final long nextPossibleAutoArchive = (lastRecMs <= 0 ? U.currentTimeMillis() : lastRecMs) + walAutoArchiveAfterInactivity;
    if (log.isDebugEnabled())
        log.debug("Schedule WAL rollover check at " + new Time(nextPossibleAutoArchive).toString());
    nextAutoArchiveTimeoutObj = new GridTimeoutObject() {

        private final IgniteUuid id = IgniteUuid.randomUuid();

        @Override
        public IgniteUuid timeoutId() {
            return id;
        }

        @Override
        public long endTime() {
            return nextPossibleAutoArchive;
        }

        @Override
        public void onTimeout() {
            if (log.isDebugEnabled())
                log.debug("Checking if WAL rollover required (" + new Time(U.currentTimeMillis()).toString() + ")");
            checkWalRolloverRequiredDuringInactivityPeriod();
            scheduleNextInactivityPeriodElapsedCheck();
        }
    };
    cctx.time().addTimeoutObject(nextAutoArchiveTimeoutObj);
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) Time(java.sql.Time) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject)

Example 12 with GridTimeoutObject

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

the class FsyncModeFileWriteAheadLogManager method stop0.

/**
 * {@inheritDoc}
 */
@Override
protected void stop0(boolean cancel) {
    final GridTimeoutProcessor.CancelableTask schedule = backgroundFlushSchedule;
    if (schedule != null)
        schedule.close();
    final GridTimeoutObject timeoutObj = nextAutoArchiveTimeoutObj;
    if (timeoutObj != null)
        cctx.time().removeTimeoutObject(timeoutObj);
    final FileWriteHandle currHnd = currentHandle();
    try {
        if (mode == WALMode.BACKGROUND) {
            if (currHnd != null)
                currHnd.flush((FileWALPointer) null, true);
        }
        if (currHnd != null)
            currHnd.close(false);
        if (archiver != null)
            archiver.shutdown();
        if (compressor != null)
            compressor.shutdown();
        if (decompressor != null)
            decompressor.shutdown();
    } catch (Exception e) {
        U.error(log, "Failed to gracefully close WAL segment: " + currentHnd.fileIO, e);
    }
}
Also used : GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) StorageException(org.apache.ignite.internal.pagemem.wal.StorageException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject)

Example 13 with GridTimeoutObject

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

the class FsyncModeFileWriteAheadLogManager method scheduleNextInactivityPeriodElapsedCheck.

/**
 * Schedules next check of inactivity period expired. Based on current record update timestamp.
 * At timeout method does check of inactivity period and schedules new launch.
 */
private void scheduleNextInactivityPeriodElapsedCheck() {
    final long lastRecMs = lastRecordLoggedMs.get();
    final long nextPossibleAutoArchive = (lastRecMs <= 0 ? U.currentTimeMillis() : lastRecMs) + walAutoArchiveAfterInactivity;
    if (log.isDebugEnabled())
        log.debug("Schedule WAL rollover check at " + new Time(nextPossibleAutoArchive).toString());
    nextAutoArchiveTimeoutObj = new GridTimeoutObject() {

        private final IgniteUuid id = IgniteUuid.randomUuid();

        @Override
        public IgniteUuid timeoutId() {
            return id;
        }

        @Override
        public long endTime() {
            return nextPossibleAutoArchive;
        }

        @Override
        public void onTimeout() {
            if (log.isDebugEnabled())
                log.debug("Checking if WAL rollover required (" + new Time(U.currentTimeMillis()).toString() + ")");
            checkWalRolloverRequiredDuringInactivityPeriod();
            scheduleNextInactivityPeriodElapsedCheck();
        }
    };
    cctx.time().addTimeoutObject(nextAutoArchiveTimeoutObj);
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) Time(java.sql.Time) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject)

Example 14 with GridTimeoutObject

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

the class GridIoManager method receiveFromChannel.

/**
 * @param topic Topic handler related to.
 * @param rcvCtx Receiver read context.
 * @throws NodeStoppingException If processing fails.
 * @throws InterruptedException If thread interrupted.
 */
private void receiveFromChannel(Object topic, ReceiverContext rcvCtx, ObjectInputStream in, ObjectOutputStream out, ReadableByteChannel ch) throws NodeStoppingException, InterruptedException {
    try {
        while (true) {
            if (Thread.currentThread().isInterrupted())
                throw new InterruptedException("The thread has been interrupted. Stop downloading file.");
            if (stopping)
                throw new NodeStoppingException("Operation has been cancelled (node is stopping)");
            boolean exit = in.readBoolean();
            if (exit) {
                ReceiverContext rcv = rcvCtxs.remove(topic);
                assert rcv != null;
                rcv.hnd.onEnd(rcv.rmtNodeId);
                break;
            }
            TransmissionMeta meta = (TransmissionMeta) in.readObject();
            if (rcvCtx.rcv == null) {
                rcvCtx.rcv = createReceiver(rcvCtx.rmtNodeId, rcvCtx.hnd, meta, () -> stopping || rcvCtx.interrupted.get());
                rcvCtx.lastState = meta;
            }
            validate(rcvCtx.lastState, meta);
            try {
                long startTime = U.currentTimeMillis();
                rcvCtx.rcv.receive(ch);
                // Write processing ack.
                out.writeBoolean(true);
                out.flush();
                rcvCtx.rcv.close();
                U.log(log, "File has been received " + "[name=" + rcvCtx.rcv.state().name() + ", transferred=" + rcvCtx.rcv.transferred() + ", time=" + (double) ((U.currentTimeMillis() - startTime) / 1000) + " sec" + ", rmtId=" + rcvCtx.rmtNodeId + ']');
                rcvCtx.rcv = null;
            } catch (Throwable e) {
                rcvCtx.lastState = rcvCtx.rcv.state();
                throw e;
            }
        }
    } catch (ClassNotFoundException e) {
        throw new IgniteException(e);
    } catch (IOException e) {
        // Waiting for re-establishing connection.
        U.warn(log, "Сonnection from the remote node lost. Will wait for the new one to continue file " + "receive [nodeId=" + rcvCtx.rmtNodeId + ", sesKey=" + rcvCtx.sesId + ']', e);
        long startTs = U.currentTimeMillis();
        boolean added = ctx.timeout().addTimeoutObject(rcvCtx.timeoutObj = new GridTimeoutObject() {

            @Override
            public IgniteUuid timeoutId() {
                return rcvCtx.sesId;
            }

            @Override
            public long endTime() {
                return startTs + netTimeoutMs;
            }

            @Override
            public void onTimeout() {
                interruptReceiver(rcvCtxs.remove(topic), new IgniteCheckedException("Receiver is closed due to " + "waiting for the reconnect has been timeouted"));
            }
        });
        assert added;
    }
}
Also used : NodeStoppingException(org.apache.ignite.internal.NodeStoppingException) IOException(java.io.IOException) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteUuid(org.apache.ignite.lang.IgniteUuid)

Example 15 with GridTimeoutObject

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

the class GridDeploymentPerVersionStore method checkRedeploy.

/**
 * Removes obsolete deployments in case of redeploy.
 *
 * @param meta Request metadata.
 */
private void checkRedeploy(GridDeploymentMetadata meta) {
    assert Thread.holdsLock(mux);
    for (List<SharedDeployment> deps : cache.values()) {
        for (SharedDeployment dep : deps) {
            if (!dep.undeployed() && !dep.pendingUndeploy()) {
                long undeployTimeout = ctx.config().getNetworkTimeout();
                // Only check deployments with no participants.
                if (!dep.hasParticipants() && dep.deployMode() == CONTINUOUS && dep.existingDeployedClass(meta.className()) != null && !meta.userVersion().equals(dep.userVersion())) {
                    // In case of SHARED deployment it is possible to get hear if
                    // unmarshalling happens during undeploy. In this case, we
                    // simply don't do anything.
                    // Change from shared deploy to shared undeploy or user version change.
                    // Simply remove all deployments with no participating nodes.
                    dep.onUndeployScheduled();
                    if (log.isDebugEnabled())
                        log.debug("Deployment was scheduled for undeploy: " + dep);
                    // Lifespan time.
                    final long endTime = U.currentTimeMillis() + undeployTimeout;
                    // Deployment to undeploy.
                    final SharedDeployment undep = dep;
                    if (endTime > 0) {
                        ctx.timeout().addTimeoutObject(new GridTimeoutObject() {

                            @Override
                            public IgniteUuid timeoutId() {
                                return undep.classLoaderId();
                            }

                            @Override
                            public long endTime() {
                                return endTime < 0 ? Long.MAX_VALUE : endTime;
                            }

                            @Override
                            public void onTimeout() {
                                boolean rmv = false;
                                // Hot redeployment.
                                synchronized (mux) {
                                    assert undep.pendingUndeploy();
                                    if (!undep.undeployed()) {
                                        undep.undeploy();
                                        undep.onRemoved();
                                        rmv = true;
                                        Collection<SharedDeployment> deps = cache.get(undep.userVersion());
                                        if (deps != null) {
                                            for (Iterator<SharedDeployment> i = deps.iterator(); i.hasNext(); ) if (i.next() == undep)
                                                i.remove();
                                            if (deps.isEmpty())
                                                cache.remove(undep.userVersion());
                                        }
                                        if (log.isInfoEnabled())
                                            log.info("Undeployed class loader due to deployment mode change, " + "user version change, or hot redeployment: " + undep);
                                    }
                                }
                                // Outside synchronization.
                                if (rmv)
                                    undep.recordUndeployed(null);
                            }
                        });
                    }
                }
            }
        }
    }
}
Also used : IgniteUuid(org.apache.ignite.lang.IgniteUuid) Iterator(java.util.Iterator) Collection(java.util.Collection) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject)

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