-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
*: add statistic lock/unlock function #38387
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// Copyright 2018 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package executor | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/pingcap/errors" | ||
"github.com/pingcap/tidb/domain" | ||
"github.com/pingcap/tidb/parser/ast" | ||
"github.com/pingcap/tidb/util/chunk" | ||
) | ||
|
||
var _ Executor = &LockStatsExec{} | ||
var _ Executor = &UnlockStatsExec{} | ||
|
||
// LockStatsExec represents a lock statistic executor. | ||
type LockStatsExec struct { | ||
baseExecutor | ||
Tables []*ast.TableName | ||
} | ||
|
||
// lockStatsVarKeyType is a dummy type to avoid naming collision in context. | ||
type lockStatsVarKeyType int | ||
|
||
// String defines a Stringer function for debugging and pretty printing. | ||
func (k lockStatsVarKeyType) String() string { | ||
return "lock_stats_var" | ||
} | ||
|
||
// LockStatsVarKey is a variable key for lock statistic. | ||
const LockStatsVarKey lockStatsVarKeyType = 0 | ||
|
||
// Next implements the Executor Next interface. | ||
func (e *LockStatsExec) Next(ctx context.Context, req *chunk.Chunk) error { | ||
do := domain.GetDomain(e.ctx) | ||
is := do.InfoSchema() | ||
h := do.StatsHandle() | ||
if h == nil { | ||
return errors.New("Lock Stats: handle is nil") | ||
} | ||
|
||
tableNum := len(e.Tables) | ||
if tableNum == 0 { | ||
return errors.New("Lock Stats: table should not empty ") | ||
} | ||
|
||
tids := make([]int64, 0, len(e.Tables)) | ||
pids := make([]int64, 0) | ||
for _, table := range e.Tables { | ||
tbl, err := is.TableByName(table.Schema, table.Name) | ||
if err != nil { | ||
return err | ||
} | ||
tids = append(tids, tbl.Meta().ID) | ||
|
||
pi := tbl.Meta().GetPartitionInfo() | ||
if pi == nil { | ||
continue | ||
} | ||
for _, p := range pi.Definitions { | ||
pids = append(pids, p.ID) | ||
} | ||
} | ||
msg, err := h.AddLockedTables(tids, pids, e.Tables) | ||
if msg != "" { | ||
e.ctx.GetSessionVars().StmtCtx.AppendWarning(errors.New(msg)) | ||
} | ||
return err | ||
} | ||
|
||
// Close implements the Executor Close interface. | ||
func (e *LockStatsExec) Close() error { | ||
return nil | ||
} | ||
|
||
// Open implements the Executor Open interface. | ||
func (e *LockStatsExec) Open(ctx context.Context) error { | ||
return nil | ||
} | ||
|
||
// UnlockStatsExec represents a unlock statistic executor. | ||
type UnlockStatsExec struct { | ||
baseExecutor | ||
Tables []*ast.TableName | ||
} | ||
|
||
// unlockStatsVarKeyType is a dummy type to avoid naming collision in context. | ||
type unlockStatsVarKeyType int | ||
|
||
// String defines a Stringer function for debugging and pretty printing. | ||
func (k unlockStatsVarKeyType) String() string { | ||
return "unlock_stats_var" | ||
} | ||
|
||
// UnlockStatsVarKey is a variable key for unlock statistic. | ||
const UnlockStatsVarKey unlockStatsVarKeyType = 0 | ||
|
||
// Next implements the Executor Next interface. | ||
func (e *UnlockStatsExec) Next(ctx context.Context, req *chunk.Chunk) error { | ||
do := domain.GetDomain(e.ctx) | ||
is := do.InfoSchema() | ||
h := do.StatsHandle() | ||
if h == nil { | ||
return errors.New("Unlock Stats: handle is nil") | ||
} | ||
|
||
tableNum := len(e.Tables) | ||
if tableNum == 0 { | ||
return errors.New("Unlock Stats: table should not empty ") | ||
} | ||
|
||
tids := make([]int64, 0, len(e.Tables)) | ||
pids := make([]int64, 0) | ||
for _, table := range e.Tables { | ||
tbl, err := is.TableByName(table.Schema, table.Name) | ||
if err != nil { | ||
return err | ||
} | ||
tids = append(tids, tbl.Meta().ID) | ||
|
||
pi := tbl.Meta().GetPartitionInfo() | ||
if pi == nil { | ||
continue | ||
} | ||
for _, p := range pi.Definitions { | ||
pids = append(pids, p.ID) | ||
} | ||
} | ||
msg, err := h.RemoveLockedTables(tids, pids, e.Tables) | ||
if msg != "" { | ||
e.ctx.GetSessionVars().StmtCtx.AppendWarning(errors.New(msg)) | ||
} | ||
return err | ||
} | ||
|
||
// Close implements the Executor Close interface. | ||
func (e *UnlockStatsExec) Close() error { | ||
return nil | ||
} | ||
|
||
// Open implements the Executor Open interface. | ||
func (e *UnlockStatsExec) Open(ctx context.Context) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use warnings to remind users that the table is locked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. Add it.