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 @@ -764,7 +764,7 @@ private static void writeRegionInfoFileContent(final Configuration conf, final F
// First check to get the permissions
FsPermission perms = CommonFSUtils.getFilePermissions(fs, conf, HConstants.DATA_FILE_UMASK_KEY);
// Write the RegionInfo file content
try (FSDataOutputStream out = FSUtils.create(conf, fs, regionInfoFile, perms, null)) {
try (FSDataOutputStream out = FSUtils.create(conf, fs, regionInfoFile, perms, null, false)) {
Copy link
Contributor

@apurtell apurtell Oct 27, 2025

Choose a reason for hiding this comment

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

Add a comment here why this change, providing the JIRA identifier. The reason not to recursively create directories is important, we don't want someone refactoring this code later to miss that.

out.write(content);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,44 @@ public static boolean deleteRegionDir(final Configuration conf, final RegionInfo
*/
public static FSDataOutputStream create(Configuration conf, FileSystem fs, Path path,
FsPermission perm, InetSocketAddress[] favoredNodes) throws IOException {
return create(conf, fs, path, perm, favoredNodes, true);
}

/**
* Create the specified file on the filesystem. By default, this will:
* <ol>
* <li>overwrite the file if it exists</li>
* <li>apply the umask in the configuration (if it is enabled)</li>
* <li>use the fs configured buffer size (or 4096 if not set)</li>
* <li>use the configured column family replication or default replication if
* {@link ColumnFamilyDescriptorBuilder#DEFAULT_DFS_REPLICATION}</li>
* <li>use the default block size</li>
* <li>not track progress</li>
* </ol>
* @param conf configurations
* @param fs {@link FileSystem} on which to write the file
* @param path {@link Path} to the file to write
* @param perm permissions
* @param favoredNodes favored data nodes
* @param isRecursiveCreate recursively create parent directories
* @return output stream to the created file
* @throws IOException if the file cannot be created
*/
public static FSDataOutputStream create(Configuration conf, FileSystem fs, Path path,
FsPermission perm, InetSocketAddress[] favoredNodes, boolean isRecursiveCreate)
throws IOException {
if (fs instanceof HFileSystem) {
FileSystem backingFs = ((HFileSystem) fs).getBackingFs();
if (backingFs instanceof DistributedFileSystem) {
short replication = Short.parseShort(conf.get(ColumnFamilyDescriptorBuilder.DFS_REPLICATION,
String.valueOf(ColumnFamilyDescriptorBuilder.DEFAULT_DFS_REPLICATION)));
DistributedFileSystem.HdfsDataOutputStreamBuilder builder =
((DistributedFileSystem) backingFs).createFile(path).recursive().permission(perm)
.create();
DistributedFileSystem.HdfsDataOutputStreamBuilder builder = null;
if (isRecursiveCreate) {
builder = ((DistributedFileSystem) backingFs).createFile(path).recursive()
.permission(perm).create();
} else {
builder = ((DistributedFileSystem) backingFs).createFile(path).permission(perm).create();
}
if (favoredNodes != null) {
builder.favoredNodes(favoredNodes);
}
Expand Down