Example usage for org.apache.hadoop.fs DF DF

List of usage examples for org.apache.hadoop.fs DF DF

Introduction

In this page you can find the example usage for org.apache.hadoop.fs DF DF.

Prototype

public DF(File path, long dfInterval) throws IOException 

Source Link

Usage

From source file:com.splicemachine.fs.localfs.SpliceFileSystem.java

License:Apache License

/**
 * Moves files to a bad file directory on the same device, so that their
 * storage will not be reused.// w  w  w  .  ja va  2 s .  c o  m
 */
@Override
public boolean reportChecksumFailure(Path p, FSDataInputStream in, long inPos, FSDataInputStream sums,
        long sumsPos) {
    try {
        // canonicalize f
        File f = ((RawLocalFileSystem) fs).pathToFile(p).getCanonicalFile();

        // find highest writable parent dir of f on the same device
        String device = new DF(f, getConf()).getMount();
        File parent = f.getParentFile();
        File dir = null;
        while (parent != null && FileUtil.canWrite(parent) && parent.toString().startsWith(device)) {
            dir = parent;
            parent = parent.getParentFile();
        }

        if (dir == null) {
            throw new IOException("not able to find the highest writable parent dir");
        }

        // move the file there
        File badDir = new File(dir, "bad_files");
        if (!badDir.mkdirs()) {
            if (!badDir.isDirectory()) {
                throw new IOException("Mkdirs failed to create " + badDir.toString());
            }
        }
        String suffix = "." + rand.nextInt();
        File badFile = new File(badDir, f.getName() + suffix);
        LOG.warn("Moving bad file " + f + " to " + badFile);
        in.close(); // close it first
        boolean b = f.renameTo(badFile); // rename it
        if (!b) {
            LOG.warn("Ignoring failure of renameTo");
        }
        // move checksum file too
        File checkFile = ((RawLocalFileSystem) fs).pathToFile(getChecksumFile(p));
        // close the stream before rename to release the file handle
        sums.close();
        b = checkFile.renameTo(new File(badDir, checkFile.getName() + suffix));
        if (!b) {
            LOG.warn("Ignoring failure of renameTo");
        }
    } catch (IOException e) {
        LOG.warn("Error moving bad file " + p + ": " + e);
    }
    return false;
}

From source file:fr.ens.biologie.genomique.eoulsan.MainHadoop.java

License:LGPL

/**
 * Log disk free information./*w w  w . j av  a 2  s .c o  m*/
 * @param f file
 * @param conf Hadoop configuration
 * @throws IOException if an error occurs
 */
private static void df(final File f, final Configuration conf) throws IOException {

    DF df = new DF(f, conf);

    getLogger().info("SYSINFO " + f + " " + StringUtils.sizeToHumanReadable(df.getCapacity()) + " capacity, "
            + StringUtils.sizeToHumanReadable(df.getUsed()) + " used, "
            + StringUtils.sizeToHumanReadable(df.getAvailable()) + " available, " + df.getPercentUsed()
            + "% used");

}

From source file:fr.ens.biologie.genomique.eoulsan.util.hadoop.HadoopInfo.java

License:LGPL

private static void df(final File f, final Configuration conf) throws IOException {

    DF df = new DF(f, conf);

    getLogger().info("SYSINFO " + f + " " + StringUtils.sizeToHumanReadable(df.getCapacity()) + " capacity, "
            + StringUtils.sizeToHumanReadable(df.getUsed()) + " used, "
            + StringUtils.sizeToHumanReadable(df.getAvailable()) + " available, " + df.getPercentUsed()
            + "% used");

}