Skip to content

Commit

Permalink
cherry-pick: fix select version (#19695)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviszhen authored Oct 31, 2024
1 parent 93f50d3 commit 6d6d7b8
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 200 deletions.
19 changes: 1 addition & 18 deletions pkg/frontend/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ var (

const (
//privilege verification
checkTenantFormat = `select account_id,account_name,status,version,suspended_time from mo_catalog.mo_account where account_name = "%s" order by account_id;`
checkTenantFormat = `select account_id,account_name,status,version,suspended_time,create_version from mo_catalog.mo_account where account_name = "%s" order by account_id;`

getTenantNameForMat = `select account_name from mo_catalog.mo_account where account_id = %d;`

Expand Down Expand Up @@ -8745,15 +8745,6 @@ func doAlterDatabaseConfig(ctx context.Context, ses *Session, ad *tree.AlterData
if err != nil {
return err
}

// step3: update the session verison
if len(ses.GetDatabaseName()) != 0 && ses.GetDatabaseName() == dbName {
err = changeVersion(ctx, ses, ses.GetDatabaseName())
if err != nil {
return err
}
}

return err
}

Expand Down Expand Up @@ -8811,14 +8802,6 @@ func doAlterAccountConfig(ctx context.Context, ses *Session, stmt *tree.AlterDat
return err
}

// step3: update the session verison
if len(ses.GetDatabaseName()) != 0 {
err = changeVersion(ctx, ses, ses.GetDatabaseName())
if err != nil {
return err
}
}

return err
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/frontend/mysql_cmd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -2623,6 +2623,11 @@ func doComQuery(ses *Session, execCtx *ExecCtx, input *UserInput) (retErr error)
ses.SetShowStmtType(NotShowStatement)
resper := ses.GetResponser()
ses.SetSql(input.getSql())
input.genHash()
version := ses.GetCreateVersion()
if len(version) == 0 {
version = serverVersion.Load().(string)
}

sqlLen := len(input.getSql())
if sqlLen != 0 {
Expand Down Expand Up @@ -2661,7 +2666,7 @@ func doComQuery(ses *Session, execCtx *ExecCtx, input *UserInput) (retErr error)
Host: getGlobalPu().SV.Host,
ConnectionID: uint64(resper.GetU32(CONNID)),
Database: ses.GetDatabaseName(),
Version: makeServerVersion(getGlobalPu(), serverVersion.Load().(string)),
Version: makeServerVersion(getGlobalPu(), version),
TimeZone: ses.GetTimeZone(),
StorageEngine: getGlobalPu().StorageEngine,
LastInsertID: ses.GetLastInsertID(),
Expand Down
4 changes: 2 additions & 2 deletions pkg/frontend/mysql_protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const charsetVarchar = 0x21
const boolColumnLength = 12

func init() {
serverVersion.Store("0.5.0")
serverVersion.Store("1.2.3")
}

func InitServerVersion(v string) {
Expand All @@ -101,7 +101,7 @@ func InitServerVersion(v string) {
serverVersion.Store(string(vv))
}
} else {
serverVersion.Store("0.5.0")
serverVersion.Store("1.2.3")
}
}

Expand Down
4 changes: 0 additions & 4 deletions pkg/frontend/self_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ func execInFrontend(ses *Session, execCtx *ExecCtx) (err error) {
if err != nil {
return
}
err = changeVersion(execCtx.reqCtx, ses, st.Name.Compare())
if err != nil {
return
}
case *tree.MoDump:

//dump
Expand Down
36 changes: 23 additions & 13 deletions pkg/frontend/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ type Session struct {
proxyAddr string

disableTrace bool
// create version
createVersion string
}

func (ses *Session) InitSystemVariables(ctx context.Context) (err error) {
Expand Down Expand Up @@ -962,6 +964,18 @@ func (ses *Session) GetUserDefinedVar(name string) (*UserDefinedVar, error) {
return val, nil
}

func (ses *Session) SetCreateVersion(version string) {
ses.mu.Lock()
defer ses.mu.Unlock()
ses.createVersion = version
}

func (ses *Session) GetCreateVersion() string {
ses.mu.Lock()
defer ses.mu.Unlock()
return ses.createVersion
}

func (ses *Session) GetTxnInfo() string {
txnH := ses.GetTxnHandler()
if txnH == nil {
Expand Down Expand Up @@ -1010,6 +1024,7 @@ func (ses *Session) AuthenticateUser(ctx context.Context, userInput string, dbNa
var userID int64
var pwd, accountStatus string
var accountVersion uint64
var createVersion string

//Get tenant info
tenant, err = GetTenantInfo(ctx, userInput)
Expand Down Expand Up @@ -1058,12 +1073,18 @@ func (ses *Session) AuthenticateUser(ctx context.Context, userInput string, dbNa
return nil, err
}

//account version
// account version
accountVersion, err = rsset[0].GetUint64(sysTenantCtx, 0, 3)
if err != nil {
return nil, err
}

// create version
createVersion, err = rsset[0].GetString(sysTenantCtx, 0, 5)
if err != nil {
return nil, err
}

if strings.ToLower(accountStatus) == tree.AccountStatusSuspend.String() {
return nil, moerr.NewInternalErrorf(sysTenantCtx, "Account %s is suspended", tenant.GetTenant())
}
Expand Down Expand Up @@ -1223,6 +1244,7 @@ func (ses *Session) AuthenticateUser(ctx context.Context, userInput string, dbNa
// record the id :routine pair in RoutineManager
ses.getRoutineManager().accountRoutine.recordRountine(tenantID, ses.getRoutine(), accountVersion)
ses.Info(ctx, tenant.String())
ses.SetCreateVersion(createVersion)

return GetPassWord(pwd)
}
Expand Down Expand Up @@ -1307,18 +1329,6 @@ func (ses *Session) GetFromRealUser() bool {
return ses.fromRealUser
}

func changeVersion(ctx context.Context, ses *Session, db string) error {
var err error
if _, ok := bannedCatalogDatabases[db]; ok {
return err
}
version, _ := GetVersionCompatibility(ctx, ses, db)
if ses.GetTenantInfo() != nil {
ses.GetTenantInfo().SetVersion(version)
}
return err
}

// getCNLabels returns requested CN labels.
func (ses *Session) getCNLabels() map[string]string {
return ses.requestLabel
Expand Down
93 changes: 0 additions & 93 deletions test/distributed/cases/database/config.result

This file was deleted.

65 changes: 0 additions & 65 deletions test/distributed/cases/database/config.sql

This file was deleted.

19 changes: 16 additions & 3 deletions test/distributed/cases/zz_accesscontrol/account_restricted.result
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,6 @@ r_test BASE TABLE
show full tables from res_test;;
Tables_in_res_test Table_type
r_test BASE TABLE
select version();
version()
8.0.30-MatrixOne-v1.0.0
alter database test set mysql_compatibility_mode = '8.0.30-MatrixOne-v0.7.0';
internal error: do not have privilege to execute the statement
select privilege_name, obj_type, privilege_level from mo_catalog.mo_role_privs where privilege_name = 'values';
Expand Down Expand Up @@ -313,4 +310,20 @@ drop role role1;
drop database rdb;
drop database res_test;
drop account if exists acc1;
select version();
version()
8.0.30-MatrixOne-v1.3.0
drop database if exists abc;
create database abc;
use abc;
select version();
version()
8.0.30-MatrixOne-v1.3.0
drop database abc;
drop account if exists acc01;
create account acc01 ADMIN_NAME 'admin' IDENTIFIED BY '123456';
select version();
version()
8.0.30-MatrixOne-v1.3.0
drop account if exists acc01;
set global enable_privilege_cache = on;
17 changes: 16 additions & 1 deletion test/distributed/cases/zz_accesscontrol/account_restricted.sql
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ show collation like 'utf8mb4_general_ci%';
show full tables;
show full tables from res_test;;

select version();
alter database test set mysql_compatibility_mode = '8.0.30-MatrixOne-v0.7.0';
select privilege_name, obj_type, privilege_level from mo_catalog.mo_role_privs where privilege_name = 'values';
select user_name from mo_catalog.mo_user;
Expand Down Expand Up @@ -134,4 +133,20 @@ drop database rdb;
drop database res_test;
-- @session
drop account if exists acc1;

-- @ignore:0
select version();
drop database if exists abc;
create database abc;
use abc;
-- @ignore:0
select version();
drop database abc;
drop account if exists acc01;
create account acc01 ADMIN_NAME 'admin' IDENTIFIED BY '123456';
-- @session:id=7&user=acc01:admin&password=123456
-- @ignore:0
select version();
-- @session
drop account if exists acc01;
set global enable_privilege_cache = on;

0 comments on commit 6d6d7b8

Please sign in to comment.