Skip to content

Commit 30c51a1

Browse files
craig[bot]arulajmanifqazijbowensrharding6373
committed
144704: kvserver: refresh ReplicaUnavailableErrors on the leaderlessWatcher r=arulajmani a=arulajmani Previously, we would construct a ReplicaUnavailableError on the LeaderlessWatcher once (using an empty descriptor, which is rather hilarious) and never updated the error. That meant that the returned error wouldn't reflect the current state of the RangeDescriptor, which made it hard to make sense of the shape of the unavailability. This patch fixes the issue by refreshing the cached error on every available -> unavailable state transition in the leaderlessWatcher. Closes #144639 Release note: None 144900: sql: optimize SHOW CREATE TABLE performance with many schema objects r=fqazi a=fqazi Previously, SHOW CREATE TABLE queried the crdb_internal.zones table to extract the zone configuration. This could be slow with a large number of objects because the subquery needed to scan the entirety of crdb_internal.zones, which would do one round-trip per zone config (to fetch descriptors). This patch optimizes crdb_internal.zones to fetch all required descriptors in a single request, instead of performing a round trip for each descriptor. Additionally, this patch adds a new BenchmarkORMQueries test in the rttanalysisccl package, configured for multi-region testing. Fixes: #141827 Release note (bug fix): Improve slow SHOW CREATE TABLE on multi-region databases with large number of objects 144969: go.mod: bump Pebble to c70ddd4f9c9e r=RaduBerinde a=jbowens Changes: * [`c70ddd4f`](cockroachdb/pebble@c70ddd4f) db: test replica removal of snapshot sstable * [`c5327549`](cockroachdb/pebble@c5327549) manifest,record: disambiguate unexpected EOFs * [`57c482fb`](cockroachdb/pebble@57c482fb) db: run score-based compactions before manual compactions * [`7ed6738a`](cockroachdb/pebble@7ed6738a) go.mod: update axisds * [`a7c678d0`](cockroachdb/pebble@a7c678d0) db: avoid use of internal type in ValueSeparationPolicy * [`30569643`](cockroachdb/pebble@30569643) db: export FormatExperimentalValueSeparation * [`c25e82e6`](cockroachdb/pebble@c25e82e6) tool: add blob handle print mode to tools * [`6816ec8c`](cockroachdb/pebble@6816ec8c) manifest: rename AddedTablesByFileNum to AllAddedTables * [`e589e571`](cockroachdb/pebble@e589e571) base: introduce TableNum * [`b99c8d26`](cockroachdb/pebble@b99c8d26) db: add TestLargeKeys * [`aa0446ac`](cockroachdb/pebble@aa0446ac) objstorageprovider: support blob files * [`243d3baf`](cockroachdb/pebble@243d3baf) manifest: remove redundant smallest, largest bounds in TableMetadata * [`decdc6ff`](cockroachdb/pebble@decdc6ff) db: deflake TestCheckpoint * [`6e324c22`](cockroachdb/pebble@6e324c22) db: include blob files in checkpoints * [`0ef24272`](cockroachdb/pebble@0ef24272) db: fix TestCompaction/value_separation merge skew Release note: none. Epic: none. 144987: changefeedccl: max changefeed.resolved_timestamp.granularity to 10s r=andyyang890 a=rharding6373 changefeed.resolved_timestamp.granularity was recently made metamorphic, but is causing test flakiness due to timeouts when it is >10s. This PR reduces the max to 10s. Epic: none Fixes: #144956 Fixes: #144948 Fixes: #144934 Release note: none Co-authored-by: Arul Ajmani <[email protected]> Co-authored-by: Faizan Qazi <[email protected]> Co-authored-by: Jackson Owens <[email protected]> Co-authored-by: rharding6373 <[email protected]>
5 parents 088b66e + f749126 + d9220e9 + 4523f85 + 9defffc commit 30c51a1

File tree

15 files changed

+303
-92
lines changed

15 files changed

+303
-92
lines changed

DEPS.bzl

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,10 +1915,10 @@ def go_deps():
19151915
patches = [
19161916
"@com_github_cockroachdb_cockroach//build/patches:com_github_cockroachdb_pebble.patch",
19171917
],
1918-
sha256 = "177126dda72103d057a70dbe645a344506b9a0f4a88b2d3ace9f5880c3af05db",
1919-
strip_prefix = "github.com/cockroachdb/[email protected]20250417234720-091ed497241b",
1918+
sha256 = "8feaf8e2bf545b0e31247314d9b4f894b13e08aedc9bb425ae27966144e6c234",
1919+
strip_prefix = "github.com/cockroachdb/[email protected]20250423160643-c70ddd4f9c9e",
19201920
urls = [
1921-
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250417234720-091ed497241b.zip",
1921+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250423160643-c70ddd4f9c9e.zip",
19221922
],
19231923
)
19241924
go_repository(
@@ -7986,10 +7986,10 @@ def go_deps():
79867986
name = "com_github_raduberinde_axisds",
79877987
build_file_proto_mode = "disable_global",
79887988
importpath = "github.com/RaduBerinde/axisds",
7989-
sha256 = "53a2821f7d7cc76e91278e457d5f58bc5a856c7968d4170435dac86f2d003a87",
7990-
strip_prefix = "github.com/RaduBerinde/[email protected]20250405232732-ecb85bedf677",
7989+
sha256 = "e943d3ac26630cf9e337483450ad9db7f43b6a0372a79d5a691aad8c3c92f9e3",
7990+
strip_prefix = "github.com/RaduBerinde/[email protected]20250419182453-5135a0650657",
79917991
urls = [
7992-
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/RaduBerinde/axisds/com_github_raduberinde_axisds-v0.0.0-20250405232732-ecb85bedf677.zip",
7992+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/RaduBerinde/axisds/com_github_raduberinde_axisds-v0.0.0-20250419182453-5135a0650657.zip",
79937993
],
79947994
)
79957995
go_repository(
@@ -8002,6 +8002,16 @@ def go_deps():
80028002
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/RaduBerinde/btree/com_github_raduberinde_btree-v1.0.2-0.20250415192849-8beea01764ce.zip",
80038003
],
80048004
)
8005+
go_repository(
8006+
name = "com_github_raduberinde_btreemap",
8007+
build_file_proto_mode = "disable_global",
8008+
importpath = "github.com/RaduBerinde/btreemap",
8009+
sha256 = "81b6e0391c0bceadab0bc56184a7ed25dfe81daaa04916900f66b55f34590f6b",
8010+
strip_prefix = "github.com/RaduBerinde/[email protected]",
8011+
urls = [
8012+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/RaduBerinde/btreemap/com_github_raduberinde_btreemap-v0.0.0-20250419174037-3d62b7205d54.zip",
8013+
],
8014+
)
80058015
go_repository(
80068016
name = "com_github_rcrowley_go_metrics",
80078017
build_file_proto_mode = "disable_global",

build/bazelutil/distdir_files.bzl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ DISTDIR_FILES = {
207207
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/PuerkitoBio/goquery/com_github_puerkitobio_goquery-v1.5.1.zip": "9d5bbc466dc4fac7ad872f69eeb9dcf6ddfd925821c4699226fbdeae117839a2",
208208
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/PuerkitoBio/purell/com_github_puerkitobio_purell-v1.1.1.zip": "59e636760d7f2ab41c2f80c1784b1c73d381d44888d1999228dedd634ddcf5ed",
209209
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/PuerkitoBio/urlesc/com_github_puerkitobio_urlesc-v0.0.0-20170810143723-de5bf2ad4578.zip": "1793124273dd94e7089e95716d40529bcf70b9e87162d60218f68dde4d6aeb9d",
210-
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/RaduBerinde/axisds/com_github_raduberinde_axisds-v0.0.0-20250405232732-ecb85bedf677.zip": "53a2821f7d7cc76e91278e457d5f58bc5a856c7968d4170435dac86f2d003a87",
210+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/RaduBerinde/axisds/com_github_raduberinde_axisds-v0.0.0-20250419182453-5135a0650657.zip": "e943d3ac26630cf9e337483450ad9db7f43b6a0372a79d5a691aad8c3c92f9e3",
211211
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/RaduBerinde/btree/com_github_raduberinde_btree-v1.0.2-0.20250415192849-8beea01764ce.zip": "1c845dc6e77f27888fa66c8521df4d1d30f3ccf6892e8c1ba0aab4db24e717c1",
212+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/RaduBerinde/btreemap/com_github_raduberinde_btreemap-v0.0.0-20250419174037-3d62b7205d54.zip": "81b6e0391c0bceadab0bc56184a7ed25dfe81daaa04916900f66b55f34590f6b",
212213
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/SAP/go-hdb/com_github_sap_go_hdb-v0.14.1.zip": "273de28a254c39e9f24293b864c1d664488e4a5d44d535755a5e5b68ae7eed8d",
213214
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/Shopify/goreferrer/com_github_shopify_goreferrer-v0.0.0-20220729165902-8cddb4f5de06.zip": "280a2f55812e8b475cfd9d467a3b3d5859315788e68592a8fc5d6cedadc0503f",
214215
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/Shopify/logrus-bugsnag/com_github_shopify_logrus_bugsnag-v0.0.0-20171204204709-577dee27f20d.zip": "a4cc3fa4b7b493b36b96ea035caa7afcf7307b0c4efc5e523a46597e171b95ce",
@@ -365,7 +366,7 @@ DISTDIR_FILES = {
365366
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/gostdlib/com_github_cockroachdb_gostdlib-v1.19.0.zip": "c4d516bcfe8c07b6fc09b8a9a07a95065b36c2855627cb3514e40c98f872b69e",
366367
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/logtags/com_github_cockroachdb_logtags-v0.0.0-20241215232642-bb51bb14a506.zip": "920068af09e3846d9ebb4e4a7787ff1dd10f3989c5f940ad861b0f6a9f824f6e",
367368
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/metamorphic/com_github_cockroachdb_metamorphic-v0.0.0-20231108215700-4ba948b56895.zip": "28c8cf42192951b69378cf537be5a9a43f2aeb35542908cc4fe5f689505853ea",
368-
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250417234720-091ed497241b.zip": "177126dda72103d057a70dbe645a344506b9a0f4a88b2d3ace9f5880c3af05db",
369+
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/pebble/com_github_cockroachdb_pebble-v0.0.0-20250423160643-c70ddd4f9c9e.zip": "8feaf8e2bf545b0e31247314d9b4f894b13e08aedc9bb425ae27966144e6c234",
369370
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/redact/com_github_cockroachdb_redact-v1.1.6.zip": "018eccb5fb9ca52d43ec9eaf213539d01c1f2b94e0e822406ebfb2e9321ef6cf",
370371
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/returncheck/com_github_cockroachdb_returncheck-v0.0.0-20200612231554-92cdbca611dd.zip": "ce92ba4352deec995b1f2eecf16eba7f5d51f5aa245a1c362dfe24c83d31f82b",
371372
"https://storage.googleapis.com/cockroach-godeps/gomod/github.com/cockroachdb/stress/com_github_cockroachdb_stress-v0.0.0-20220803192808-1806698b1b7b.zip": "3fda531795c600daf25532a4f98be2a1335cd1e5e182c72789bca79f5f69fcc1",

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ require (
138138
github.com/cockroachdb/go-test-teamcity v0.0.0-20191211140407-cff980ad0a55
139139
github.com/cockroachdb/gostdlib v1.19.0
140140
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506
141-
github.com/cockroachdb/pebble v0.0.0-20250417234720-091ed497241b
141+
github.com/cockroachdb/pebble v0.0.0-20250423160643-c70ddd4f9c9e
142142
github.com/cockroachdb/redact v1.1.6
143143
github.com/cockroachdb/returncheck v0.0.0-20200612231554-92cdbca611dd
144144
github.com/cockroachdb/stress v0.0.0-20220803192808-1806698b1b7b
@@ -289,7 +289,8 @@ require (
289289
github.com/Masterminds/semver v1.5.0 // indirect
290290
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
291291
github.com/Microsoft/go-winio v0.5.2 // indirect
292-
github.com/RaduBerinde/axisds v0.0.0-20250405232732-ecb85bedf677 // indirect
292+
github.com/RaduBerinde/axisds v0.0.0-20250419182453-5135a0650657 // indirect
293+
github.com/RaduBerinde/btreemap v0.0.0-20250419174037-3d62b7205d54 // indirect
293294
github.com/abbot/go-http-auth v0.4.1-0.20181019201920-860ed7f246ff // indirect
294295
github.com/aclements/go-moremath v0.0.0-20210112150236-f10218a38794 // indirect
295296
github.com/ajstarks/svgo v0.0.0-20211024235047-1546f124cd8b // indirect

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,12 @@ github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
266266
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
267267
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
268268
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
269-
github.com/RaduBerinde/axisds v0.0.0-20250405232732-ecb85bedf677 h1:NofOMIO/Z3301wDc9gIM/M0/+YjvOYSvUe7+30bkxkA=
270-
github.com/RaduBerinde/axisds v0.0.0-20250405232732-ecb85bedf677/go.mod h1:YO26VdZg1RVVjEhjmeEJE/4bLnD2mowj5eDiZQSLtlE=
269+
github.com/RaduBerinde/axisds v0.0.0-20250419182453-5135a0650657 h1:8XBWWQD+vFF+JqOsm16t0Kab1a7YWV8+GISVEP8AuZ8=
270+
github.com/RaduBerinde/axisds v0.0.0-20250419182453-5135a0650657/go.mod h1:UHGJonU9z4YYGKJxSaC6/TNcLOBptpmM5m2Cksbnw0Y=
271271
github.com/RaduBerinde/btree v1.0.2-0.20250415192849-8beea01764ce h1:jmg1o6EkSTLFQ4vdTBzob5AjFBzNH4ELn56iKhMVk48=
272272
github.com/RaduBerinde/btree v1.0.2-0.20250415192849-8beea01764ce/go.mod h1:1+GykKoq3bIUWDVjNWWxWYblBduYahx5NGepZjgYqvI=
273+
github.com/RaduBerinde/btreemap v0.0.0-20250419174037-3d62b7205d54 h1:bsU8Tzxr/PNz75ayvCnxKZWEYdLMPDkUgticP4a4Bvk=
274+
github.com/RaduBerinde/btreemap v0.0.0-20250419174037-3d62b7205d54/go.mod h1:0tr7FllbE9gJkHq7CVeeDDFAFKQVy5RnCSSNBOvdqbc=
273275
github.com/SAP/go-hdb v0.14.1/go.mod h1:7fdQLVC2lER3urZLjZCm0AuMQfApof92n3aylBPEkMo=
274276
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
275277
github.com/Shopify/logrus-bugsnag v0.0.0-20171204204709-577dee27f20d/go.mod h1:HI8ITrYtUY+O+ZhtlqUnD8+KwNPOyugEhfP9fdUIaEQ=
@@ -593,8 +595,8 @@ github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506 h1:ASDL+UJcILM
593595
github.com/cockroachdb/logtags v0.0.0-20241215232642-bb51bb14a506/go.mod h1:Mw7HqKr2kdtu6aYGn3tPmAftiP3QPX63LdK/zcariIo=
594596
github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895 h1:XANOgPYtvELQ/h4IrmPAohXqe2pWA8Bwhejr3VQoZsA=
595597
github.com/cockroachdb/metamorphic v0.0.0-20231108215700-4ba948b56895/go.mod h1:aPd7gM9ov9M8v32Yy5NJrDyOcD8z642dqs+F0CeNXfA=
596-
github.com/cockroachdb/pebble v0.0.0-20250417234720-091ed497241b h1:x0mDX6DRVJphx9xkup4N00L6nDn6K+cSOIUXKvbmeSI=
597-
github.com/cockroachdb/pebble v0.0.0-20250417234720-091ed497241b/go.mod h1:ONMS0WzY11hEvOyO3Cl6fyfaDduyiz42cYeQAcqHRNQ=
598+
github.com/cockroachdb/pebble v0.0.0-20250423160643-c70ddd4f9c9e h1:zG2jqS8AgpMbLThyQm3HrKs/yaLV8CORKLn0N4hoGxA=
599+
github.com/cockroachdb/pebble v0.0.0-20250423160643-c70ddd4f9c9e/go.mod h1:jyGqUZ9jl6TVX9HHi12f0JQ+h+oL75De//O43X898BA=
598600
github.com/cockroachdb/redact v1.1.3/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=
599601
github.com/cockroachdb/redact v1.1.6 h1:zXJBwDZ84xJNlHl1rMyCojqyIxv+7YUpQiJLQ7n4314=
600602
github.com/cockroachdb/redact v1.1.6/go.mod h1:BVNblN9mBWFyMyqK1k3AAiSxhvhfK2oOZZ2lK+dpvRg=

pkg/ccl/benchccl/rttanalysisccl/multi_region_bench_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ package rttanalysisccl
77

88
import (
99
gosql "database/sql"
10+
"fmt"
1011
"net/url"
12+
"strings"
1113
"testing"
1214

1315
"github.com/cockroachdb/cockroach/pkg/base"
@@ -69,6 +71,37 @@ CREATE TABLE test42 (p int) LOCALITY REGIONAL BY TABLE IN "us-east2";
6971
`
7072
)
7173

74+
// multipleTableFixtures creates multiple tables with different localities.
75+
func multipleTableFixtures(n int) string {
76+
b := strings.Builder{}
77+
78+
b.WriteString(`CREATE DATABASE test PRIMARY REGION "us-east1" REGIONS "us-east1", "us-east2", "us-east3";
79+
USE test;`)
80+
b.WriteString("BEGIN;\n")
81+
b.WriteString("SET LOCAL autocommit_before_ddl = false;\n")
82+
for i := 0; i < n; i++ {
83+
b.WriteString(fmt.Sprintf("CREATE TABLE test%d (p int)", i))
84+
85+
locality := i % 5
86+
87+
switch locality {
88+
case 0:
89+
b.WriteString(" LOCALITY GLOBAL")
90+
case 1:
91+
b.WriteString(" LOCALITY REGIONAL BY ROW")
92+
case 2:
93+
b.WriteString(" LOCALITY REGIONAL BY TABLE IN \"us-east1\"")
94+
case 3:
95+
b.WriteString(" LOCALITY REGIONAL BY TABLE IN \"us-east2\"")
96+
case 4:
97+
b.WriteString(" LOCALITY REGIONAL BY TABLE IN \"us-east3\"")
98+
}
99+
b.WriteString(";\n")
100+
}
101+
b.WriteString("COMMIT;\n")
102+
return b.String()
103+
}
104+
72105
func BenchmarkAlterRegions(b *testing.B) { reg.Run(b) }
73106
func init() {
74107
reg.Register("AlterRegions", []rttanalysis.RoundTripBenchTestCase{
@@ -238,3 +271,28 @@ CREATE TABLE test (p int) LOCALITY REGIONAL BY ROW;
238271
},
239272
})
240273
}
274+
275+
func BenchmarkVirtualTableQueries(b *testing.B) { reg.Run(b) }
276+
func init() {
277+
reg.Register("VirtualTableQueries", []rttanalysis.RoundTripBenchTestCase{
278+
{
279+
Name: "select from crdb_internal.zones (10 tables)",
280+
Setup: multipleTableFixtures(10),
281+
Stmt: `select * from crdb_internal.zones`,
282+
Reset: "DROP DATABASE test",
283+
},
284+
{
285+
Name: "select from crdb_internal.zones (50 tables)",
286+
Setup: multipleTableFixtures(50),
287+
Stmt: `select * from crdb_internal.zones`,
288+
Reset: "DROP DATABASE test",
289+
},
290+
291+
{
292+
Name: "select from crdb_internal.zones (100 tables)",
293+
Setup: multipleTableFixtures(100),
294+
Stmt: `select * from crdb_internal.zones`,
295+
Reset: "DROP DATABASE test",
296+
},
297+
})
298+
}

pkg/ccl/benchccl/rttanalysisccl/testdata/benchmark_expectations

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ exp,benchmark
1717
10,AlterTableLocality/alter_from_rbr_to_regional_by_table
1818
13,AlterTableLocality/alter_from_regional_by_table_to_global
1919
18,AlterTableLocality/alter_from_regional_by_table_to_rbr
20+
10,VirtualTableQueries/select_from_crdb_internal.zones_(100_tables)
21+
10,VirtualTableQueries/select_from_crdb_internal.zones_(10_tables)
22+
10,VirtualTableQueries/select_from_crdb_internal.zones_(50_tables)

pkg/ccl/changefeedccl/changefeedbase/settings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,5 +346,5 @@ var Quantize = settings.RegisterDurationSettingWithExplicitUnit(
346346
settings.ApplicationLevel,
347347
"changefeed.resolved_timestamp.granularity",
348348
"the granularity at which changefeed progress is quantized to make tracking more efficient",
349-
time.Duration(metamorphic.ConstantWithTestRange("changefeed.resolved_timestamp.granularity", 0, 0, 20))*time.Second,
349+
time.Duration(metamorphic.ConstantWithTestRange("changefeed.resolved_timestamp.granularity", 0, 0, 10))*time.Second,
350350
)

pkg/kv/kvserver/client_replica_test.go

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import (
6868
"github.com/cockroachdb/cockroach/pkg/util/log"
6969
"github.com/cockroachdb/cockroach/pkg/util/randutil"
7070
"github.com/cockroachdb/cockroach/pkg/util/retry"
71+
"github.com/cockroachdb/cockroach/pkg/util/stop"
7172
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
7273
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
7374
"github.com/cockroachdb/cockroach/pkg/util/tracing"
@@ -2788,7 +2789,6 @@ func TestLossQuorumCauseLeaderWatcherToSignalUnavailable(t *testing.T) {
27882789
require.NoError(t, log.SetVModule("replica_range_lease=3,raft=4"))
27892790

27902791
ctx := context.Background()
2791-
manualClock := hlc.NewHybridManualClock()
27922792
stickyVFSRegistry := fs.NewStickyRegistry()
27932793
lisReg := listenerutil.NewListenerRegistry()
27942794
defer lisReg.Close()
@@ -2851,12 +2851,8 @@ func TestLossQuorumCauseLeaderWatcherToSignalUnavailable(t *testing.T) {
28512851
return nil
28522852
})
28532853

2854-
// Increment the clock by the leaderlessWatcher unavailable threshold.
2855-
manualClock.Increment(threshold.Nanoseconds())
2856-
28572854
// Wait for the leaderlessWatcher to indicate that the range is unavailable.
28582855
testutils.SucceedsSoon(t, func() error {
2859-
tc.GetFirstStoreFromServer(t, aliveNodeIdx).LookupReplica(roachpb.RKey(key))
28602856
if !repl.LeaderlessWatcher.IsUnavailable() {
28612857
return errors.New("range is still available")
28622858
}
@@ -2915,6 +2911,77 @@ func TestLossQuorumCauseLeaderWatcherToSignalUnavailable(t *testing.T) {
29152911
})
29162912
}
29172913

2914+
// TestLeaderlessWatcherUnavailabilityErrorRefreshedOnUnavailabilityTransition
2915+
// ensures that the leaderless watcher constructs a new error every time it
2916+
// transitions to the unavailable state. In particular, the descriptor used
2917+
// in the error should be the latest descriptor.
2918+
// Serves as a regression test for
2919+
// https://github.com/cockroachdb/cockroach/issues/144639.
2920+
func TestLeaderlessWatcherErrorRefreshedOnUnavailabilityTransition(t *testing.T) {
2921+
defer leaktest.AfterTest(t)()
2922+
defer log.Scope(t).Close(t)
2923+
ctx := context.Background()
2924+
stopper := stop.NewStopper()
2925+
defer stopper.Stop(ctx)
2926+
2927+
manual := hlc.NewHybridManualClock()
2928+
st := cluster.MakeTestingClusterSettings()
2929+
// Set the leaderless threshold to 10 second.
2930+
kvserver.ReplicaLeaderlessUnavailableThreshold.Override(ctx, &st.SV, 10*time.Second)
2931+
2932+
tc := testcluster.StartTestCluster(t, 3, base.TestClusterArgs{
2933+
ReplicationMode: base.ReplicationManual,
2934+
ServerArgs: base.TestServerArgs{
2935+
Settings: st,
2936+
Knobs: base.TestingKnobs{
2937+
Server: &server.TestingKnobs{
2938+
WallClock: manual,
2939+
},
2940+
},
2941+
},
2942+
})
2943+
defer tc.Stopper().Stop(ctx)
2944+
key := tc.ScratchRange(t)
2945+
tc.AddVotersOrFatal(t, key, tc.Targets(1)...)
2946+
repl := tc.GetFirstStoreFromServer(t, 1).LookupReplica(roachpb.RKey(key))
2947+
2948+
// The leaderlessWatcher starts off as available.
2949+
require.False(t, repl.LeaderlessWatcher.IsUnavailable())
2950+
// Let it know it's leaderless.
2951+
repl.RefreshLeaderlessWatcherUnavailableStateForTesting(ctx, raft.None, manual.Now(), st)
2952+
// Even though the replica is leaderless, enough time hasn't passed for it to
2953+
// be considered unavailable.
2954+
require.False(t, repl.LeaderlessWatcher.IsUnavailable())
2955+
// The error should be nil as we're not considered leaderless at this point.
2956+
require.NoError(t, repl.LeaderlessWatcher.Err())
2957+
// Let enough time pass.
2958+
manual.Increment(10 * time.Second.Nanoseconds())
2959+
repl.RefreshLeaderlessWatcherUnavailableStateForTesting(ctx, raft.None, manual.Now(), st)
2960+
// Now the replica is considered unavailable.
2961+
require.True(t, repl.LeaderlessWatcher.IsUnavailable())
2962+
require.Error(t, repl.LeaderlessWatcher.Err())
2963+
// Regex to ensure we've got a replica unavailable error with n1 and n2 in the
2964+
// range descriptor.
2965+
require.Regexp(t, "replica unavailable.*n1.*n2.*gen=3", repl.LeaderlessWatcher.Err().Error())
2966+
2967+
// Next up, let the replica know there's a leader. This should make it
2968+
// available again.
2969+
repl.RefreshLeaderlessWatcherUnavailableStateForTesting(ctx, 1, manual.Now(), st)
2970+
require.False(t, repl.LeaderlessWatcher.IsUnavailable())
2971+
// Change the range descriptor. Mark it leaderless and let enough time pass
2972+
// for it to be considered unavailable again.
2973+
tc.AddVotersOrFatal(t, key, tc.Targets(2)...)
2974+
repl.RefreshLeaderlessWatcherUnavailableStateForTesting(ctx, raft.None, manual.Now(), st)
2975+
manual.Increment(10 * time.Second.Nanoseconds())
2976+
repl.RefreshLeaderlessWatcherUnavailableStateForTesting(ctx, raft.None, manual.Now(), st)
2977+
// The replica should now be considered unavailable again.
2978+
require.True(t, repl.LeaderlessWatcher.IsUnavailable())
2979+
require.Error(t, repl.LeaderlessWatcher.Err())
2980+
// Ensure that the range descriptor now contains n1, n2, and n3 -- i.e, we're
2981+
// updating the error with the latest descriptor on the latest transition.
2982+
require.Regexp(t, "replica unavailable.*n1.*n2.*n3.*gen=5", repl.LeaderlessWatcher.Err().Error())
2983+
}
2984+
29182985
func TestClearRange(t *testing.T) {
29192986
defer leaktest.AfterTest(t)()
29202987
defer log.Scope(t).Close(t)

0 commit comments

Comments
 (0)