-
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
session, tikv: allocate task IDs for distsql requests #16520
Changes from all commits
2d98e9c
8a993a6
70d3ea1
728b663
57b2050
016ac01
208e07d
7aa0614
7765e2a
b15a326
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
"sort" | ||
"strconv" | ||
"sync" | ||
"sync/atomic" | ||
"time" | ||
|
||
"github.com/pingcap/parser" | ||
|
@@ -38,6 +39,13 @@ const ( | |
WarnLevelNote = "Note" | ||
) | ||
|
||
var taskIDAlloc uint64 | ||
|
||
// AllocateTaskID allocates a new unique ID for a statement execution | ||
func AllocateTaskID() uint64 { | ||
return atomic.AddUint64(&taskIDAlloc, 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a chance that different tidb-server use the same task ID. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TiKV will combine both There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, how about moving this calculation logic into the request sender side? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TiDB's logic is too complicated, I'm not sure if start ts exists when task id is assigned. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use the statement idx, starts from 0 as the task id in the transaction? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original author also suggests to use the ID for tracing. I'm not sure if allocating as statement index will affect the purpose. |
||
} | ||
|
||
// SQLWarn relates a sql warning and it's level. | ||
type SQLWarn struct { | ||
Level string | ||
|
@@ -144,6 +152,7 @@ type StatementContext struct { | |
LockKeysDuration time.Duration | ||
LockKeysCount int32 | ||
TblInfo2UnionScan map[*model.TableInfo]bool | ||
TaskID uint64 // unique ID for an execution of a statement | ||
} | ||
|
||
// StmtHints are SessionVars related sql hints. | ||
|
@@ -465,6 +474,7 @@ func (sc *StatementContext) ResetForRetry() { | |
sc.BaseRowID = 0 | ||
sc.TableIDs = sc.TableIDs[:0] | ||
sc.IndexNames = sc.IndexNames[:0] | ||
sc.TaskID = AllocateTaskID() | ||
} | ||
|
||
// MergeExecDetails merges a single region execution details into self, used to print | ||
|
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.
taskIDAlloc is a server-level variable here.
Can we define it as a session-level variable to reduce the contention on it?