Code review comment: There is no need to check permissions when creating a user. You can check permissions when connecting, and the behavior is similar to mysql --database. Because even if you can check permissions when altering user, what if the permissions are revoked later? How do you deal with it?

Code before review:
public void createUser(CreateUserStmt stmt) throws DdlException {
UserIdentity userIdentity = stmt.getUserIdentity();
UserAuthenticationInfo info = stmt.getAuthenticationInfo();
writeLock();
try {
if (userToAuthenticationInfo.containsKey(userIdentity)) {
LOG.info("Operation CREATE USER failed for " + stmt.getUserIdentity()
+ " : user " + stmt.getUserIdentity() + " already exists");
return;
}
UserProperty userProperty = null;
String userName = userIdentity.getUser();
if (userNameToProperty.containsKey(userName)) {
userProperty = userNameToProperty.get(userName);
} else {
userProperty = new UserProperty();
}
if (stmt.getProperties() != null) {
Map<String, String> properties = stmt.getProperties();
if (properties.containsKey(UserProperty.PROP_CATALOG) ||
properties.containsKey(UserProperty.PROP_DATABASE)) {
throw new PrivilegeException(String.format("User property %s and %s are not allowed to set in CREATE USER",
UserProperty.PROP_CATALOG, UserProperty.PROP_DATABASE));
}
userProperty.update(userIdentity, UserProperty.changeToPairList(stmt.getProperties()));
}
userToAuthenticationInfo.put(userIdentity, info);
userNameToProperty.put(userName, userProperty);
GlobalStateMgr globalStateMgr = GlobalStateMgr.getCurrentState();
AuthorizationMgr authorizationManager = globalStateMgr.getAuthorizationMgr();
UserPrivilegeCollectionV2 collection =
authorizationManager.onCreateUser(userIdentity, stmt.getDefaultRoles());
short pluginId = authorizationManager.getProviderPluginId();
short pluginVersion = authorizationManager.getProviderPluginVersion();
globalStateMgr.getEditLog().logCreateUser(
userIdentity, info, userProperty, collection, pluginId, pluginVersion);
} catch (PrivilegeException e) {
throw new DdlException("failed to create user " + userIdentity + " : " + e.getMessage(), e);
} finally {
writeUnlock();
}
}

Line under review: throw new PrivilegeException(String.format("User property %s and %s are not allowed to set in CREATE USER",

Code after addressing the review:
public void createUser(CreateUserStmt stmt) throws DdlException {
UserIdentity userIdentity = stmt.getUserIdentity();
UserAuthenticationInfo info = stmt.getAuthenticationInfo();
writeLock();
try {
if (userToAuthenticationInfo.containsKey(userIdentity)) {
LOG.info("Operation CREATE USER failed for " + stmt.getUserIdentity()
+ " : user " + stmt.getUserIdentity() + " already exists");
return;
}
UserProperty userProperty = null;
String userName = userIdentity.getUser();
if (userNameToProperty.containsKey(userName)) {
userProperty = userNameToProperty.get(userName);
} else {
userProperty = new UserProperty();
}
if (stmt.getProperties() != null) {
userProperty.update(userIdentity, UserProperty.changeToPairList(stmt.getProperties()));
}
userToAuthenticationInfo.put(userIdentity, info);
userNameToProperty.put(userName, userProperty);
GlobalStateMgr globalStateMgr = GlobalStateMgr.getCurrentState();
AuthorizationMgr authorizationManager = globalStateMgr.getAuthorizationMgr();
UserPrivilegeCollectionV2 collection =
authorizationManager.onCreateUser(userIdentity, stmt.getDefaultRoles());
short pluginId = authorizationManager.getProviderPluginId();
short pluginVersion = authorizationManager.getProviderPluginVersion();
globalStateMgr.getEditLog().logCreateUser(
userIdentity, info, userProperty, collection, pluginId, pluginVersion);
} catch (PrivilegeException e) {
throw new DdlException("failed to create user " + userIdentity + " : " + e.getMessage(), e);
} finally {
writeUnlock();
}
}