Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,14 @@ public class DFSConfigKeys extends CommonConfigurationKeys {
public static final int DFS_NAMENODE_BLOCK_DELETION_UNLOCK_INTERVAL_MS_DEFAULT =
10;

/** Block deletion increment. */
public static final String DFS_NAMENODE_BLOCK_DELETION_INCREMENT_KEY =
"dfs.namenode.block.deletion.increment";
public static final int DFS_NAMENODE_BLOCK_DELETION_INCREMENT_DEFAULT = 1000;
/** Block deletion asynchronous. */
public static final String DFS_NAMENODE_BLOCK_DELETION_ASYNC_KEY = "dfs.namenode.block.deletion.async";
public static final boolean DFS_NAMENODE_BLOCK_DELETION_ASYNC_DEFAULT = true;

public static final String DFS_NAMENODE_SNAPSHOT_CAPTURE_OPENFILES =
HdfsClientConfigKeys.DFS_NAMENODE_SNAPSHOT_CAPTURE_OPENFILES;
public static final boolean DFS_NAMENODE_SNAPSHOT_CAPTURE_OPENFILES_DEFAULT =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ private boolean isClientPortInfoAbsent(CallerContext ctx){
private final String supergroup;
private final boolean standbyShouldCheckpoint;
private final boolean isSnapshotTrashRootEnabled;
private final boolean blockDeletionAsync;
private final int blockDeletionIncrement;
private final int snapshotDiffReportLimit;

/**
Expand Down Expand Up @@ -1064,6 +1066,12 @@ static FSNamesystem loadFromDisk(Configuration conf) throws IOException {
this.allowOwnerSetQuota = conf.getBoolean(
DFSConfigKeys.DFS_PERMISSIONS_ALLOW_OWNER_SET_QUOTA_KEY,
DFSConfigKeys.DFS_PERMISSIONS_ALLOW_OWNER_SET_QUOTA_DEFAULT);
this.blockDeletionAsync = conf.getBoolean(
DFSConfigKeys.DFS_NAMENODE_BLOCK_DELETION_ASYNC_KEY,
DFSConfigKeys.DFS_NAMENODE_BLOCK_DELETION_ASYNC_DEFAULT);
this.blockDeletionIncrement = conf.getInt(
DFSConfigKeys.DFS_NAMENODE_BLOCK_DELETION_INCREMENT_KEY,
DFSConfigKeys.DFS_NAMENODE_BLOCK_DELETION_INCREMENT_DEFAULT);
this.isGetBlocksCheckOperationEnabled = conf.getBoolean(
DFSConfigKeys.DFS_NAMENODE_GETBLOCKS_CHECK_OPERATION_KEY,
DFSConfigKeys.DFS_NAMENODE_GETBLOCKS_CHECK_OPERATION_DEFAULT);
Expand Down Expand Up @@ -2380,8 +2388,7 @@ boolean truncate(String src, long newLength, String clientName,
}
getEditLog().logSync();
if (!toRemoveBlocks.getToDeleteList().isEmpty()) {
blockManager.addBLocksToMarkedDeleteQueue(
toRemoveBlocks.getToDeleteList());
removeBlocks(toRemoveBlocks.getToDeleteList());
}
logAuditEvent(true, operationName, src, null, status);
} catch (AccessControlException e) {
Expand Down Expand Up @@ -2828,8 +2835,7 @@ private HdfsFileStatus startFileInt(String src,
if (!skipSync) {
getEditLog().logSync();
if (toRemoveBlocks != null) {
blockManager.addBLocksToMarkedDeleteQueue(
toRemoveBlocks.getToDeleteList());
removeBlocks(toRemoveBlocks.getToDeleteList());
}
}
}
Expand Down Expand Up @@ -3352,8 +3358,7 @@ void renameTo(final String src, final String dst,
assert res != null;
BlocksMapUpdateInfo collectedBlocks = res.collectedBlocks;
if (!collectedBlocks.getToDeleteList().isEmpty()) {
blockManager.addBLocksToMarkedDeleteQueue(
collectedBlocks.getToDeleteList());
removeBlocks(collectedBlocks.getToDeleteList());
}

logAuditEvent(true, operationName + " (options=" +
Expand Down Expand Up @@ -3392,8 +3397,7 @@ boolean delete(String src, boolean recursive, boolean logRetryCache)
getEditLog().logSync();
logAuditEvent(ret, operationName, src);
if (toRemovedBlocks != null) {
blockManager.addBLocksToMarkedDeleteQueue(
toRemovedBlocks.getToDeleteList());
removeBlocks(toRemovedBlocks.getToDeleteList());
}
return ret;
}
Expand All @@ -3403,6 +3407,33 @@ FSPermissionChecker getPermissionChecker()
return dir.getPermissionChecker();
}

/**
* If blockDeletionAsync enables, blocks will be deleted asynchronously.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use dfs.namenode.block.deletion.async not blockDeletionAsync

* If not, incrementally remove the blocks from blockManager
* Writelock is dropped and reacquired every BLOCK_DELETION_INCREMENT to
* ensure that other waiters on the lock can get in. See HDFS-2938
*
* @param toDeleteList
* a list of blocks that need to be removed from blocksMap
*/
void removeBlocks(List<BlockInfo> toDeleteList) {
if (this.blockDeletionAsync) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable blockDeletionAsync doesn't seem to be declared.

blockManager.addBLocksToMarkedDeleteQueue(toDeleteList);
} else {
Iterator<BlockInfo> iter = toDeleteList.iterator();
while (iter.hasNext()) {
writeLock();
try {
for (int i = 0; i < blockDeletionIncrement && iter.hasNext(); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed blockDeletionIncrement in HDFS-16554

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About "blockDeletionIncrement", in my opinion, why we removed it in HDFS-16554 is that we decided to use delete async to replace the previous method, so the "blockDeletionIncrement" won't be used any more. But when we add a switch to control blocks deletion async, we need to save the previous block deletion method, so we still need it.

blockManager.removeBlock(iter.next());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compared with the previous one, the following code is missing:

toRemoveBlocks.clear(); 

https://github.com/apache/hadoop/pull/3063/files#diff-dac9de4dd225110eff2f29a44000bf32705f02df2b3fcf17b5d89bc236c12f01

}
} finally {
writeUnlock("removeBlocks");
}
}
}
}

/**
* Remove leases and inodes related to a given path
* @param removedUCFiles INodes whose leases need to be released
Expand Down Expand Up @@ -4609,8 +4640,7 @@ private void clearCorruptLazyPersistFiles()
INodesInPath.fromINode((INodeFile) bc), false);
changed |= toRemoveBlocks != null;
if (toRemoveBlocks != null) {
blockManager.addBLocksToMarkedDeleteQueue(
toRemoveBlocks.getToDeleteList());
removeBlocks(toRemoveBlocks.getToDeleteList());
}
}
} finally {
Expand Down Expand Up @@ -7348,8 +7378,7 @@ void deleteSnapshot(String snapshotRoot, String snapshotName,
// Breaking the pattern as removing blocks have to happen outside of the
// global lock
if (blocksToBeDeleted != null) {
blockManager.addBLocksToMarkedDeleteQueue(
blocksToBeDeleted.getToDeleteList());
removeBlocks(blocksToBeDeleted.getToDeleteList());
}
logAuditEvent(true, operationName, rootPath, null, null);
}
Expand All @@ -7375,8 +7404,7 @@ public void gcDeletedSnapshot(String snapshotRoot, String snapshotName)
} finally {
writeUnlock(operationName, getLockReportInfoSupplier(rootPath));
}
blockManager.addBLocksToMarkedDeleteQueue(
blocksToBeDeleted.getToDeleteList());
removeBlocks(blocksToBeDeleted.getToDeleteList());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6163,6 +6163,14 @@
</description>
</property>

<property>
<name>dfs.namenode.block.deletion.async</name>
<value>true</value>
<description>
If false, disable block deleting asynchronously
</description>
</property>

<property>
<name>dfs.namenode.rpc-address.auxiliary-ports</name>
<value></value>
Expand Down