@Override public boolean accept(Path p) { return HFileLink.isHFileLink(p); } }
/** * @param path Path to check. * @return True if the path is a HFileLink. */ public static boolean isHFileLink(final Path path) { return isHFileLink(path.getName()); }
/** * Validate the store file name. * @param fileName name of the file to validate * @return <tt>true</tt> if the file could be a valid store file, <tt>false</tt> otherwise */ public static boolean validateStoreFileName(final String fileName) { if (HFileLink.isHFileLink(fileName) || isReference(fileName)) return(true); return !fileName.contains("-"); }
/** * Create an HFileLink relative path for the table/region/family/hfile location * @param table Table name * @param region Region Name * @param family Family Name * @param hfile HFile Name * @return the relative Path to open the specified table/region/family/hfile link */ public static Path createPath(final TableName table, final String region, final String family, final String hfile) { if (HFileLink.isHFileLink(hfile)) { return new Path(family, hfile); } return new Path(family, HFileLink.createHFileLinkName(table, region, hfile)); }
/** * Return if the specified file is a valid store file or not. * @param fileStatus The {@link FileStatus} of the file * @return <tt>true</tt> if the file is valid */ public static boolean isValid(final FileStatus fileStatus) throws IOException { final Path p = fileStatus.getPath(); if (fileStatus.isDirectory()) return false; // Check for empty hfile. Should never be the case but can happen // after data loss in hdfs for whatever reason (upgrade, etc.): HBASE-646 // NOTE: that the HFileLink is just a name, so it's an empty file. if (!HFileLink.isHFileLink(p) && fileStatus.getLen() <= 0) { LOG.warn("Skipping " + p + " because it is empty. HBASE-646 DATA LOSS?"); return false; } return validateStoreFileName(p.getName()); }
@Override public void storeFile(final RegionInfo regionInfo, final String family, final SnapshotRegionManifest.StoreFile storeFile) throws IOException { String hfile = storeFile.getName(); if (HFileLink.isHFileLink(hfile)) { names.add(HFileLink.getReferencedHFileName(hfile)); } else { names.add(hfile); } } });
this.initialPath = initialPath; Path p = initialPath; if (HFileLink.isHFileLink(p)) { this.reference = Reference.read(fs, p); Path referencePath = getReferredToFile(p); if (HFileLink.isHFileLink(referencePath)) {
continue; if (HFileLink.isHFileLink(fileName)) { LOG.warn("Skipping HFileLink " + fileName); continue;
if (hfile.getName().startsWith("_") || hfile.getName().startsWith(".") || StoreFileInfo.isReference(hfile.getName()) || HFileLink.isHFileLink(hfile.getName())) { continue;
/** * Gets the number of HFileLink in the mob path. * @param familyName the family name * @return the number of the HFileLink */ private int countHFileLinks(String familyName) throws IOException { Path mobDirPath = MobUtils.getMobFamilyPath(conf, tableName, familyName); int count = 0; if (fs.exists(mobDirPath)) { FileStatus[] files = fs.listStatus(mobDirPath); for (FileStatus file : files) { if (HFileLink.isHFileLink(file.getPath())) { count++; } } } return count; }
String fileName = file.getPath().getName(); try { if (HFileLink.isHFileLink(file.getPath())) { HFileLink hfileLink = HFileLink.buildFromHFileLinkPattern(conf, file.getPath()); fileName = hfileLink.getOriginPath().getName();
Path filePath = fStat.getPath(); if (HFileLink.isHFileLink(filePath)) return true;
/** * Create a new {@link HFileLink} to reference the store file. * <p>The store file in the snapshot can be a simple hfile, an HFileLink or a reference. * <ul> * <li>hfile: abc -> table=region-abc * <li>reference: abc.1234 -> table=region-abc.1234 * <li>hfilelink: table=region-hfile -> table=region-hfile * </ul> * @param familyDir destination directory for the store file * @param regionInfo destination region info for the table * @param createBackRef - Whether back reference should be created. Defaults to true. * @param storeFile store file name (can be a Reference, HFileLink or simple HFile) */ private void restoreStoreFile(final Path familyDir, final RegionInfo regionInfo, final SnapshotRegionManifest.StoreFile storeFile, final boolean createBackRef) throws IOException { String hfileName = storeFile.getName(); if (HFileLink.isHFileLink(hfileName)) { HFileLink.createFromHFileLink(conf, fs, familyDir, hfileName, createBackRef); } else if (StoreFileInfo.isReference(hfileName)) { restoreReferenceFile(familyDir, regionInfo, storeFile); } else { HFileLink.create(conf, fs, familyDir, regionInfo, hfileName, createBackRef); } }
if (refPath != null && HFileLink.isHFileLink(refPath)) { linkPath = new Path(family, refPath.getName()); } else if (HFileLink.isHFileLink(fileName)) { linkPath = new Path(family, fileName); } else {
private void verifyRestore(final Path rootDir, final TableDescriptor sourceHtd, final TableDescriptor htdClone) throws IOException { List<String> files = SnapshotTestingUtils.listHFileNames(fs, FSUtils.getTableDir(rootDir, htdClone.getTableName())); assertEquals(12, files.size()); for (int i = 0; i < files.size(); i += 2) { String linkFile = files.get(i); String refFile = files.get(i+1); assertTrue(linkFile + " should be a HFileLink", HFileLink.isHFileLink(linkFile)); assertTrue(refFile + " should be a Referene", StoreFileInfo.isReference(refFile)); assertEquals(sourceHtd.getTableName(), HFileLink.getReferencedTableName(linkFile)); Path refPath = getReferredToFile(refFile); LOG.debug("get reference name for file " + refFile + " = " + refPath); assertTrue(refPath.getName() + " should be a HFileLink", HFileLink.isHFileLink(refPath.getName())); assertEquals(linkFile, refPath.getName()); } }
private boolean hasHFileLink(Path tableDir) throws IOException { if (fs.exists(tableDir)) { RemoteIterator<LocatedFileStatus> iterator = fs.listFiles(tableDir, true); while (iterator.hasNext()) { LocatedFileStatus fileStatus = iterator.next(); if (fileStatus.isFile() && HFileLink.isHFileLink(fileStatus.getPath())) { return true; } } } return false; }
if (HFileLink.isHFileLink(path) || StoreFileInfo.isHFile(path)) { HFileLink link = HFileLink .build(conf, regionInfoForFs.getTable(), regionInfoForFs.getEncodedName(), familyName, Reference reference = Reference.read(fs, path); Path referencePath = StoreFileInfo.getReferredToFile(path); if (HFileLink.isHFileLink(referencePath)) {
if (StoreFileInfo.isReference(p) || HFileLink.isHFileLink(p)) {
/** * Validate that we can handle valid tables with '.', '_', and '-' chars. */ @Test public void testStoreFileNames() { String[] legalHFileLink = { "MyTable_02=abc012-def345", "MyTable_02.300=abc012-def345", "MyTable_02-400=abc012-def345", "MyTable_02-400.200=abc012-def345", "MyTable_02=abc012-def345_SeqId_1_", "MyTable_02=abc012-def345_SeqId_20_" }; for (String name: legalHFileLink) { assertTrue("should be a valid link: " + name, HFileLink.isHFileLink(name)); assertTrue("should be a valid StoreFile" + name, StoreFileInfo.validateStoreFileName(name)); assertFalse("should not be a valid reference: " + name, StoreFileInfo.isReference(name)); String refName = name + ".6789"; assertTrue("should be a valid link reference: " + refName, StoreFileInfo.isReference(refName)); assertTrue("should be a valid StoreFile" + refName, StoreFileInfo.validateStoreFileName(refName)); } String[] illegalHFileLink = { ".MyTable_02=abc012-def345", "-MyTable_02.300=abc012-def345", "MyTable_02-400=abc0_12-def345", "MyTable_02-400.200=abc012-def345...." }; for (String name: illegalHFileLink) { assertFalse("should not be a valid link: " + name, HFileLink.isHFileLink(name)); } }
Assert.assertTrue("Failed validating:" + name, HFileLink.isHFileLink(name));