Skip to content

HIVE-28820: HMS might only creates the external directory and not the managed directory - #6717

Open
DanielZhu58 wants to merge 1 commit into
apache:masterfrom
DanielZhu58:HIVE-28820_master
Open

HIVE-28820: HMS might only creates the external directory and not the managed directory#6717
DanielZhu58 wants to merge 1 commit into
apache:masterfrom
DanielZhu58:HIVE-28820_master

Conversation

@DanielZhu58

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR fixes CreateDatabaseHandler.java so that the managed directory for a database is always created, regardless of whether MANAGEDLOCATION is explicitly specified at database creation time.

Previously, dbMgdPath was only set when the user explicitly passed a managed location URI; otherwise it was left null, and the managed directory creation logic (guarded by if (dbMgdPath != null)) was skipped entirely. This PR changes dbMgdPath to fall back to the already-computed defaultDbMgdPath when no managed location is explicitly specified, so the managed directory is always created using either the user-specified or the default path.

As part of this fix, the duplicated directory-creation logic for the managed and external directories (each previously implemented as separate doAs + isDir + mkdirs blocks) has been consolidated into a single private helper method, createDbDirectory, parameterized by the target path, whether to run as the login (admin) user or the current user, and a label used for logging/error messages.

Why are the changes needed?

The correct behavior is for HMS to always create a managed directory path for a database, whether or not a managed location is explicitly specified — mirroring how the external directory is always created via a default fallback path. Without this fix, some databases end up with only an external directory and no managed directory, which can cause downstream failures for any operation that expects the managed directory to exist (e.g. copying files into it).

Does this PR introduce any user-facing change?

Yes. Previously, creating a database without an explicit MANAGEDLOCATION could result in no managed directory being created on the filesystem. After this change, the managed directory is always created at the default managed location if one is not explicitly specified.

How was this patch tested?

Unit tests and q tests.

@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants