-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Support setting session vars in user property #48477
[Feature] Support setting session vars in user property #48477
Conversation
@yandongxiao |
Done |
b1db23f
to
792180f
Compare
fe/fe-core/src/main/java/com/starrocks/authentication/UserProperty.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/com/starrocks/authentication/UserProperty.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/com/starrocks/authentication/UserProperty.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/com/starrocks/authentication/UserProperty.java
Outdated
Show resolved
Hide resolved
fe/fe-core/src/main/java/com/starrocks/authentication/UserProperty.java
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
private UserIdentity getUserIdentityByName(String userName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put it into AuthenticationMgr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
fe/fe-core/src/main/java/com/starrocks/authentication/UserProperty.java
Outdated
Show resolved
Hide resolved
Fixed all based on review comments |
@@ -122,7 +122,8 @@ public void testShowUserProperty() { | |||
|
|||
@Test | |||
public void testSetUserProperty() { | |||
String sql = "SET PROPERTY FOR 'tom' 'max_user_connections' = 'value', 'test' = 'true'"; | |||
String sql = "SET PROPERTY FOR 'tom' 'max_user_connections' = '100 " + | |||
"git '"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
public void updateByUserProperty(UserProperty userProperty) { | ||
try { | ||
// set catalog and database | ||
boolean dBHasBeenSetByUser = !getCurrentCatalog().equals(InternalCatalog.DEFAULT_INTERNAL_CATALOG_NAME) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boolean dBHasBeenSetByUser = !getCurrentCatalog().equals(InternalCatalog.DEFAULT_INTERNAL_CATALOG_NAME) || | |
boolean dbHasBeenSetByUser = !getCurrentCatalog().equals(InternalCatalog.DEFAULT_INTERNAL_CATALOG_NAME) || |
try { | ||
// set catalog and database | ||
boolean dBHasBeenSetByUser = !getCurrentCatalog().equals(InternalCatalog.DEFAULT_INTERNAL_CATALOG_NAME) || | ||
!getDatabase().isEmpty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now there is a scenario where the default catalog of the global session variable is not default_catalog. Then does this user's property catalog become ineffective?
properties.containsKey(UserProperty.PROP_DATABASE)) { | ||
// Authorizer.checkAnyActionOnOrInDb and Authorizer.checkAnyActionOnCatalog methods are not allowed to be called, | ||
// because they assume the user has been created. | ||
throw new PrivilegeException(String.format("User property %s and %s are not allowed to set in CREATE USER", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
|
||
try { | ||
if (!CatalogMgr.isInternalCatalog(value)) { | ||
Authorizer.checkAnyActionOnCatalog(user, roleIds, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the same as above. No need check privilege
@SerializedName(value = "m") | ||
private long maxConn = 1024; | ||
private long maxConn = MAX_CONN_DEFAULT_VALUE; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to manage these separately? Can we unify the coding with system variables? Just make sure that user properties and system variables do not have the same name (this is easy for us to do because user properties are also under our control). The current approach 1. It brings complexity to the code. 2. The logic is not unified. There is a catalog in the user property and there is also a catalog in the session variable, and it is called "session.catalog". How to maintain the relationship between these two pieces of data, and what is the meaning of these two identical pieces of data? We should use user properties as a supplement and overwrite of system variables.
6fd28cd
to
ee1d2d2
Compare
Signed-off-by: yandongxiao <[email protected]>
514234a
to
44ff04e
Compare
Quality Gate failedFailed conditions See analysis details on SonarCloud Catch issues before they fail your Quality Gate with our IDE extension SonarLint |
[FE Incremental Coverage Report]✅ pass : 195 / 223 (87.44%) file detail
|
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
@mergify backport 3.3 |
❌ No backport have been created
Git reported the following error:
|
@mergify backport-3.3 |
❌ No backport have been created
GitHub error: |
@mergify backport branch-3.3 |
✅ Backports have been created
|
Signed-off-by: yandongxiao <[email protected]> (cherry picked from commit 17d1914) # Conflicts: # fe/fe-core/src/main/java/com/starrocks/sql/ast/AlterUserStmt.java # fe/fe-core/src/main/java/com/starrocks/sql/ast/BaseCreateAlterUserStmt.java # fe/fe-core/src/main/java/com/starrocks/sql/ast/CreateUserStmt.java # fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java
) Signed-off-by: yandongxiao <[email protected]>
) (#49828) Signed-off-by: yandongxiao <[email protected]>
Why I'm doing:
When the user connects to FE SQL, the Session variables need to be initialized according to the user's attribute information.
What I'm doing:
Support to CRUD user's properties.
Fixes: #48478
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: