此参数主要是配置hdfs的超级部门,默认值是supergroup。

这个参数主要在FSNamesystem类中用于创建root目录。

PermissionStatus createFsOwnerPermissions(FsPermission permission) {
return new PermissionStatus(fsOwner.getShortUserName(), supergroup, permission);
}
private static INodeDirectory createRoot(FSNamesystem namesystem) {
final INodeDirectory r = new INodeDirectory(
INodeId.ROOT_INODE_ID,
INodeDirectory.ROOT_NAME,
namesystem.createFsOwnerPermissions(new FsPermission((short) 0755)),
0L);
...
return r;
}

这里面还有一个有趣的问题,就是用户创建文件的时候group是和linux系统是有用户组吗?实际情况不是的,结论是子文件的group继承于父目录的group。

NameNodeRpcServer.java
public HdfsFileStatus create(String src, FsPermission masked,
String clientName, EnumSetWritable flag,
boolean createParent, short replication, long blockSize,
CryptoProtocolVersion[] supportedVersions, String ecPolicyName)
throws IOException {
...
HdfsFileStatus status = null;
    try {
      PermissionStatus perm = new PermissionStatus(getRemoteUser()
          .getShortUserName(), null, masked);
      status = namesystem.startFile(src, perm, clientName, clientMachine,
          flag.get(), createParent, replication, blockSize, supportedVersions,
          ecPolicyName, cacheEntry != null);
    } finally {
      RetryCache.setState(cacheEntry, status != null, status);
    }
...
}

可以看到创建文件是group默认都是NULL。

FSDirWriteFileOp.java 
private static INodesInPath addFile(
      FSDirectory fsd, INodesInPath existing, byte[] localName,
      PermissionStatus permissions, short replication, long preferredBlockSize,
      String clientName, String clientMachine, boolean shouldReplicate,
      String ecPolicyName) throws IOException {
...
newiip = fsd.addINode(existing, newNode, permissions.getPermission());
...
}

添加文件都是通过parent.addInode这个方法。

INodeDirectory.java
private void addChild(final INode node, final int insertionPoint) {
if (children == null) {
children = new ArrayList<>(DEFAULT_FILES_PER_DIRECTORY);
}
node.setParent(this);
children.add(-insertionPoint - 1, node);
if (node.getGroupName() == null) {
  node.setGroup(getGroupName());
}
}

可以看到如果childnode的groupName=NULL,就那parentgroupname。