详情请参见DatanodeUtil.java中的函数idToBlockDir(File root, long blockId)。
如果block文件没有放在正确的目录下,则DataNode会出现“expected block file path”日志。

// g++ -g -o block2dir block2dir.cpp
#include
#include

int main(int argc, char* argv[])
{
    if (argc != 2)
    {
        fprintf(stderr, "usage: block2dir block_id, example: block2dir 1075840138\n");
        exit(1);
    }

    const long block_id = atol(argv[1]);
    const int d1 = (int) ((block_id >> 16) & 0x1F);
    const int d2 = (int) ((block_id >> 8) & 0x1F);
    fprintf(stderr, "subdir%d/subdir%d\n", d1, d2);

    return 0;
}

运行示例:
$ ./block2dir 1075840138
subdir0/subdir4

/**
* @return the meta name given the block name and generation stamp.
*/
public static String getMetaName(String blockName, long generationStamp) {
    return blockName + "_" + generationStamp + Block.METADATA_EXTENSION; 
}
12-18 07:16