dengzhhu653 commented on code in PR #6717:
URL: https://github.com/apache/hive/pull/6717#discussion_r3955724771
##########
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/handler/CreateDatabaseHandler.java:
##########
@@ -269,4 +241,44 @@ public record CreateDatabaseResult(boolean success,
Map<String, String>
transactionalListenersResponses) implements Result {
}
+
+ /**
+ * Creates the given database directory (managed or external) as the given
user,
+ * running the actual mkdir as an admin (login) or current user depending on
runAsLoginUser.
+ *
+ * @param path the directory path to create
+ * @param runAsLoginUser true to run as the login (admin) user (used for
managed dir,
+ * since the calling user may not have access to it),
+ * false to run as the current user (used for
external dir)
+ * @param dirLabel a short label ("managed"/"external") used only for
log/error messages
+ * @param throwOnMkdirFailure true to throw the exception about create
database dir
+ * @return true if the directory was created by this call, false if it
already existed
+ * @throws MetaException if directory creation fails
+ */
+ private boolean createDbDirectory(Path path, boolean runAsLoginUser, String
dirLabel,
+ boolean throwOnMkdirFailure) throws
MetaException {
+ try {
+ UserGroupInformation ugi = runAsLoginUser
+ ? UserGroupInformation.getLoginUser()
+ : UserGroupInformation.getCurrentUser();
+ return ugi.doAs((PrivilegedExceptionAction<Boolean>) () -> {
+ if (!wh.isDir(path)) {
+ LOG.info("Creating database path in {} directory {}", dirLabel,
path);
+ if (!wh.mkdirs(path)) {
+ if (throwOnMkdirFailure) {
Review Comment:
do we need to throw the exception explicitly at here? since we can do the
same when `madeManagedDir` is false at `else if` branch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]