Skip to content

Commit

Permalink
refactor DatanodeUtil#idToBlockDir
Browse files Browse the repository at this point in the history
  • Loading branch information
hfutatzhanghb committed Jan 16, 2025
1 parent 6823483 commit b82105b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class DataNodeLayoutSubLockStrategy implements DataSetSubLockStrategy {
@Override
public String blockIdToSubLock(long blockid) {
return DatanodeUtil.idToBlockDirSuffixName(blockid);
return DatanodeUtil.idToBlockDirSuffix(blockid);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class DatanodeUtil {
public static final String DISK_ERROR = "Possible disk error: ";

private static final String SEP = System.getProperty("file.separator");

Check failure on line 42 in hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DatanodeUtil.java

View check run for this annotation

ASF Cloudbees Jenkins ci-hadoop / Apache Yetus

hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DatanodeUtil.java#L42

blanks: end of line
private static final long MASK = 0x1F;

/** Get the cause of an I/O exception if caused by a possible disk error
* @param ioe an I/O exception
Expand Down Expand Up @@ -114,23 +116,6 @@ public static boolean dirNoFilesRecursive(
return true;
}

/**
* Get the directory where a finalized block with this ID should be stored.
* Do not attempt to create the directory.
* Note: update {@link DatanodeUtil#idToBlockDirSuffixName(long)} and
* {@link DatanodeUtil#getAllSubDirNameForDataSetLock()} when current method changed.
* @param root the root directory where finalized blocks are stored
* @param blockId
* @return
*/
public static File idToBlockDir(File root, long blockId) {
int d1 = (int) ((blockId >> 16) & 0x1F);
int d2 = (int) ((blockId >> 8) & 0x1F);
String path = DataStorage.BLOCK_SUBDIR_PREFIX + d1 + SEP +
DataStorage.BLOCK_SUBDIR_PREFIX + d2;
return new File(root, path);
}

/**
* Take an example.
* We hava a block with blockid mapping to:
Expand All @@ -139,17 +124,29 @@ public static File idToBlockDir(File root, long blockId) {
* @param blockId the block id.
* @return two-level subdir string where block will be stored.
*/
public static String idToBlockDirSuffixName(long blockId) {
int d1 = (int) ((blockId >> 16) & 0x1F);
int d2 = (int) ((blockId >> 8) & 0x1F);
public static String idToBlockDirSuffix(long blockId) {
int d1 = (int) ((blockId >> 16) & MASK);
int d2 = (int) ((blockId >> 8) & MASK);
return DataStorage.BLOCK_SUBDIR_PREFIX + d1 + SEP +
DataStorage.BLOCK_SUBDIR_PREFIX + d2;
}

/**
* Get the directory where a finalized block with this ID should be stored.
* Do not attempt to create the directory.
* @param root the root directory where finalized blocks are stored
* @param blockId
* @return
*/
public static File idToBlockDir(File root, long blockId) {
String path = idToBlockDirSuffix(blockId);
return new File(root, path);
}

public static List<String> getAllSubDirNameForDataSetLock() {
List<String> res = new ArrayList<>();
for (int d1 = 0; d1 <= 0x1F; d1++) {
for (int d2 = 0; d2 <= 0x1F; d2++) {
for (int d1 = 0; d1 <= MASK; d1++) {
for (int d2 = 0; d2 <= MASK; d2++) {
res.add(DataStorage.BLOCK_SUBDIR_PREFIX + d1 + SEP +
DataStorage.BLOCK_SUBDIR_PREFIX + d2);
}
Expand Down

0 comments on commit b82105b

Please sign in to comment.