hadoophdfsnamenode

In which scenarios we do not allocate blocks to files?


The HDFS Quota Guide says the following for Space Quota. In which scenarios we do not allocate blocks to files?

A quota of zero still permits files to be created, but no blocks can be added to the files.


Solution

  • A file in HDFS is analogous to an INode in more typical file systems. It may or may not contain data, and blocks will only be created if data is added to the file. For example, in the following snippet, no blocks are created because no data is added to the file:

    FileSystem fs = ...
    Path p = ...
    fs.create(p).close();
    

    Whereas in the following, a block is created:

    FileSystem fs = ...
    Path p = ...
    try (FSDataOutputStream out = fs.create(p)) {
        out.write(42);
    }