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);
}
}
Aggregations