@@ -1398,8 +1398,9 @@ public INodesInPath addLastINode(INodesInPath existing, INode inode, FsPermissio
13981398 // always verify inode name
13991399 verifyINodeName (inode .getLocalNameBytes ());
14001400
1401+ QuotaCounts counts = null ;
14011402 if (updateQuota ) {
1402- QuotaCounts counts = quotaCount .orElseGet (() -> inode .
1403+ counts = quotaCount .orElseGet (() -> inode .
14031404 computeQuotaUsage (getBlockStoragePolicySuite (),
14041405 parent .getStoragePolicyID (), false ,
14051406 Snapshot .CURRENT_STATE_ID ));
@@ -1409,12 +1410,11 @@ public INodesInPath addLastINode(INodesInPath existing, INode inode, FsPermissio
14091410 boolean isRename = (inode .getParent () != null );
14101411 final boolean added = parent .addChild (inode , true ,
14111412 existing .getLatestSnapshotId ());
1412- if (!added && updateQuota ) {
1413- QuotaCounts counts = quotaCount .orElseGet (() -> inode .
1414- computeQuotaUsage (getBlockStoragePolicySuite (),
1415- parent .getStoragePolicyID (), false ,
1416- Snapshot .CURRENT_STATE_ID ));
1417- updateCountNoQuotaCheck (existing , pos , counts .negation ());
1413+ if (!added ) {
1414+ // When adding INode fails, if 'updateQuota' is true, rollback quotaUsage.
1415+ if (updateQuota ) {
1416+ updateCountNoQuotaCheck (existing , pos , counts .negation ());
1417+ }
14181418 return null ;
14191419 } else {
14201420 if (!isRename ) {
0 commit comments