Search in sources :

Example 1 with MobFile

use of org.apache.hadoop.hbase.mob.MobFile in project hbase by apache.

the class HMobStore method readCell.

/**
 * Reads the cell from a mob file.
 * The mob file might be located in different directories.
 * 1. The working directory.
 * 2. The archive directory.
 * Reads the cell from the files located in both of the above directories.
 * @param locations The possible locations where the mob files are saved.
 * @param fileName The file to be read.
 * @param search The cell to be searched.
 * @param cacheMobBlocks Whether the scanner should cache blocks.
 * @param readPt the read point.
 * @param readEmptyValueOnMobCellMiss Whether return null value when the mob file is
 *        missing or corrupt.
 * @return The found cell. Null if there's no such a cell.
 * @throws IOException
 */
private MobCell readCell(List<Path> locations, String fileName, Cell search, boolean cacheMobBlocks, long readPt, boolean readEmptyValueOnMobCellMiss) throws IOException {
    FileSystem fs = getFileSystem();
    Throwable throwable = null;
    for (Path location : locations) {
        MobFile file = null;
        Path path = new Path(location, fileName);
        try {
            file = mobFileCache.openFile(fs, path, getCacheConfig());
            return readPt != -1 ? file.readCell(search, cacheMobBlocks, readPt) : file.readCell(search, cacheMobBlocks);
        } catch (IOException e) {
            mobFileCache.evictFile(fileName);
            throwable = e;
            if ((e instanceof FileNotFoundException) || (e.getCause() instanceof FileNotFoundException)) {
                LOG.debug("Fail to read the cell, the mob file " + path + " doesn't exist", e);
            } else if (e instanceof CorruptHFileException) {
                LOG.error("The mob file " + path + " is corrupt", e);
                break;
            } else {
                throw e;
            }
        } catch (NullPointerException e) {
            // HDFS 1.x - DFSInputStream.getBlockAt()
            mobFileCache.evictFile(fileName);
            LOG.debug("Fail to read the cell", e);
            throwable = e;
        } catch (AssertionError e) {
            // assert in HDFS 1.x - DFSInputStream.getBlockAt()
            mobFileCache.evictFile(fileName);
            LOG.debug("Fail to read the cell", e);
            throwable = e;
        } finally {
            if (file != null) {
                mobFileCache.closeFile(file);
            }
        }
    }
    LOG.error("The mob file " + fileName + " could not be found in the locations " + locations + " or it is corrupt");
    if (readEmptyValueOnMobCellMiss) {
        return null;
    } else if ((throwable instanceof FileNotFoundException) || (throwable.getCause() instanceof FileNotFoundException)) {
        // doesn't help fix the lost MOB files.
        throw new DoNotRetryIOException(throwable);
    } else if (throwable instanceof IOException) {
        throw (IOException) throwable;
    } else {
        throw new IOException(throwable);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) FileSystem(org.apache.hadoop.fs.FileSystem) FileNotFoundException(java.io.FileNotFoundException) CorruptHFileException(org.apache.hadoop.hbase.io.hfile.CorruptHFileException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) MobFile(org.apache.hadoop.hbase.mob.MobFile)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 FileSystem (org.apache.hadoop.fs.FileSystem)1 Path (org.apache.hadoop.fs.Path)1 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)1 CorruptHFileException (org.apache.hadoop.hbase.io.hfile.CorruptHFileException)1 MobFile (org.apache.hadoop.hbase.mob.MobFile)1