|
@@ -165,6 +165,7 @@ import org.apache.hadoop.hdfs.security.token.block.BlockTokenSecretManager;
|
|
|
import org.apache.hadoop.hdfs.security.token.block.BlockTokenSecretManager.AccessMode;
|
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenIdentifier;
|
|
|
import org.apache.hadoop.hdfs.security.token.delegation.DelegationTokenSecretManager;
|
|
|
+import org.apache.hadoop.hdfs.server.blockmanagement.BlockCollection;
|
|
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfo;
|
|
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoUnderConstruction;
|
|
|
import org.apache.hadoop.hdfs.server.blockmanagement.BlockManager;
|
|
@@ -3717,6 +3718,39 @@ public class FSNamesystem implements Namesystem, FSClusterStats,
|
|
|
BlockInfo getStoredBlock(Block block) {
|
|
|
return blockManager.getStoredBlock(block);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean isInSnapshot(BlockInfoUnderConstruction blockUC) {
|
|
|
+ assert hasReadOrWriteLock();
|
|
|
+ final BlockCollection bc = blockUC.getBlockCollection();
|
|
|
+ if (bc == null || !(bc instanceof INodeFileUnderConstruction)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ INodeFileUnderConstruction inodeUC = (INodeFileUnderConstruction) blockUC
|
|
|
+ .getBlockCollection();
|
|
|
+ String fullName = inodeUC.getName();
|
|
|
+ try {
|
|
|
+ if (fullName != null && fullName.startsWith(Path.SEPARATOR)
|
|
|
+ && dir.getINode(fullName) == inodeUC) {
|
|
|
+ // If file exists in normal path then no need to look in snapshot
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ } catch (UnresolvedLinkException e) {
|
|
|
+ LOG.error("Error while resolving the link : " + fullName, e);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ * 1. if bc is an instance of INodeFileUnderConstructionWithSnapshot, and
|
|
|
+ * bc is not in the current fsdirectory tree, bc must represent a snapshot
|
|
|
+ * file.
|
|
|
+ * 2. if fullName is not an absolute path, bc cannot be existent in the
|
|
|
+ * current fsdirectory tree.
|
|
|
+ * 3. if bc is not the current node associated with fullName, bc must be a
|
|
|
+ * snapshot inode.
|
|
|
+ */
|
|
|
+ return true;
|
|
|
+ }
|
|
|
|
|
|
void commitBlockSynchronization(ExtendedBlock lastblock,
|
|
|
long newgenerationstamp, long newlength,
|