Search in sources :

Example 1 with StateHandler

use of edu.snu.mist.core.operators.StateHandler in project mist by snuspl.

the class DefaultGroupImpl method getQueryCheckpoint.

/**
 * Get the checkpoint data for the query.
 */
private QueryCheckpoint getQueryCheckpoint(final DAG<ConfigVertex, MISTEdge> configDag, final GroupMinimumLatestWatermarkTimeStamp groupTimestamp) {
    // Find the minimum of the available checkpoint timestamps for the group.
    // Replaying will start from this timestamp, if this ConfigDag is used for recovery.
    // This is initiated as Long.MAX_VALUE, as this means that there are no stateful operators within this dag,
    // and therefore requires no replay.
    long latestWatermarkTimestamp = Long.MAX_VALUE;
    for (final ConfigVertex cv : configDag.getVertices()) {
        final ExecutionVertex ev = configExecutionVertexMap.get(cv);
        if (ev.getType() == ExecutionVertex.Type.OPERATOR) {
            final Operator op = ((DefaultPhysicalOperatorImpl) ev).getOperator();
            if (op instanceof StateHandler) {
                final StateHandler stateHandler = (StateHandler) op;
                latestWatermarkTimestamp = stateHandler.getLatestTimestampBeforeCheckpoint();
                groupTimestamp.compareAndSetIfSmaller(latestWatermarkTimestamp);
            }
        }
    }
    final Map<String, StateWithTimestamp> stateWithTimestampMap = new HashMap<>();
    for (final ConfigVertex cv : configDag.getVertices()) {
        final ExecutionVertex ev = configExecutionVertexMap.get(cv);
        Map<String, Object> state = null;
        long checkpointTimestamp = 0L;
        if (ev.getType() == ExecutionVertex.Type.OPERATOR) {
            final Operator op = ((DefaultPhysicalOperatorImpl) ev).getOperator();
            if (op instanceof StateHandler) {
                final StateHandler stateHandler = (StateHandler) op;
                checkpointTimestamp = stateHandler.getMaxAvailableTimestamp(groupTimestamp.getValue());
                state = StateSerializer.serializeStateMap(stateHandler.getOperatorState(checkpointTimestamp));
            }
        }
        stateWithTimestampMap.put(cv.getId(), StateWithTimestamp.newBuilder().setVertexState(state).setCheckpointTimestamp(checkpointTimestamp).build());
    }
    return QueryCheckpoint.newBuilder().setQueryState(stateWithTimestampMap).build();
}
Also used : Operator(edu.snu.mist.core.operators.Operator) StateHandler(edu.snu.mist.core.operators.StateHandler)

Example 2 with StateHandler

use of edu.snu.mist.core.operators.StateHandler in project mist by snuspl.

the class DefaultGroupCheckpointStore method checkpointGroupStates.

@Override
public CheckpointResult checkpointGroupStates(final Tuple<String, Group> tuple) {
    final String groupId = tuple.getKey();
    final Group group = tuple.getValue();
    final GroupCheckpoint checkpoint = group.checkpoint();
    try {
        // Write the file.
        final File storedFile = getGroupCheckpointFile(groupId);
        if (storedFile.exists()) {
            storedFile.delete();
            LOG.log(Level.INFO, "Checkpoint deleted for groupId: {0}", groupId);
        }
        final DataFileWriter<GroupCheckpoint> dataFileWriter = new DataFileWriter<>(groupCheckpointDatumWriter);
        dataFileWriter.create(checkpoint.getSchema(), storedFile);
        dataFileWriter.append(checkpoint);
        dataFileWriter.close();
        LOG.log(Level.INFO, "Checkpoint completed for groupId: {0}", groupId);
    } catch (final Exception e) {
        e.printStackTrace();
        return CheckpointResult.newBuilder().setIsSuccess(false).setMsg("Unsuccessful in checkpointing group " + tuple.getKey()).setPathToCheckpoint("").build();
    }
    // Delete all the unnecessary states within the stateMaps of stateful operators.
    for (final ExecutionDag ed : group.getExecutionDags().values()) {
        for (final ExecutionVertex ev : ed.getDag().getVertices()) {
            if (ev.getType() == ExecutionVertex.Type.OPERATOR) {
                final Operator op = ((DefaultPhysicalOperatorImpl) ev).getOperator();
                if (op instanceof StateHandler) {
                    final StateHandler stateHandler = (StateHandler) op;
                    stateHandler.removeOldStates(checkpoint.getCheckpointTimestamp());
                }
            }
        }
    }
    return CheckpointResult.newBuilder().setIsSuccess(true).setMsg("Successfully checkpointed group " + tuple.getKey()).setPathToCheckpoint(getGroupCheckpointFile(groupId).toString()).build();
}
Also used : GroupCheckpoint(edu.snu.mist.formats.avro.GroupCheckpoint) Operator(edu.snu.mist.core.operators.Operator) Group(edu.snu.mist.core.task.groupaware.Group) StateHandler(edu.snu.mist.core.operators.StateHandler) DataFileWriter(org.apache.avro.file.DataFileWriter) DefaultPhysicalOperatorImpl(edu.snu.mist.core.task.DefaultPhysicalOperatorImpl) ExecutionDag(edu.snu.mist.core.task.ExecutionDag) File(java.io.File) IOException(java.io.IOException) ExecutionVertex(edu.snu.mist.core.task.ExecutionVertex)

Aggregations

Operator (edu.snu.mist.core.operators.Operator)2 StateHandler (edu.snu.mist.core.operators.StateHandler)2 DefaultPhysicalOperatorImpl (edu.snu.mist.core.task.DefaultPhysicalOperatorImpl)1 ExecutionDag (edu.snu.mist.core.task.ExecutionDag)1 ExecutionVertex (edu.snu.mist.core.task.ExecutionVertex)1 Group (edu.snu.mist.core.task.groupaware.Group)1 GroupCheckpoint (edu.snu.mist.formats.avro.GroupCheckpoint)1 File (java.io.File)1 IOException (java.io.IOException)1 DataFileWriter (org.apache.avro.file.DataFileWriter)1