/** * Checks a path to see if it is a valid hfile. * * @param p * full Path to an HFile * @throws IOException * This is a connectivity related exception */ protected void checkHFile(Path p) throws IOException { HFile.Reader r = null; try { r = HFile.createReader(fs, p, cacheConf, conf); } catch (CorruptHFileException che) { LOG.warn("Found corrupt HFile " + p, che); corrupted.add(p); if (inQuarantineMode) { Path dest = createQuarantinePath(p); LOG.warn("Quarantining corrupt HFile " + p + " into " + dest); boolean success = fs.mkdirs(dest.getParent()); success = success ? fs.rename(p, dest): false; if (!success) { failures.add(p); } else { quarantined.add(dest); } } return; } catch (FileNotFoundException fnfe) { LOG.warn("HFile " + p + " was missing. Likely removed due to compaction/split?"); missing.add(p); } finally { hfilesChecked.addAndGet(1); if (r != null) { r.close(true); } } }
/** * Checks a path to see if it is a valid hfile. * * @param p * full Path to an HFile * @throws IOException * This is a connectivity related exception */ protected void checkHFile(Path p) throws IOException { HFile.Reader r = null; try { r = HFile.createReader(fs, p, cacheConf); } catch (CorruptHFileException che) { LOG.warn("Found corrupt HFile " + p, che); corrupted.add(p); if (inQuarantineMode) { Path dest = createQuarantinePath(p); LOG.warn("Quarantining corrupt HFile " + p + " into " + dest); boolean success = fs.mkdirs(dest.getParent()); success = success ? fs.rename(p, dest): false; if (!success) { failures.add(p); } else { quarantined.add(dest); } } return; } catch (FileNotFoundException fnfe) { LOG.warn("HFile " + p + " was missing. Likely removed due to compaction/split?"); missing.add(p); } finally { hfilesChecked.addAndGet(1); if (r != null) { r.close(true); } } }
/** * Checks a path to see if it is a valid hfile. * * @param p * full Path to an HFile * @throws IOException * This is a connectivity related exception */ protected void checkHFile(Path p) throws IOException { HFile.Reader r = null; try { r = HFile.createReader(fs, p, cacheConf, true, conf); } catch (CorruptHFileException che) { LOG.warn("Found corrupt HFile " + p, che); corrupted.add(p); if (inQuarantineMode) { Path dest = createQuarantinePath(p); LOG.warn("Quarantining corrupt HFile " + p + " into " + dest); boolean success = fs.mkdirs(dest.getParent()); success = success ? fs.rename(p, dest): false; if (!success) { failures.add(p); } else { quarantined.add(dest); } } return; } catch (FileNotFoundException fnfe) { LOG.warn("HFile " + p + " was missing. Likely removed due to compaction/split?"); missing.add(p); } finally { hfilesChecked.addAndGet(1); if (r != null) { r.close(true); } } }
/** * Checks a path to see if it is a valid mob file. * * @param p * full Path to a mob file. * @throws IOException * This is a connectivity related exception */ protected void checkMobFile(Path p) throws IOException { HFile.Reader r = null; try { r = HFile.createReader(fs, p, cacheConf, true, conf); } catch (CorruptHFileException che) { LOG.warn("Found corrupt mob file " + p, che); corruptedMobFiles.add(p); if (inQuarantineMode) { Path dest = createQuarantinePath(p); LOG.warn("Quarantining corrupt mob file " + p + " into " + dest); boolean success = fs.mkdirs(dest.getParent()); success = success ? fs.rename(p, dest): false; if (!success) { failureMobFiles.add(p); } else { quarantinedMobFiles.add(dest); } } return; } catch (FileNotFoundException fnfe) { LOG.warn("Mob file " + p + " was missing. Likely removed due to compaction?"); missedMobFiles.add(p); } finally { mobFilesChecked.addAndGet(1); if (r != null) { r.close(true); } } }
@Test public void testReadFromCorruptMobFiles() throws Exception { final TableName tableName = TableName.valueOf(name.getMethodName()); setUp(0, tableName); createRecordAndCorruptMobFile(tableName, row1, family, qf1, Bytes.toBytes("value1")); Get get = new Get(row1); IOException ioe = null; try { table.get(get); } catch (IOException e) { ioe = e; } Assert.assertNotNull(ioe); Assert.assertEquals(CorruptHFileException.class.getName(), ioe.getClass().getName()); }
@Override public boolean preScannerNext(ObserverContext<RegionCoprocessorEnvironment> e, InternalScanner s, List<Result> results, int limit, boolean hasMore) throws IOException { throw new CorruptHFileException("For test"); }