Search in sources :

Example 11 with StatefulStorageException

use of com.twitter.heron.spi.statefulstorage.StatefulStorageException in project incubator-heron by apache.

the class DlogStorage method init.

@Override
public void init(Map<String, Object> conf) throws StatefulStorageException {
    LOG.info("Initializing ... Config: " + conf.toString());
    LOG.info("Class path: " + System.getProperty("java.class.path"));
    checkpointNamespaceUriStr = (String) conf.get(NS_URI_KEY);
    checkpointNamespaceUri = URI.create(checkpointNamespaceUriStr);
    Integer numReplicasValue = (Integer) conf.get(NUM_REPLICAS_KEY);
    this.numReplicas = null == numReplicasValue ? 3 : numReplicasValue;
    try {
        this.namespace = initializeNamespace(checkpointNamespaceUri);
    } catch (IOException ioe) {
        throw new StatefulStorageException("Failed to open distributedlog namespace @ " + checkpointNamespaceUri, ioe);
    }
}
Also used : StatefulStorageException(com.twitter.heron.spi.statefulstorage.StatefulStorageException) IOException(java.io.IOException)

Example 12 with StatefulStorageException

use of com.twitter.heron.spi.statefulstorage.StatefulStorageException in project incubator-heron by apache.

the class HDFSStorage method dispose.

@Override
public void dispose(String topologyName, String oldestCheckpointPreserved, boolean deleteAll) throws StatefulStorageException {
    String topologyCheckpointRoot = getTopologyCheckpointRoot(topologyName);
    Path topologyRootPath = new Path(topologyCheckpointRoot);
    if (deleteAll) {
        // Clean all checkpoint states
        try {
            fileSystem.delete(topologyRootPath, true);
            if (fileSystem.exists(topologyRootPath)) {
                throw new StatefulStorageException("Failed to delete " + topologyRootPath);
            }
        } catch (IOException e) {
            throw new StatefulStorageException("Error while deleting " + topologyRootPath, e);
        }
    } else {
        try {
            FileStatus[] statuses = fileSystem.listStatus(topologyRootPath);
            for (FileStatus status : statuses) {
                String name = status.getPath().getName();
                if (name.compareTo(oldestCheckpointPreserved) < 0) {
                    fileSystem.delete(status.getPath(), true);
                }
            }
            // Do a double check. Now all checkpoints with smaller checkpoint id should be cleaned
            statuses = fileSystem.listStatus(topologyRootPath);
            for (FileStatus status : statuses) {
                String name = status.getPath().getName();
                if (name.compareTo(oldestCheckpointPreserved) < 0) {
                    throw new StatefulStorageException("Error while deleting " + name);
                }
            }
        } catch (IOException e) {
            throw new StatefulStorageException("Failed to clean to: " + oldestCheckpointPreserved, e);
        }
    }
}
Also used : Path(org.apache.hadoop.fs.Path) StatefulStorageException(com.twitter.heron.spi.statefulstorage.StatefulStorageException) FileStatus(org.apache.hadoop.fs.FileStatus) IOException(java.io.IOException)

Example 13 with StatefulStorageException

use of com.twitter.heron.spi.statefulstorage.StatefulStorageException in project incubator-heron by apache.

the class HDFSStorage method restore.

@Override
public Checkpoint restore(String topologyName, String checkpointId, PhysicalPlans.Instance instanceInfo) throws StatefulStorageException {
    Path path = new Path(getCheckpointPath(topologyName, checkpointId, instanceInfo.getInfo().getComponentName(), instanceInfo.getInfo().getTaskId()));
    FSDataInputStream in = null;
    CheckpointManager.InstanceStateCheckpoint state = null;
    try {
        in = fileSystem.open(path);
        state = CheckpointManager.InstanceStateCheckpoint.parseFrom(in);
    } catch (IOException e) {
        throw new StatefulStorageException("Failed to read", e);
    } finally {
        SysUtils.closeIgnoringExceptions(in);
    }
    return new Checkpoint(topologyName, instanceInfo, state);
}
Also used : Path(org.apache.hadoop.fs.Path) StatefulStorageException(com.twitter.heron.spi.statefulstorage.StatefulStorageException) Checkpoint(com.twitter.heron.spi.statefulstorage.Checkpoint) CheckpointManager(com.twitter.heron.proto.ckptmgr.CheckpointManager) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) IOException(java.io.IOException)

Aggregations

StatefulStorageException (com.twitter.heron.spi.statefulstorage.StatefulStorageException)13 IOException (java.io.IOException)8 Checkpoint (com.twitter.heron.spi.statefulstorage.Checkpoint)5 CheckpointManager (com.twitter.heron.proto.ckptmgr.CheckpointManager)4 ByteString (com.google.protobuf.ByteString)3 Common (com.twitter.heron.proto.system.Common)3 Path (org.apache.hadoop.fs.Path)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 DLInputStream (com.twitter.heron.dlog.DLInputStream)1 DLOutputStream (com.twitter.heron.dlog.DLOutputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 Namespace (org.apache.distributedlog.api.namespace.Namespace)1 Configuration (org.apache.hadoop.conf.Configuration)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 FileStatus (org.apache.hadoop.fs.FileStatus)1