Skip to content
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

remove the accountinfo in process.sessioninfo #21101

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
22 changes: 11 additions & 11 deletions pkg/frontend/back_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,24 +329,24 @@ func doComQueryInBack(
//!!!does not init sequence in the background exec
if backSes.tenant != nil {
proc.Base.SessionInfo.Account = backSes.tenant.GetTenant()
proc.Base.SessionInfo.AccountId = backSes.tenant.GetTenantID()
//proc.Base.SessionInfo.AccountId = backSes.tenant.GetTenantID()
proc.Base.SessionInfo.Role = backSes.tenant.GetDefaultRole()
proc.Base.SessionInfo.RoleId = backSes.tenant.GetDefaultRoleID()
proc.Base.SessionInfo.UserId = backSes.tenant.GetUserID()
//proc.Base.SessionInfo.RoleId = backSes.tenant.GetDefaultRoleID()
//proc.Base.SessionInfo.UserId = backSes.tenant.GetUserID()

if len(backSes.tenant.GetVersion()) != 0 {
proc.Base.SessionInfo.Version = backSes.tenant.GetVersion()
}
userNameOnly = backSes.tenant.GetUser()
} else {
var accountId uint32
accountId, retErr = defines.GetAccountId(execCtx.reqCtx)
if retErr != nil {
return retErr
}
proc.Base.SessionInfo.AccountId = accountId
proc.Base.SessionInfo.UserId = defines.GetUserId(execCtx.reqCtx)
proc.Base.SessionInfo.RoleId = defines.GetRoleId(execCtx.reqCtx)
//var accountId uint32
//accountId, retErr = defines.GetAccountId(execCtx.reqCtx)
//if retErr != nil {
// return retErr
//}
//proc.Base.SessionInfo.AccountId = accountId
//proc.Base.SessionInfo.UserId = defines.GetUserId(execCtx.reqCtx)
//proc.Base.SessionInfo.RoleId = defines.GetRoleId(execCtx.reqCtx)
}
var span trace.Span
execCtx.reqCtx, span = trace.Start(execCtx.reqCtx, "backExec.doComQueryInBack",
Expand Down
25 changes: 13 additions & 12 deletions pkg/frontend/mysql_cmd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ var RecordStatement = func(ctx context.Context, ses *Session, proc *process.Proc

stm.ConnectionId = ses.GetConnectionID()
stm.Account = tenant.GetTenant()
stm.RoleId = proc.GetSessionInfo().RoleId
stm.RoleId = tenant.GetDefaultRoleID()
//stm.RoleId = proc.GetSessionInfo().RoleId
stm.User = tenant.GetUser()
stm.Host = ses.respr.GetStr(PEER)
stm.Database = ses.respr.GetStr(DBNAME)
Expand Down Expand Up @@ -2995,24 +2996,24 @@ func doComQuery(ses *Session, execCtx *ExecCtx, input *UserInput) (retErr error)
ses.CopySeqToProc(proc)
if ses.GetTenantInfo() != nil {
proc.Base.SessionInfo.Account = ses.GetTenantInfo().GetTenant()
proc.Base.SessionInfo.AccountId = ses.GetTenantInfo().GetTenantID()
//proc.Base.SessionInfo.AccountId = ses.GetTenantInfo().GetTenantID()
proc.Base.SessionInfo.Role = ses.GetTenantInfo().GetDefaultRole()
proc.Base.SessionInfo.RoleId = ses.GetTenantInfo().GetDefaultRoleID()
proc.Base.SessionInfo.UserId = ses.GetTenantInfo().GetUserID()
//proc.Base.SessionInfo.RoleId = ses.GetTenantInfo().GetDefaultRoleID()
//proc.Base.SessionInfo.UserId = ses.GetTenantInfo().GetUserID()

if len(ses.GetTenantInfo().GetVersion()) != 0 {
proc.Base.SessionInfo.Version = ses.GetTenantInfo().GetVersion()
}
userNameOnly = ses.GetTenantInfo().GetUser()
} else {
var accountId uint32
accountId, retErr = defines.GetAccountId(execCtx.reqCtx)
if retErr != nil {
return retErr
}
proc.Base.SessionInfo.AccountId = accountId
proc.Base.SessionInfo.UserId = defines.GetUserId(execCtx.reqCtx)
proc.Base.SessionInfo.RoleId = defines.GetRoleId(execCtx.reqCtx)
//var accountId uint32
//accountId, retErr = defines.GetAccountId(execCtx.reqCtx)
//if retErr != nil {
// return retErr
//}
//proc.Base.SessionInfo.AccountId = accountId
//proc.Base.SessionInfo.UserId = defines.GetUserId(execCtx.reqCtx)
//proc.Base.SessionInfo.RoleId = defines.GetRoleId(execCtx.reqCtx)
}
var span trace.Span
execCtx.reqCtx, span = trace.Start(execCtx.reqCtx, "doComQuery",
Expand Down
7 changes: 6 additions & 1 deletion pkg/frontend/query_result.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,16 @@ func saveMeta(ctx context.Context, ses *Session) error {
if err != nil {
return err
}

//-------------------------------------------------------
roleId := defines.GetRoleId(ctx)
//-------------------------------------------------------

m := &catalog.Meta{
QueryId: ses.GetStmtId(),
Statement: ses.GetSql(),
AccountId: ses.GetTenantInfo().GetTenantID(),
RoleId: ses.proc.GetSessionInfo().RoleId,
RoleId: roleId,
ResultPath: buf.String(),
CreateTime: types.UnixToTimestamp(ses.createdTime.Unix()),
ResultSize: ses.curResultSize,
Expand Down
17 changes: 14 additions & 3 deletions pkg/sql/colexec/table_function/current_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/common/moerr"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/defines"
"github.com/matrixorigin/matrixone/pkg/vm/process"
)

Expand All @@ -38,22 +39,32 @@ func (s *currentAccountState) start(tf *TableFunction, proc *process.Process, nt
// we do not call startPreamble here,
// there are very specific way of constructing the batch, below.
var err error

//-------------------------------------------------------
accountId, err := defines.GetAccountId(proc.Ctx)
if err != nil {
return err
}
userId := defines.GetUserId(proc.Ctx)
roleId := defines.GetRoleId(proc.Ctx)
//-------------------------------------------------------

if s.batch == nil {
s.batch = tf.createResultBatch()
for i, attr := range tf.Attrs {
switch attr {
case "account_name":
s.batch.Vecs[i], err = vector.NewConstBytes(types.T_varchar.ToType(), []byte(proc.GetSessionInfo().Account), 1, proc.Mp())
case "account_id":
s.batch.Vecs[i], err = vector.NewConstFixed(types.T_uint32.ToType(), proc.GetSessionInfo().AccountId, 1, proc.Mp())
s.batch.Vecs[i], err = vector.NewConstFixed(types.T_uint32.ToType(), accountId, 1, proc.Mp())
case "user_name":
s.batch.Vecs[i], err = vector.NewConstBytes(types.T_varchar.ToType(), []byte(proc.GetSessionInfo().User), 1, proc.Mp())
case "user_id":
s.batch.Vecs[i], err = vector.NewConstFixed(types.T_uint32.ToType(), proc.GetSessionInfo().UserId, 1, proc.Mp())
s.batch.Vecs[i], err = vector.NewConstFixed(types.T_uint32.ToType(), userId, 1, proc.Mp())
case "role_name":
s.batch.Vecs[i], err = vector.NewConstBytes(types.T_varchar.ToType(), []byte(proc.GetSessionInfo().Role), 1, proc.Mp())
case "role_id":
s.batch.Vecs[i], err = vector.NewConstFixed(types.T_uint32.ToType(), proc.GetSessionInfo().RoleId, 1, proc.Mp())
s.batch.Vecs[i], err = vector.NewConstFixed(types.T_uint32.ToType(), roleId, 1, proc.Mp())
default:
err = moerr.NewInvalidInputf(proc.Ctx, "%v is not supported by current_account()", attr)
}
Expand Down
26 changes: 22 additions & 4 deletions pkg/sql/colexec/table_function/fulltext.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/defines"
"github.com/matrixorigin/matrixone/pkg/fulltext"
"github.com/matrixorigin/matrixone/pkg/pb/plan"
"github.com/matrixorigin/matrixone/pkg/sql/colexec"
Expand Down Expand Up @@ -217,6 +218,15 @@ func ft_runSql_fn(proc *process.Process, sql string) (executor.Result, error) {
if !ok {
panic("missing lock service")
}

//-------------------------------------------------------
topContext := proc.GetTopContext()
accountId, err := defines.GetAccountId(proc.Ctx)
if err != nil {
return executor.Result{}, err
}
//-------------------------------------------------------

exec := v.(executor.SQLExecutor)
opts := executor.Options{}.
// All runSql and runSqlWithResult is a part of input sql, can not incr statement.
Expand All @@ -225,8 +235,8 @@ func ft_runSql_fn(proc *process.Process, sql string) (executor.Result, error) {
WithTxn(proc.GetTxnOperator()).
WithDatabase(proc.GetSessionInfo().Database).
WithTimeZone(proc.GetSessionInfo().TimeZone).
WithAccountID(proc.GetSessionInfo().AccountId)
return exec.Exec(proc.GetTopContext(), sql, opts)
WithAccountID(accountId)
return exec.Exec(topContext, sql, opts)
}

var ft_runSql_streaming = ft_runSql_streaming_fn
Expand All @@ -237,6 +247,14 @@ func ft_runSql_streaming_fn(proc *process.Process, sql string, stream_chan chan
if !ok {
panic("missing lock service")
}

//-------------------------------------------------------
topContext := proc.GetTopContext()
accountId, err := defines.GetAccountId(proc.Ctx)
if err != nil {
return executor.Result{}, err
}
//-------------------------------------------------------
exec := v.(executor.SQLExecutor)
opts := executor.Options{}.
// All runSql and runSqlWithResult is a part of input sql, can not incr statement.
Expand All @@ -245,9 +263,9 @@ func ft_runSql_streaming_fn(proc *process.Process, sql string, stream_chan chan
WithTxn(proc.GetTxnOperator()).
WithDatabase(proc.GetSessionInfo().Database).
WithTimeZone(proc.GetSessionInfo().TimeZone).
WithAccountID(proc.GetSessionInfo().AccountId).
WithAccountID(accountId).
WithStreaming(stream_chan, error_chan)
return exec.Exec(proc.GetTopContext(), sql, opts)
return exec.Exec(topContext, sql, opts)
}

// run SQL to get the (doc_id, word_index) of all patterns (words) in the search string
Expand Down
27 changes: 23 additions & 4 deletions pkg/sql/compile/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ func (s *Scope) CreateDatabase(c *Compile) error {
return err
}

accountId, err := defines.GetAccountId(ctx)
if err != nil {
return err
}

updatePitrSql := fmt.Sprintf("update `%s`.`%s` set `%s` = '%s' where `%s` = %d and `%s` = '%s'",
catalog.MO_CATALOG, catalog.MO_PITR, catalog.MO_PITR_OBJECT_ID, newDb.GetDatabaseId(ctx),
catalog.MO_PITR_ACCOUNT_ID, c.proc.GetSessionInfo().AccountId,
catalog.MO_PITR_ACCOUNT_ID, accountId,
catalog.MO_PITR_DB_NAME, dbName)

err = c.runSqlWithSystemTenant(updatePitrSql)
Expand Down Expand Up @@ -1537,9 +1542,15 @@ func (s *Scope) CreateTable(c *Compile) error {
if err != nil {
return err
}

accountId, err := defines.GetAccountId(c.proc.Ctx)
if err != nil {
return err
}

updatePitrSql := fmt.Sprintf("update `%s`.`%s` set `%s` = %d where `%s` = %d and `%s` = '%s' and `%s` = '%s'",
catalog.MO_CATALOG, catalog.MO_PITR, catalog.MO_PITR_OBJECT_ID, newRelation.GetTableID(c.proc.Ctx),
catalog.MO_PITR_ACCOUNT_ID, c.proc.GetSessionInfo().AccountId,
catalog.MO_PITR_ACCOUNT_ID, accountId,
catalog.MO_PITR_DB_NAME, dbName,
catalog.MO_PITR_TABLE_NAME, tblName)

Expand Down Expand Up @@ -3817,7 +3828,11 @@ var lockMoDatabase = func(c *Compile, dbName string, lockMode lock.LockMode) err
if err != nil {
return err
}
accountID := c.proc.GetSessionInfo().AccountId

accountID, err := defines.GetAccountId(c.proc.Ctx)
if err != nil {
return err
}
vec, err := getLockVector(c.proc, accountID, []string{dbName})
if err != nil {
return err
Expand All @@ -3838,7 +3853,11 @@ var lockMoTable = func(
if err != nil {
return err
}
accountID := c.proc.GetSessionInfo().AccountId

accountID, err := defines.GetAccountId(c.proc.Ctx)
if err != nil {
return err
}
vec, err := getLockVector(c.proc, accountID, []string{dbName, tblName})
if err != nil {
return err
Expand Down
9 changes: 7 additions & 2 deletions pkg/sql/compile/lock_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/matrixorigin/matrixone/pkg/container/batch"
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/container/vector"
"github.com/matrixorigin/matrixone/pkg/defines"
"github.com/matrixorigin/matrixone/pkg/pb/lock"
"github.com/matrixorigin/matrixone/pkg/pb/plan"
"github.com/matrixorigin/matrixone/pkg/sql/colexec"
Expand Down Expand Up @@ -119,7 +120,11 @@ func (l *LockMeta) doLock(e engine.Engine, proc *process.Process) error {
}
}

accountId := proc.GetSessionInfo().AccountId
accountId, err := defines.GetAccountId(proc.Ctx)
if err != nil {
return err
}

lockDbs := make(map[string]struct{})
bat := batch.NewWithSize(3)
for _, table := range tables {
Expand All @@ -141,7 +146,7 @@ func (l *LockMeta) doLock(e engine.Engine, proc *process.Process) error {

// call serial function to lock mo_tables
bat.Vecs = l.lockMetaVecs
err := l.lockMetaRows(e, proc, l.lockTableExe, bat, accountId, l.table_table_id)
err = l.lockMetaRows(e, proc, l.lockTableExe, bat, accountId, l.table_table_id)
if err != nil {
return err
}
Expand Down
18 changes: 9 additions & 9 deletions pkg/sql/compile/sql_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,17 +305,17 @@ func (exec *txnExecutor) Exec(
exec.s.us,
nil,
)
accId, err := defines.GetAccountId(proc.Ctx)
if err != nil {
return executor.Result{}, err
}
useId := defines.GetUserId(proc.Ctx)
roleId := defines.GetRoleId(proc.Ctx)
//accId, err := defines.GetAccountId(proc.Ctx)
//if err != nil {
// return executor.Result{}, err
//}
//useId := defines.GetUserId(proc.Ctx)
//roleId := defines.GetRoleId(proc.Ctx)

proc.Base.WaitPolicy = statementOption.WaitPolicy()
proc.Base.SessionInfo.AccountId = accId
proc.Base.SessionInfo.UserId = useId
proc.Base.SessionInfo.RoleId = roleId
//proc.Base.SessionInfo.AccountId = accId
//proc.Base.SessionInfo.UserId = useId
//proc.Base.SessionInfo.RoleId = roleId
proc.Base.SessionInfo.TimeZone = exec.opts.GetTimeZone()
proc.Base.SessionInfo.Buf = exec.s.buf
proc.Base.SessionInfo.StorageEngine = exec.s.eng
Expand Down
11 changes: 9 additions & 2 deletions pkg/sql/plan/build_dml_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3293,6 +3293,13 @@ func runSql(ctx CompilerContext, sql string) (executor.Result, error) {
panic("missing lock service")
}
proc := ctx.GetProcess()

topContext := proc.GetTopContext()
accountId, err := defines.GetAccountId(topContext)
if err != nil {
return executor.Result{}, err
}

exec := v.(executor.SQLExecutor)
opts := executor.Options{}.
// All runSql and runSqlWithResult is a part of input sql, can not incr statement.
Expand All @@ -3301,8 +3308,8 @@ func runSql(ctx CompilerContext, sql string) (executor.Result, error) {
WithTxn(proc.GetTxnOperator()).
WithDatabase(proc.GetSessionInfo().Database).
WithTimeZone(proc.GetSessionInfo().TimeZone).
WithAccountID(proc.GetSessionInfo().AccountId)
return exec.Exec(proc.GetTopContext(), sql, opts)
WithAccountID(accountId)
return exec.Exec(topContext, sql, opts)
}

/*
Expand Down
17 changes: 14 additions & 3 deletions pkg/sql/plan/function/ctl/cmd_inspectdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package ctl

import (
"github.com/matrixorigin/matrixone/pkg/container/types"
"github.com/matrixorigin/matrixone/pkg/defines"
"github.com/matrixorigin/matrixone/pkg/pb/api"
"github.com/matrixorigin/matrixone/pkg/vm/engine/cmd_util"
"github.com/matrixorigin/matrixone/pkg/vm/process"
Expand All @@ -26,11 +27,21 @@ func handleInspectTN() handleFunc {
api.OpCode_OpInspect,
func(string) ([]uint64, error) { return nil, nil },
func(tnShardID uint64, parameter string, proc *process.Process) ([]byte, error) {
//---------------------------------------------------------------------------
topContext := proc.GetTopContext()
accountId, err := defines.GetAccountId(topContext)
if err != nil {
return nil, err
}
useId := defines.GetUserId(topContext)
roleId := defines.GetRoleId(topContext)
//---------------------------------------------------------------------------

return types.Encode(&cmd_util.InspectTN{
AccessInfo: cmd_util.AccessInfo{
AccountID: proc.GetSessionInfo().AccountId,
UserID: proc.GetSessionInfo().UserId,
RoleID: proc.GetSessionInfo().RoleId,
AccountID: accountId,
UserID: useId,
RoleID: roleId,
},
Operation: parameter,
})
Expand Down
Loading
Loading