Search in sources :

Example 1 with AsyncStorageAgent

use of org.apache.apex.common.util.AsyncStorageAgent in project apex-core by apache.

the class Node method checkpoint.

void checkpoint(long windowId) {
    if (!context.stateless) {
        if (operator instanceof Operator.CheckpointNotificationListener) {
            ((Operator.CheckpointNotificationListener) operator).beforeCheckpoint(windowId);
        }
        StorageAgent ba = context.getValue(OperatorContext.STORAGE_AGENT);
        if (ba != null) {
            try {
                checkpointStats = new Stats.CheckpointStats();
                checkpointStats.checkpointStartTime = System.currentTimeMillis();
                ba.save(operator, id, windowId);
                if (ba instanceof AsyncStorageAgent) {
                    AsyncStorageAgent asyncStorageAgent = (AsyncStorageAgent) ba;
                    if (!asyncStorageAgent.isSyncCheckpoint()) {
                        if (PROCESSING_MODE != ProcessingMode.EXACTLY_ONCE) {
                            CheckpointWindowInfo checkpointWindowInfo = new CheckpointWindowInfo();
                            checkpointWindowInfo.windowId = windowId;
                            checkpointWindowInfo.applicationWindowCount = applicationWindowCount;
                            checkpointWindowInfo.checkpointWindowCount = checkpointWindowCount;
                            CheckpointHandler checkpointHandler = new CheckpointHandler();
                            checkpointHandler.agent = asyncStorageAgent;
                            checkpointHandler.operatorId = id;
                            checkpointHandler.windowId = windowId;
                            checkpointHandler.stats = checkpointStats;
                            FutureTask<Stats.CheckpointStats> futureTask = new FutureTask<>(checkpointHandler);
                            taskQueue.add(new Pair<>(futureTask, checkpointWindowInfo));
                            executorService.submit(futureTask);
                            checkpoint = null;
                            checkpointStats = null;
                            return;
                        } else {
                            asyncStorageAgent.flush(id, windowId);
                        }
                    }
                }
                checkpointStats.checkpointTime = System.currentTimeMillis() - checkpointStats.checkpointStartTime;
            } catch (IOException ie) {
                try {
                    logger.warn("Rolling back checkpoint {} for Operator {} due to the exception {}", Codec.getStringWindowId(windowId), operator, ie);
                    ba.delete(id, windowId);
                } catch (IOException ex) {
                    logger.warn("Error while rolling back checkpoint", ex);
                }
                throw new RuntimeException(ie);
            }
        }
    }
    calculateNextCheckpointWindow();
    dagCheckpointOffsetCount = 0;
    checkpoint = new Checkpoint(windowId, applicationWindowCount, checkpointWindowCount);
    if (operator instanceof Operator.CheckpointListener) {
        ((Operator.CheckpointListener) operator).checkpointed(windowId);
    }
}
Also used : IOException(java.io.IOException) Checkpoint(com.datatorrent.stram.api.Checkpoint) AsyncStorageAgent(org.apache.apex.common.util.AsyncStorageAgent) FutureTask(java.util.concurrent.FutureTask) AsyncStorageAgent(org.apache.apex.common.util.AsyncStorageAgent) StorageAgent(com.datatorrent.api.StorageAgent) Stats(com.datatorrent.api.Stats) ContainerStats(com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.ContainerStats)

Example 2 with AsyncStorageAgent

use of org.apache.apex.common.util.AsyncStorageAgent in project apex-core by apache.

the class PhysicalPlan method initCheckpoint.

private void initCheckpoint(PTOperator oper, Operator oo, Checkpoint checkpoint) {
    try {
        LOG.debug("Writing activation checkpoint {} {} {}", checkpoint, oper, oo);
        long windowId = oper.isOperatorStateLess() ? Stateless.WINDOW_ID : checkpoint.windowId;
        StorageAgent agent = oper.operatorMeta.getValue(OperatorContext.STORAGE_AGENT);
        agent.save(oo, oper.id, windowId);
        if (agent instanceof AsyncStorageAgent) {
            ((AsyncStorageAgent) agent).flush(oper.id, windowId);
        }
    } catch (IOException e) {
        // inconsistent state, no recovery option, requires shutdown
        throw new IllegalStateException("Failed to write operator state after partition change " + oper, e);
    }
    oper.setRecoveryCheckpoint(checkpoint);
    if (!Checkpoint.INITIAL_CHECKPOINT.equals(checkpoint)) {
        oper.checkpoints.add(checkpoint);
    }
}
Also used : AsyncStorageAgent(org.apache.apex.common.util.AsyncStorageAgent) AsyncStorageAgent(org.apache.apex.common.util.AsyncStorageAgent) StorageAgent(com.datatorrent.api.StorageAgent) IOException(java.io.IOException)

Aggregations

StorageAgent (com.datatorrent.api.StorageAgent)2 IOException (java.io.IOException)2 AsyncStorageAgent (org.apache.apex.common.util.AsyncStorageAgent)2 Stats (com.datatorrent.api.Stats)1 Checkpoint (com.datatorrent.stram.api.Checkpoint)1 ContainerStats (com.datatorrent.stram.api.StreamingContainerUmbilicalProtocol.ContainerStats)1 FutureTask (java.util.concurrent.FutureTask)1