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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions pkg/frontend/back_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,25 +329,14 @@ 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.Role = backSes.tenant.GetDefaultRole()
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 span trace.Span
execCtx.reqCtx, span = trace.Start(execCtx.reqCtx, "backExec.doComQueryInBack",
trace.WithKind(trace.SpanKindStatement))
Expand Down
15 changes: 2 additions & 13 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 @@ -3004,24 +3005,12 @@ 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.Role = ses.GetTenantInfo().GetDefaultRole()
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 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
23 changes: 23 additions & 0 deletions pkg/sql/compile/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,26 @@ func TestDebugLogFor19288(t *testing.T) {
})
}
}

func TestLockMeta_doLock(t *testing.T) {
lm := &LockMeta{
database_table_id: 11230,
table_table_id: 123123,
metaTables: map[string]struct{}{
"test1": {},
},
lockDbExe: nil,
lockTableExe: nil,
lockMetaVecs: nil,
}

ctrl := gomock.NewController(t)
defer ctrl.Finish()

proc := testutil.NewProcess()
proc.Base.SessionInfo.Buf = buffer.New()
proc.Ctx = context.Background()
eng := mock_frontend.NewMockEngine(ctrl)

assert.Error(t, lm.doLock(eng, proc))
}
24 changes: 20 additions & 4 deletions pkg/sql/compile/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ func (s *Scope) DropDatabase(c *Compile) error {
s.ScopeAnalyzer.Start()
defer s.ScopeAnalyzer.Stop()

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

dbName := s.Plan.GetDdl().GetDropDatabase().GetDatabase()
db, err := c.e.Database(c.proc.Ctx, dbName, c.proc.GetTxnOperator())
if err != nil {
Expand Down Expand Up @@ -202,7 +207,7 @@ func (s *Scope) DropDatabase(c *Compile) error {
if !needSkipDbs[dbName] {
updatePitrSql := fmt.Sprintf("update `%s`.`%s` set `%s` = %d, `%s` = %s where `%s` = %d and `%s` = '%s' and `%s` = %d and `%s` = %s",
catalog.MO_CATALOG, catalog.MO_PITR, catalog.MO_PITR_STATUS, 0, catalog.MO_PITR_CHANGED_TIME, "default",
catalog.MO_PITR_ACCOUNT_ID, c.proc.GetSessionInfo().AccountId,
catalog.MO_PITR_ACCOUNT_ID, accountId,
catalog.MO_PITR_DB_NAME, dbName,
catalog.MO_PITR_STATUS, 1,
catalog.MO_PITR_OBJECT_ID, database.GetDatabaseId(c.proc.Ctx),
Expand Down Expand Up @@ -2622,10 +2627,15 @@ func (s *Scope) DropTable(c *Compile) error {
return err
}

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

if !needSkipDbs[dbName] {
updatePitrSql := fmt.Sprintf("update `%s`.`%s` set `%s` = %d, `%s` = %s where `%s` = %d and `%s` = '%s' and `%s` = '%s' and `%s` = %d and `%s` = %d",
catalog.MO_CATALOG, catalog.MO_PITR, catalog.MO_PITR_STATUS, 0, catalog.MO_PITR_CHANGED_TIME, "default",
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,
catalog.MO_PITR_STATUS, 1,
Expand Down Expand Up @@ -3682,7 +3692,10 @@ 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
}
bat, err := getLockBatch(c.proc, accountID, []string{dbName})
if err != nil {
return err
Expand All @@ -3704,7 +3717,10 @@ 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
}
bat, err := getLockBatch(c.proc, accountID, []string{dbName, tblName})
if err != nil {
return err
Expand Down
Loading
Loading