Search in sources :

Example 6 with StatefulStorageException

use of org.apache.heron.spi.statefulstorage.StatefulStorageException in project heron by twitter.

the class LocalFileSystemStorage method cleanCheckpoints.

protected void cleanCheckpoints(File rootFile, int remaining) throws StatefulStorageException {
    if (FileUtils.isDirectoryExists(rootFile.getAbsolutePath()) && FileUtils.hasChildren(rootFile.getAbsolutePath())) {
        String[] children = rootFile.list();
        Arrays.sort(children);
        // only keep the latest N remaining files, delete others
        for (int i = 0; i < children.length - remaining; i++) {
            File ckptFile = new File(rootFile.getAbsolutePath(), children[i]);
            FileUtils.deleteDir(ckptFile, true);
            if (FileUtils.isDirectoryExists(ckptFile.getAbsolutePath())) {
                throw new StatefulStorageException("Failed to delete " + ckptFile.getAbsolutePath());
            }
        }
    }
}
Also used : StatefulStorageException(org.apache.heron.spi.statefulstorage.StatefulStorageException) File(java.io.File) Checkpoint(org.apache.heron.spi.statefulstorage.Checkpoint)

Example 7 with StatefulStorageException

use of org.apache.heron.spi.statefulstorage.StatefulStorageException in project heron by twitter.

the class HDFSStorage method storeCheckpoint.

@Override
public void storeCheckpoint(CheckpointInfo info, Checkpoint checkpoint) throws StatefulStorageException {
    Path path = new Path(getCheckpointPath(info.getCheckpointId(), info.getComponent(), info.getInstanceId()));
    // We need to ensure the existence of directories structure,
    // since it is not guaranteed that FileSystem.create(..) always creates parents' dirs.
    String checkpointDir = getCheckpointDir(info.getCheckpointId(), info.getComponent());
    createDir(checkpointDir);
    FSDataOutputStream out = null;
    try {
        out = fileSystem.create(path);
        checkpoint.getCheckpoint().writeTo(out);
    } catch (IOException e) {
        throw new StatefulStorageException("Failed to persist", e);
    } finally {
        SysUtils.closeIgnoringExceptions(out);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) StatefulStorageException(org.apache.heron.spi.statefulstorage.StatefulStorageException) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) IOException(java.io.IOException)

Example 8 with StatefulStorageException

use of org.apache.heron.spi.statefulstorage.StatefulStorageException in project heron by twitter.

the class HDFSStorage method dispose.

@Override
public void dispose(String oldestCheckpointPreserved, boolean deleteAll) throws StatefulStorageException {
    String topologyCheckpointRoot = getTopologyCheckpointRoot();
    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(org.apache.heron.spi.statefulstorage.StatefulStorageException) FileStatus(org.apache.hadoop.fs.FileStatus) IOException(java.io.IOException)

Example 9 with StatefulStorageException

use of org.apache.heron.spi.statefulstorage.StatefulStorageException in project heron by twitter.

the class HDFSStorage method init.

@Override
public void init(String topology, final Map<String, Object> conf) throws StatefulStorageException {
    LOG.info("Initializing... Config: " + conf.toString());
    LOG.info("Class path: " + System.getProperty("java.class.path"));
    this.topologyName = topology;
    checkpointRootPath = (String) conf.get(ROOT_PATH_KEY);
    // Notice, we pass the config folder via classpath
    // So hadoop will automatically search config files from classpath
    Configuration hadoopConfig = new Configuration();
    try {
        fileSystem = FileSystem.get(hadoopConfig);
        LOG.info("Hadoop FileSystem URI: " + fileSystem.getUri() + " ; Home Dir: " + fileSystem.getHomeDirectory());
    } catch (IOException e) {
        throw new StatefulStorageException("Failed to get hadoop file system", e);
    }
}
Also used : StatefulStorageException(org.apache.heron.spi.statefulstorage.StatefulStorageException) Configuration(org.apache.hadoop.conf.Configuration) IOException(java.io.IOException)

Example 10 with StatefulStorageException

use of org.apache.heron.spi.statefulstorage.StatefulStorageException in project heron by twitter.

the class HDFSStorage method restoreCheckpoint.

@Override
public Checkpoint restoreCheckpoint(CheckpointInfo info) throws StatefulStorageException {
    Path path = new Path(getCheckpointPath(info.getCheckpointId(), info.getComponent(), info.getInstanceId()));
    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(state);
}
Also used : Path(org.apache.hadoop.fs.Path) StatefulStorageException(org.apache.heron.spi.statefulstorage.StatefulStorageException) Checkpoint(org.apache.heron.spi.statefulstorage.Checkpoint) CheckpointManager(org.apache.heron.proto.ckptmgr.CheckpointManager) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) IOException(java.io.IOException)

Aggregations

StatefulStorageException (org.apache.heron.spi.statefulstorage.StatefulStorageException)15 IOException (java.io.IOException)8 Checkpoint (org.apache.heron.spi.statefulstorage.Checkpoint)6 CheckpointManager (org.apache.heron.proto.ckptmgr.CheckpointManager)4 ByteString (com.google.protobuf.ByteString)3 Path (org.apache.hadoop.fs.Path)3 Common (org.apache.heron.proto.system.Common)3 File (java.io.File)2 CheckpointInfo (org.apache.heron.spi.statefulstorage.CheckpointInfo)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)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 DLInputStream (org.apache.heron.dlog.DLInputStream)1 DLOutputStream (org.apache.heron.dlog.DLOutputStream)1