Skip to content

Commit 3549342

Browse files
committed
Merge branch 'master' into fix_58305
2 parents 221528d + 8a80a41 commit 3549342

File tree

26 files changed

+540
-262
lines changed

26 files changed

+540
-262
lines changed

lightning/pkg/importer/import.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,9 @@ func (rc *Controller) restoreSchema(ctx context.Context) error {
593593
// we can handle the duplicated created with createIfNotExist statement
594594
// and we will check the schema in TiDB is valid with the datafile in DataCheck later.
595595
logger := log.FromContext(ctx)
596-
concurrency := min(rc.cfg.App.RegionConcurrency, 8)
596+
// the minimum 4 comes the fact that when connect to non-owner TiDB, the max
597+
// QPS is 2 per connection due to polling every 500ms.
598+
concurrency := max(2*rc.cfg.App.RegionConcurrency, 4)
597599
// sql.DB is a connection pool, we set it to concurrency + 1(for job generator)
598600
// to reuse connections, as we might call db.Conn/conn.Close many times.
599601
// there's no API to get sql.DB.MaxIdleConns, so we revert to its default which is 2

pkg/distsql/context/context.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ type DistSQLContext struct {
8585
SessionAlias string
8686

8787
ExecDetails *execdetails.SyncExecDetails
88+
89+
// Only one cop-reader can use lite worker. Using lite-worker in multiple readers will affect the concurrent execution of readers.
90+
TryCopLiteWorker uint32
8891
}
8992

9093
// AppendWarning appends the warning to the warning handler.

pkg/distsql/context/context_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func TestContextDetach(t *testing.T) {
8989
ReplicaClosestReadThreshold: 1,
9090
ConnectionID: 1,
9191
SessionAlias: "c",
92+
TryCopLiteWorker: 1,
9293
}
9394

9495
obj.AppendWarning(errors.New("test warning"))

pkg/distsql/distsql.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func Select(ctx context.Context, dctx *distsqlctx.DistSQLContext, kvReq *kv.Requ
8080
EnabledRateLimitAction: enabledRateLimitAction,
8181
EventCb: eventCb,
8282
EnableCollectExecutionInfo: config.GetGlobalConfig().Instance.EnableCollectExecutionInfo.Load(),
83+
TryCopLiteWorker: &dctx.TryCopLiteWorker,
8384
}
8485

8586
if kvReq.StoreType == kv.TiFlash {

pkg/executor/recommend_index.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,13 @@ func (e *RecommendIndexExec) Next(ctx context.Context, req *chunk.Chunk) error {
8181
req.AppendString(3, strings.Join(r.IndexColumns, ","))
8282
req.AppendString(4, fmt.Sprintf("%v", r.IndexDetail.IndexSize))
8383
req.AppendString(5, r.IndexDetail.Reason)
84-
8584
jData, err := json.Marshal(r.TopImpactedQueries)
8685
if err != nil {
8786
return err
8887
}
8988
req.AppendString(6, string(jData))
89+
req.AppendString(7, fmt.Sprintf("CREATE INDEX %s ON %s(%s);",
90+
r.IndexName, r.Table, strings.Join(r.IndexColumns, ",")))
9091
}
9192
return err
9293
}

pkg/executor/show.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ func (e *ShowExec) fetchShowCreateUser(ctx context.Context) error {
17511751
`SELECT plugin, Account_locked, user_attributes->>'$.metadata', Token_issuer,
17521752
Password_reuse_history, Password_reuse_time, Password_expired, Password_lifetime,
17531753
user_attributes->>'$.Password_locking.failed_login_attempts',
1754-
user_attributes->>'$.Password_locking.password_lock_time_days'
1754+
user_attributes->>'$.Password_locking.password_lock_time_days', authentication_string
17551755
FROM %n.%n WHERE User=%? AND Host=%?`,
17561756
mysql.SystemDB, mysql.UserTable, userName, strings.ToLower(hostName))
17571757
if err != nil {
@@ -1829,6 +1829,8 @@ func (e *ShowExec) fetchShowCreateUser(ctx context.Context) error {
18291829
passwordLockTimeDays = " PASSWORD_LOCK_TIME " + passwordLockTimeDays
18301830
}
18311831
}
1832+
authData := rows[0].GetString(10)
1833+
18321834
rows, _, err = exec.ExecRestrictedSQL(ctx, nil, `SELECT Priv FROM %n.%n WHERE User=%? AND Host=%?`, mysql.SystemDB, mysql.GlobalPrivTable, userName, hostName)
18331835
if err != nil {
18341836
return errors.Trace(err)
@@ -1845,7 +1847,6 @@ func (e *ShowExec) fetchShowCreateUser(ctx context.Context) error {
18451847
require = privValue.RequireStr()
18461848
}
18471849

1848-
authData := checker.GetEncodedPassword(ctx, e.User.Username, e.User.Hostname)
18491850
authStr := ""
18501851
if !(authPlugin == mysql.AuthSocket && authData == "") {
18511852
authStr = fmt.Sprintf(" AS '%s'", authData)

pkg/executor/simple.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,15 +1778,15 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt)
17781778
if !(hasCreateUserPriv || hasSystemSchemaPriv) {
17791779
return plannererrors.ErrSpecificAccessDenied.GenWithStackByArgs("CREATE USER")
17801780
}
1781-
if checker.RequestDynamicVerificationWithUser(ctx, "SYSTEM_USER", false, spec.User) && !(hasSystemUserPriv || hasRestrictedUserPriv) {
1781+
if !(hasSystemUserPriv || hasRestrictedUserPriv) && checker.RequestDynamicVerificationWithUser(ctx, "SYSTEM_USER", false, spec.User) {
17821782
return plannererrors.ErrSpecificAccessDenied.GenWithStackByArgs("SYSTEM_USER or SUPER")
17831783
}
1784-
if sem.IsEnabled() && checker.RequestDynamicVerificationWithUser(ctx, "RESTRICTED_USER_ADMIN", false, spec.User) && !hasRestrictedUserPriv {
1784+
if sem.IsEnabled() && !hasRestrictedUserPriv && checker.RequestDynamicVerificationWithUser(ctx, "RESTRICTED_USER_ADMIN", false, spec.User) {
17851785
return plannererrors.ErrSpecificAccessDenied.GenWithStackByArgs("RESTRICTED_USER_ADMIN")
17861786
}
17871787
}
17881788

1789-
exists, _, err := userExistsInternal(ctx, sqlExecutor, spec.User.Username, spec.User.Hostname)
1789+
exists, currentAuthPlugin, err := userExistsInternal(ctx, sqlExecutor, spec.User.Username, spec.User.Hostname)
17901790
if err != nil {
17911791
return err
17921792
}
@@ -1795,10 +1795,6 @@ func (e *SimpleExec) executeAlterUser(ctx context.Context, s *ast.AlterUserStmt)
17951795
failedUsers = append(failedUsers, user)
17961796
continue
17971797
}
1798-
currentAuthPlugin, err := privilege.GetPrivilegeManager(e.Ctx()).GetAuthPlugin(ctx, spec.User.Username, spec.User.Hostname)
1799-
if err != nil {
1800-
return err
1801-
}
18021798

18031799
type AuthTokenOptionHandler int
18041800
const (
@@ -2311,7 +2307,7 @@ func (e *SimpleExec) executeDropUser(ctx context.Context, s *ast.DropUserStmt) e
23112307
// Because in TiDB SUPER can be used as a substitute for any dynamic privilege, this effectively means that
23122308
// any user with SUPER requires a user with SUPER to be able to DROP the user.
23132309
// We also allow RESTRICTED_USER_ADMIN to count for simplicity.
2314-
if checker.RequestDynamicVerificationWithUser(ctx, "SYSTEM_USER", false, user) && !(hasSystemUserPriv || hasRestrictedUserPriv) {
2310+
if !(hasSystemUserPriv || hasRestrictedUserPriv) && checker.RequestDynamicVerificationWithUser(ctx, "SYSTEM_USER", false, user) {
23152311
if _, err := sqlExecutor.ExecuteInternal(internalCtx, "rollback"); err != nil {
23162312
return err
23172313
}
@@ -2522,14 +2518,13 @@ func (e *SimpleExec) executeSetPwd(ctx context.Context, s *ast.SetPwdStmt) error
25222518
h = s.User.Hostname
25232519

25242520
checker := privilege.GetPrivilegeManager(e.Ctx())
2525-
checker.MatchIdentity(ctx, u, h, false)
25262521
activeRoles := e.Ctx().GetSessionVars().ActiveRoles
25272522
if checker != nil && !checker.RequestVerification(activeRoles, "", "", "", mysql.SuperPriv) {
25282523
currUser := e.Ctx().GetSessionVars().User
25292524
return exeerrors.ErrDBaccessDenied.GenWithStackByArgs(currUser.Username, currUser.Hostname, "mysql")
25302525
}
25312526
}
2532-
exists, _, err := userExistsInternal(ctx, sqlExecutor, u, h)
2527+
exists, authplugin, err := userExistsInternal(ctx, sqlExecutor, u, h)
25332528
if err != nil {
25342529
return err
25352530
}
@@ -2544,10 +2539,6 @@ func (e *SimpleExec) executeSetPwd(ctx context.Context, s *ast.SetPwdStmt) error
25442539
disableSandboxMode = true
25452540
}
25462541

2547-
authplugin, err := privilege.GetPrivilegeManager(e.Ctx()).GetAuthPlugin(ctx, u, h)
2548-
if err != nil {
2549-
return err
2550-
}
25512542
if e.isValidatePasswordEnabled() {
25522543
if err := pwdValidator.ValidatePassword(e.Ctx().GetSessionVars(), s.Password); err != nil {
25532544
return err

pkg/extension/auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func TestAuthPlugin(t *testing.T) {
235235
// Should authenticate using plugin impl.
236236
p.AssertNumberOfCalls(t, "AuthenticateUser", 2)
237237
p.AssertCalled(t, "ValidateAuthString", "encodedpassword")
238-
p.AssertNumberOfCalls(t, "ValidateAuthString", 4)
238+
p.AssertNumberOfCalls(t, "ValidateAuthString", 3)
239239

240240
// Change password should work using ALTER USER statement.
241241
tk.MustExec("alter user 'u2'@'localhost' identified with 'authentication_test_plugin' by 'anotherrawpassword'")

pkg/kv/kv.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ type ClientSendOption struct {
327327
EnableCollectExecutionInfo bool
328328
TiFlashReplicaRead tiflash.ReplicaRead
329329
AppendWarning func(warn error)
330+
TryCopLiteWorker *uint32
330331
}
331332

332333
// ReqTypes.

0 commit comments

Comments
 (0)