diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HFileLink.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HFileLink.java index ff33951..2aed159 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HFileLink.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/HFileLink.java @@ -338,26 +338,27 @@ public class HFileLink extends FileLink { String name = createHFileLinkName(linkedTable, linkedRegion, hfileName); String refName = createBackReferenceName(tableName, regionName); + Path linkPath = new Path(dstFamilyPath, name); + Path backRefPath = null; // Make sure the destination directory exists fs.mkdirs(dstFamilyPath); + fs.createNewFile(linkPath); - // Make sure the FileLink reference directory exists - Path archiveStoreDir = HFileArchiveUtil.getStoreArchivePath(conf, + try { + // Make sure the FileLink reference directory exists + Path archiveStoreDir = HFileArchiveUtil.getStoreArchivePath(conf, linkedTable, linkedRegion, familyName); - Path backRefssDir = getBackReferencesDir(archiveStoreDir, hfileName); - fs.mkdirs(backRefssDir); + backRefPath = getBackReferencesDir(archiveStoreDir, hfileName); + fs.mkdirs(backRefPath); - // Create the reference for the link - Path backRefPath = new Path(backRefssDir, refName); - fs.createNewFile(backRefPath); - try { - // Create the link - return fs.createNewFile(new Path(dstFamilyPath, name)); + // Create the reference for the link + backRefPath = new Path(backRefPath, refName); + return fs.createNewFile(backRefPath); } catch (IOException e) { - LOG.error("couldn't create the link=" + name + " for " + dstFamilyPath, e); - // Revert the reference if the link creation failed - fs.delete(backRefPath, false); + LOG.error("couldn't create the reference=" + backRefPath + " for " + linkPath, e); + // Revert the link if the reference creation failed + fs.delete(linkPath, false); throw e; } } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/cleaner/HFileLinkCleaner.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/cleaner/HFileLinkCleaner.java index e8fba43..5a50a50 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/cleaner/HFileLinkCleaner.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/cleaner/HFileLinkCleaner.java @@ -18,15 +18,15 @@ package org.apache.hadoop.hbase.master.cleaner; import java.io.IOException; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.HBaseInterfaceAudience; +import org.apache.hadoop.hbase.HConstants; +import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.io.HFileLink; import org.apache.hadoop.hbase.util.FSUtils; @@ -57,7 +57,14 @@ public class HFileLinkCleaner extends BaseHFileCleanerDelegate { if (HFileLink.isBackReferencesDir(parentDir)) { Path hfilePath = null; try { - hfilePath = HFileLink.getHFileFromBackReference(getConf(), filePath); + // Also check if the HFile is in the HBASE_TEMP_DIRECTORY; this is where the referenced + // file gets created when cloning a snapshot. + hfilePath = HFileLink.getHFileFromBackReference(FSUtils.getRootDir(getConf()), filePath); + if (fs.exists(hfilePath)) { + return false; + } + hfilePath = HFileLink.getHFileFromBackReference( + new Path(FSUtils.getRootDir(getConf()), HConstants.HBASE_TEMP_DIRECTORY), filePath); return !fs.exists(hfilePath); } catch (IOException e) { if (LOG.isDebugEnabled()) { diff --git a/hbase-server/src/test/resources/log4j.properties b/hbase-server/src/test/resources/log4j.properties index 13a95b4..e80c6c4 100644 --- a/hbase-server/src/test/resources/log4j.properties +++ b/hbase-server/src/test/resources/log4j.properties @@ -64,3 +64,5 @@ log4j.org.apache.hadoop.metrics2.impl.MetricsSystemImpl=ERROR log4j.org.apache.hadoop.metrics2.util.MBeans=ERROR # Enable this to get detailed connection error/retry logging. # log4j.logger.org.apache.hadoop.hbase.client.ConnectionImplementation=TRACE + +log4j.logger.org.apache.hadoop.hbase.master.cleaner.CleanerChore=DEBUG