Skip to content

Commit 85b9ea3

Browse files
craig[bot]iskettaneh
andcommitted
Merge #128506
128506: sql: support deadlock_timeout session variable r=iskettaneh a=iskettaneh This commit introduces a new `deadlock_timeout` field to the sql session If set, it will be used as the time to wait on a lock before pushing the lock holder for deadlock detection. If not set, the cluster-wide setting: kv.lock_table.deadlock_detection_push_delay will be used as the timeout. Based on: #127430 Fixes: #116305 Release note (sql change): The deadlock_timeout session variable is now supported. The configuration can be used to specify the time to wait on a lock before pushing the lock holder for deadlock detection. It can be set at session granularity. Co-authored-by: Ibrahim Kettaneh <ibrahim.kettaneh@cockroachlabs.com>
2 parents 99e44fb + 7c42d80 commit 85b9ea3

26 files changed

+240
-4
lines changed

pkg/settings/registry.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ var sqlDefaultSettings = map[InternalKey]struct{}{
259259
"sql.defaults.cost_scans_with_default_col_size.enabled": {},
260260
"sql.defaults.datestyle": {},
261261
"sql.defaults.datestyle.enabled": {},
262+
"sql.defaults.deadlock_timeout": {},
262263
"sql.defaults.default_hash_sharded_index_bucket_count": {},
263264
"sql.defaults.default_int_size": {},
264265
"sql.defaults.disallow_full_table_scans.enabled": {},

pkg/sql/colfetcher/colbatch_direct_scan.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ func NewColBatchDirectScan(
217217
spec.LockingWaitPolicy,
218218
spec.LockingDurability,
219219
flowCtx.EvalCtx.SessionData().LockTimeout,
220+
flowCtx.EvalCtx.SessionData().DeadlockTimeout,
220221
kvFetcherMemAcc,
221222
flowCtx.EvalCtx.TestingKnobs.ForceProductionValues,
222223
spec.FetchSpec.External,

pkg/sql/colfetcher/colbatch_scan.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ func NewColBatchScan(
337337
spec.LockingWaitPolicy,
338338
spec.LockingDurability,
339339
flowCtx.EvalCtx.SessionData().LockTimeout,
340+
flowCtx.EvalCtx.SessionData().DeadlockTimeout,
340341
kvFetcherMemAcc,
341342
flowCtx.EvalCtx.TestingKnobs.ForceProductionValues,
342343
spec.FetchSpec.External,

pkg/sql/colfetcher/index_join.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ func NewColIndexJoin(
576576
spec.LockingWaitPolicy,
577577
spec.LockingDurability,
578578
flowCtx.EvalCtx.SessionData().LockTimeout,
579+
flowCtx.EvalCtx.SessionData().DeadlockTimeout,
579580
kvFetcherMemAcc,
580581
flowCtx.EvalCtx.TestingKnobs.ForceProductionValues,
581582
spec.FetchSpec.External,

pkg/sql/delete_range.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ func (d *deleteRangeNode) startExec(params runParams) error {
121121
b := params.p.txn.NewBatch()
122122
b.Header.MaxSpanRequestKeys = row.TableTruncateChunkSize
123123
b.Header.LockTimeout = params.SessionData().LockTimeout
124+
b.Header.DeadlockTimeout = params.SessionData().DeadlockTimeout
124125
d.deleteSpans(params, b, spans)
125126
log.VEventf(ctx, 2, "fast delete: processing %d spans", len(spans))
126127
if err := params.p.txn.Run(ctx, b); err != nil {
@@ -143,6 +144,7 @@ func (d *deleteRangeNode) startExec(params runParams) error {
143144
// keys to delete in this command are low, so we're made safe.
144145
b := params.p.txn.NewBatch()
145146
b.Header.LockTimeout = params.SessionData().LockTimeout
147+
b.Header.DeadlockTimeout = params.SessionData().DeadlockTimeout
146148
d.deleteSpans(params, b, spans)
147149
log.VEventf(ctx, 2, "fast delete: processing %d spans and committing", len(spans))
148150
if err := params.p.txn.CommitInBatch(ctx, b); err != nil {

pkg/sql/exec_util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,6 +3399,10 @@ func (m *sessionDataMutator) SetLockTimeout(timeout time.Duration) {
33993399
m.data.LockTimeout = timeout
34003400
}
34013401

3402+
func (m *sessionDataMutator) SetDeadlockTimeout(timeout time.Duration) {
3403+
m.data.DeadlockTimeout = timeout
3404+
}
3405+
34023406
func (m *sessionDataMutator) SetIdleInSessionTimeout(timeout time.Duration) {
34033407
m.data.IdleInSessionTimeout = timeout
34043408
}

pkg/sql/explain_bundle.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,8 @@ func (c *stmtEnvCollector) PrintSessionSettings(w io.Writer, sv *settings.Values
866866
maybeAdjustTimeout := func(value string) (string, error) {
867867
switch varName {
868868
case "idle_in_session_timeout", "idle_in_transaction_session_timeout",
869-
"idle_session_timeout", "lock_timeout", "statement_timeout", "transaction_timeout":
869+
"idle_session_timeout", "lock_timeout", "deadlock_timeout",
870+
"statement_timeout", "transaction_timeout":
870871
// Defaults for timeout settings are of the duration type (i.e.
871872
// "0s"), so we'll parse it to extract the number of
872873
// milliseconds (which is what the session variable uses).

pkg/sql/logictest/testdata/logic_test/information_schema

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6097,6 +6097,7 @@ copy_write_pipelining_enabled off
60976097
cost_scans_with_default_col_size off
60986098
database test
60996099
datestyle ISO, MDY
6100+
deadlock_timeout 0
61006101
declare_cursor_statement_timeout_enabled on
61016102
default_int_size 8
61026103
default_table_access_method heap

pkg/sql/logictest/testdata/logic_test/pg_catalog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2830,6 +2830,7 @@ copy_write_pipelining_enabled off N
28302830
cost_scans_with_default_col_size off NULL NULL NULL string
28312831
database test NULL NULL NULL string
28322832
datestyle ISO, MDY NULL NULL NULL string
2833+
deadlock_timeout 0 NULL NULL NULL string
28332834
declare_cursor_statement_timeout_enabled on NULL NULL NULL string
28342835
default_int_size 8 NULL NULL NULL string
28352836
default_table_access_method heap NULL NULL NULL string
@@ -3020,6 +3021,7 @@ copy_write_pipelining_enabled off N
30203021
cost_scans_with_default_col_size off NULL user NULL off off
30213022
database test NULL user NULL · test
30223023
datestyle ISO, MDY NULL user NULL ISO, MDY ISO, MDY
3024+
deadlock_timeout 0 NULL user NULL 0s 0s
30233025
declare_cursor_statement_timeout_enabled on NULL user NULL on on
30243026
default_int_size 8 NULL user NULL 8 8
30253027
default_table_access_method heap NULL user NULL heap heap
@@ -3205,6 +3207,7 @@ cost_scans_with_default_col_size NULL NULL NULL
32053207
crdb_version NULL NULL NULL NULL NULL
32063208
database NULL NULL NULL NULL NULL
32073209
datestyle NULL NULL NULL NULL NULL
3210+
deadlock_timeout NULL NULL NULL NULL NULL
32083211
declare_cursor_statement_timeout_enabled NULL NULL NULL NULL NULL
32093212
default_int_size NULL NULL NULL NULL NULL
32103213
default_table_access_method NULL NULL NULL NULL NULL

pkg/sql/logictest/testdata/logic_test/set

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,22 @@ SHOW lock_timeout
396396
----
397397
0
398398

399+
statement ok
400+
SET deadlock_timeout = '1ms'
401+
402+
query T
403+
SHOW deadlock_timeout
404+
----
405+
1
406+
407+
statement ok
408+
SET deadlock_timeout = 0
409+
410+
query T
411+
SHOW deadlock_timeout
412+
----
413+
0
414+
399415
statement ok
400416
SET idle_in_session_timeout = 10000
401417

0 commit comments

Comments
 (0)