zhuxiangyi commented on code in PR #2964: URL: https://github.com/apache/hadoop/pull/2964#discussion_r1328445332
########## hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/FSDirRenameOp.java: ########## @@ -470,17 +475,53 @@ static RenameResult unprotectedRenameTo(FSDirectory fsd, } } finally { if (undoRemoveSrc) { - tx.restoreSource(); + tx.restoreSource(srcStoragePolicyCounts); } if (undoRemoveDst) { // Rename failed - restore dst - tx.restoreDst(bsps); + tx.restoreDst(bsps, dstStoragePolicyCounts); } } NameNode.stateChangeLog.warn("DIR* FSDirectory.unprotectedRenameTo: " + "failed to rename " + src + " to " + dst); throw new IOException("rename from " + src + " to " + dst + " failed."); } + /* + * Calculate QuotaCounts based on parent directory and storage policy + * 1. If the storage policy of src and dst are different, + * calculate the QuotaCounts of src and dst respectively. + * 2. If all parent nodes of src and dst are not set with Quota, + * there is no need to calculate QuotaCount. + * 3. if parent nodes of src and dst have Quota configured, + * the QuotaCount is calculated once using the storage policy of src. + * */ + private static void computeQuotaCounts( + QuotaCounts srcStoragePolicyCounts, + QuotaCounts dstStoragePolicyCounts, + INodesInPath srcIIP, + INodesInPath dstIIP, + BlockStoragePolicySuite bsps, + RenameOperation tx) { + INode dstParent = dstIIP.getINode(-2); + INode srcParentNode = FSDirectory. + getFirstSetQuotaParentNode(srcIIP); + INode srcInode = srcIIP.getLastINode(); + INode dstParentNode = FSDirectory. + getFirstSetQuotaParentNode(dstIIP); + byte srcStoragePolicyID = FSDirectory.getStoragePolicyId(srcInode); + byte dstStoragePolicyID = FSDirectory.getStoragePolicyId(dstParent); + if (srcStoragePolicyID != dstStoragePolicyID) { + srcStoragePolicyCounts.add(srcIIP.getLastINode(). + computeQuotaUsage(bsps)); + dstStoragePolicyCounts.add(srcIIP.getLastINode() Review Comment: Thanks for finding this problem. If the Inode sets the StoragePolicy we should use the StoragePolicy calculation of the Inode. I will fix it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-issues-h...@hadoop.apache.org