@Test public void testHFileLink() throws Exception { // pass a link, and verify that correct paths are returned. Path rootDir = FSUtils.getRootDir(TEST_UTIL.getConfiguration()); Path aFileLink = new Path(rootDir, "table/2086db948c48/cf/table=21212abcdc33-0906db948c48"); Path preNamespaceTablePath = new Path(rootDir, "table/21212abcdc33/cf/0906db948c48"); Path preNamespaceArchivePath = new Path(rootDir, ".archive/table/21212abcdc33/cf/0906db948c48"); Path preNamespaceTempPath = new Path(rootDir, ".tmp/table/21212abcdc33/cf/0906db948c48"); boolean preNSTablePathExists = false; boolean preNSArchivePathExists = false; boolean preNSTempPathExists = false; assertTrue(HFileLink.isHFileLink(aFileLink)); HFileLink hFileLink = HFileLink.buildFromHFileLinkPattern(TEST_UTIL.getConfiguration(), aFileLink); assertTrue(hFileLink.getArchivePath().toString().startsWith(rootDir.toString())); HFileV1Detector t = new HFileV1Detector(); t.setConf(TEST_UTIL.getConfiguration()); FileLink fileLink = t.getFileLinkWithPreNSPath(aFileLink); //assert it has 6 paths (2 NS, 2 Pre NS, and 2 .tmp) to look. assertTrue(fileLink.getLocations().length == 6); for (Path p : fileLink.getLocations()) { if (p.equals(preNamespaceArchivePath)) preNSArchivePathExists = true; if (p.equals(preNamespaceTablePath)) preNSTablePathExists = true; if (p.equals(preNamespaceTempPath)) preNSTempPathExists = true; } assertTrue(preNSArchivePathExists & preNSTablePathExists & preNSTempPathExists); }
/** * Creates a corrupt file, and run HFileV1 detector tool * @throws Exception */ @Test public void testHFileV1DetectorWithCorruptFiles() throws Exception { // add a corrupt file. Path tablePath = new Path(hbaseRootDir, "foo"); FileStatus[] regionsDir = fs.listStatus(tablePath); if (regionsDir == null) throw new IOException("No Regions found for table " + "foo"); Path columnFamilyDir = null; Path targetRegion = null; for (FileStatus s : regionsDir) { if (fs.exists(new Path(s.getPath(), HRegionFileSystem.REGION_INFO_FILE))) { targetRegion = s.getPath(); break; } } FileStatus[] cfs = fs.listStatus(targetRegion); for (FileStatus f : cfs) { if (f.isDirectory()) { columnFamilyDir = f.getPath(); break; } } LOG.debug("target columnFamilyDir: " + columnFamilyDir); // now insert a corrupt file in the columnfamily. Path corruptFile = new Path(columnFamilyDir, "corrupt_file"); if (!fs.createNewFile(corruptFile)) throw new IOException("Couldn't create corrupt file: " + corruptFile); assertEquals(1, ToolRunner.run(TEST_UTIL.getConfiguration(), new HFileV1Detector(), null)); // remove the corrupt file FileSystem.get(TEST_UTIL.getConfiguration()).delete(corruptFile, false); }
@Test public void testADirForHFileV1() throws Exception { Path tablePath = new Path(hbaseRootDir, "foo"); System.out.println("testADirForHFileV1: " + tablePath.makeQualified(fs)); System.out.println("Passed: " + hbaseRootDir + "/foo"); assertEquals(0, ToolRunner.run(TEST_UTIL.getConfiguration(), new HFileV1Detector(), new String[] { "-p" + "foo" })); }
@Test public void testHFileLink() throws Exception { // pass a link, and verify that correct paths are returned. Path rootDir = FSUtils.getRootDir(TEST_UTIL.getConfiguration()); Path aFileLink = new Path(rootDir, "table/2086db948c48/cf/table=21212abcdc33-0906db948c48"); Path preNamespaceTablePath = new Path(rootDir, "table/21212abcdc33/cf/0906db948c48"); Path preNamespaceArchivePath = new Path(rootDir, ".archive/table/21212abcdc33/cf/0906db948c48"); Path preNamespaceTempPath = new Path(rootDir, ".tmp/table/21212abcdc33/cf/0906db948c48"); boolean preNSTablePathExists = false; boolean preNSArchivePathExists = false; boolean preNSTempPathExists = false; assertTrue(HFileLink.isHFileLink(aFileLink)); HFileLink hFileLink = new HFileLink(TEST_UTIL.getConfiguration(), aFileLink); assertTrue(hFileLink.getArchivePath().toString().startsWith(rootDir.toString())); HFileV1Detector t = new HFileV1Detector(); t.setConf(TEST_UTIL.getConfiguration()); FileLink fileLink = t.getFileLinkWithPreNSPath(aFileLink); //assert it has 6 paths (2 NS, 2 Pre NS, and 2 .tmp) to look. assertTrue(fileLink.getLocations().length == 6); for (Path p : fileLink.getLocations()) { if (p.equals(preNamespaceArchivePath)) preNSArchivePathExists = true; if (p.equals(preNamespaceTablePath)) preNSTablePathExists = true; if (p.equals(preNamespaceTempPath)) preNSTempPathExists = true; } assertTrue(preNSArchivePathExists & preNSTablePathExists & preNSTempPathExists); }
/** * Creates a corrupt file, and run HFileV1 detector tool * @throws Exception */ @Test public void testHFileV1DetectorWithCorruptFiles() throws Exception { // add a corrupt file. Path tablePath = new Path(hbaseRootDir, "foo"); FileStatus[] regionsDir = fs.listStatus(tablePath); if (regionsDir == null) throw new IOException("No Regions found for table " + "foo"); Path columnFamilyDir = null; Path targetRegion = null; for (FileStatus s : regionsDir) { if (fs.exists(new Path(s.getPath(), HRegionFileSystem.REGION_INFO_FILE))) { targetRegion = s.getPath(); break; } } FileStatus[] cfs = fs.listStatus(targetRegion); for (FileStatus f : cfs) { if (f.isDir()) { columnFamilyDir = f.getPath(); break; } } LOG.debug("target columnFamilyDir: " + columnFamilyDir); // now insert a corrupt file in the columnfamily. Path corruptFile = new Path(columnFamilyDir, "corrupt_file"); if (!fs.createNewFile(corruptFile)) throw new IOException("Couldn't create corrupt file: " + corruptFile); assertEquals(1, ToolRunner.run(TEST_UTIL.getConfiguration(), new HFileV1Detector(), null)); // remove the corrupt file FileSystem.get(TEST_UTIL.getConfiguration()).delete(corruptFile, false); }
private int doHFileV1Check() throws Exception { String[] args = null; if (dirToCheckForHFileV1 != null) args = new String[] { "-p" + dirToCheckForHFileV1 }; return ToolRunner.run(getConf(), new HFileV1Detector(), args); }
/** * Tests a 0.94 filesystem for any HFileV1. * @throws Exception */ @Test public void testHFileV1Detector() throws Exception { assertEquals(0, ToolRunner.run(TEST_UTIL.getConfiguration(), new HFileV1Detector(), null)); }