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

Stats authorization time consumption #20998

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
0b3e16b
add Permission authentication resource statistics
qingxinhome Dec 30, 2024
bb3d113
Merge branch 'main' into StatsAuthorizationTimeConsumption
qingxinhome Dec 30, 2024
9aa45b3
append code
qingxinhome Dec 30, 2024
bdd5279
Merge branch 'main' into StatsAuthorizationTimeConsumption
qingxinhome Dec 30, 2024
b93958f
Merge branch 'main' into StatsAuthorizationTimeConsumption
qingxinhome Dec 31, 2024
2e82fc4
Additional permission authentication SQL resource statistics
qingxinhome Dec 31, 2024
f1c38b9
update ut test case
qingxinhome Dec 31, 2024
018d5e1
imporve code
qingxinhome Dec 31, 2024
d5b2445
add code
qingxinhome Dec 31, 2024
9f6ea21
merge code from main
qingxinhome Jan 8, 2025
701bda4
update code
qingxinhome Jan 8, 2025
5ebf14c
Merge branch 'main' into StatsAuthorizationTimeConsumption
qingxinhome Jan 8, 2025
af4b1cc
Merge branch 'main' into StatsAuthorizationTimeConsumption
qingxinhome Jan 8, 2025
54f1717
Merge branch 'main' into StatsAuthorizationTimeConsumption
qingxinhome Jan 12, 2025
0051c1f
Merge branch 'main' into StatsAuthorizationTimeConsumption
qingxinhome Jan 13, 2025
cf177e3
Merge branch 'main' into StatsAuthorizationTimeConsumption
qingxinhome Jan 14, 2025
e22825e
Merge branch 'main' into StatsAuthorizationTimeConsumption
qingxinhome Jan 14, 2025
64c3cb2
Merge branch 'main' into StatsAuthorizationTimeConsumption
qingxinhome Jan 14, 2025
bdcecf8
Merge branch 'main' into StatsAuthorizationTimeConsumption
qingxinhome Jan 14, 2025
289df32
Merge branch 'main' into StatsAuthorizationTimeConsumption
qingxinhome Jan 14, 2025
2747d02
Merge branch 'main' into StatsAuthorizationTimeConsumption
qingxinhome Jan 16, 2025
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
245 changes: 148 additions & 97 deletions pkg/frontend/authenticate.go

Large diffs are not rendered by default.

123 changes: 64 additions & 59 deletions pkg/frontend/authenticate_test.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pkg/frontend/back_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ func doComQueryInBack(
defer span.End()

// Instantiate StatsInfo to track SQL resource statistics
statsInfo := new(statistic.StatsInfo)
//statsInfo := new(statistic.StatsInfo)
statsInfo := statistic.NewStatsInfo()
statsInfo.ParseStage.ParseStartTime = beginInstant
execCtx.reqCtx = statistic.ContextWithStatsInfo(execCtx.reqCtx, statsInfo)
execCtx.input = input
Expand Down
49 changes: 39 additions & 10 deletions pkg/frontend/computation_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,14 @@ func (cwft *TxnComputationWrapper) GetServerStatus() uint16 {
return uint16(cwft.ses.GetTxnHandler().GetServerStatus())
}

func checkResultQueryPrivilege(proc *process.Process, p *plan.Plan, reqCtx context.Context, sid string, ses *Session) error {
func checkResultQueryPrivilege(proc *process.Process, p *plan.Plan, reqCtx context.Context, sid string, ses *Session) (statistic.StatsArray, error) {
var ids []string
var err error
var stats statistic.StatsArray
stats.Reset()

if ids, err = isResultQuery(proc, p); err != nil || ids == nil {
return err
return stats, err
}
return checkPrivilege(sid, ids, reqCtx, ses)
}
Expand All @@ -188,37 +191,56 @@ func checkResultQueryPrivilege(proc *process.Process, p *plan.Plan, reqCtx conte
func (cwft *TxnComputationWrapper) Compile(any any, fill func(*batch.Batch, *perfcounter.CounterSet) error) (interface{}, error) {
var originSQL string
var span trace.Span
var err error

execCtx := any.(*ExecCtx)
execCtx.reqCtx, span = trace.Start(execCtx.reqCtx, "TxnComputationWrapper.Compile",
trace.WithKind(trace.SpanKindStatement))
defer span.End(trace.WithStatementExtra(cwft.ses.GetTxnId(), cwft.ses.GetStmtId(), cwft.ses.GetSqlOfStmt()))

var err error
defer RecordStatementTxnID(execCtx.reqCtx, cwft.ses)
if cwft.ses.GetTxnHandler().HasTempEngine() {
updateTempStorageInCtx(execCtx, cwft.proc, cwft.ses.GetTxnHandler().GetTempStorage())
}
stats := statistic.StatsInfoFromContext(execCtx.reqCtx)

cacheHit := cwft.plan != nil
if !cacheHit {
cwft.plan, err = buildPlan(execCtx.reqCtx, cwft.ses, cwft.ses.GetTxnCompileCtx(), cwft.stmt)
cwft.plan, err = buildPlanWithAuthorization(execCtx.reqCtx, cwft.ses, cwft.ses.GetTxnCompileCtx(), cwft.stmt)
if err != nil {
return nil, err
}
//cwft.plan, err = buildPlan(execCtx.reqCtx, cwft.ses, cwft.ses.GetTxnCompileCtx(), cwft.stmt)
} else if cwft.ses != nil && cwft.ses.GetTenantInfo() != nil && !cwft.ses.IsBackgroundSession() {
var accId uint32
accId, err = defines.GetAccountId(execCtx.reqCtx)
if err != nil {
return nil, err
}
cwft.ses.SetAccountId(accId)
err = authenticateCanExecuteStatementAndPlan(execCtx.reqCtx, cwft.ses.(*Session), cwft.stmt, cwft.plan)
}
if err != nil {
return nil, err

//err = authenticateCanExecuteStatementAndPlan(execCtx.reqCtx, cwft.ses.(*Session), cwft.stmt, cwft.plan)
authStats, err := authenticateCanExecuteStatementAndPlan(execCtx.reqCtx, cwft.ses.(*Session), cwft.stmt, cwft.plan)
if err != nil {
return nil, err
}
// record permission statistics.
stats.PermissionAuth.Add(&authStats)
}
//if err != nil {
// return nil, err
//}
if !cwft.ses.IsBackgroundSession() {
cwft.ses.SetPlan(cwft.plan)
if err := checkResultQueryPrivilege(cwft.proc, cwft.plan, execCtx.reqCtx, cwft.ses.GetService(), cwft.ses.(*Session)); err != nil {
//if err := checkResultQueryPrivilege(cwft.proc, cwft.plan, execCtx.reqCtx, cwft.ses.GetService(), cwft.ses.(*Session)); err != nil {
// return nil, err
//}

authStats, err := checkResultQueryPrivilege(cwft.proc, cwft.plan, execCtx.reqCtx, cwft.ses.GetService(), cwft.ses.(*Session))
if err != nil {
return nil, err
}
stats.PermissionAuth.Add(&authStats)
}

if _, isTextProtExecute := cwft.stmt.(*tree.Execute); isTextProtExecute || execCtx.input.isBinaryProtExecute {
Expand All @@ -232,9 +254,15 @@ func (cwft *TxnComputationWrapper) Compile(any any, fill func(*batch.Batch, *per
if err != nil {
return nil, err
}
if err := checkResultQueryPrivilege(cwft.proc, plan, execCtx.reqCtx, cwft.ses.GetService(), cwft.ses.(*Session)); err != nil {
//if err := checkResultQueryPrivilege(cwft.proc, plan, execCtx.reqCtx, cwft.ses.GetService(), cwft.ses.(*Session)); err != nil {
// return nil, err
//}
authStats, err := checkResultQueryPrivilege(cwft.proc, plan, execCtx.reqCtx, cwft.ses.GetService(), cwft.ses.(*Session))
if err != nil {
return nil, err
}
stats.PermissionAuth.Add(&authStats)

cwft.plan = plan
cwft.stmt.Free()
// reset plan & stmt
Expand Down Expand Up @@ -510,6 +538,7 @@ func createCompile(
)
retCompile.SetIsPrepare(isPrepare)
retCompile.SetBuildPlanFunc(func(ctx context.Context) (*plan2.Plan, error) {
// No permission verification is required when retry execute buildPlan
plan, err := buildPlan(ctx, ses, ses.GetTxnCompileCtx(), stmt)
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion pkg/frontend/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func handleCreateDynamicTable(ctx context.Context, ses *Session, st *tree.Create
}
}

generatedPlan, err := buildPlan(ctx, ses, ses.GetTxnCompileCtx(), st.AsSource)
generatedPlan, err := buildPlanWithAuthorization(ctx, ses, ses.GetTxnCompileCtx(), st.AsSource)
//generatedPlan, err := buildPlan(ctx, ses, ses.GetTxnCompileCtx(), st.AsSource)
if err != nil {
return err
}
Expand Down
Loading
Loading