Skip to content

Commit 73c10e8

Browse files
craig[bot]fqaziyuzefovichbghal
committed
156403: catalog/lease: fix queries against initial versions in locked mode r=fqazi a=fqazi Previously, all of our testing for locked timestamping included WaitForInitialVersion being enabled. This configuration ensured that we would always acquire the first version of leased descriptors in our tests. However, upon enabling locked leasing across the binary, we encountered issues because bootstrapped tables and other tests might not secure the initial version checkout. Consequently, we would incorrectly declare the object as non-existent if the lease timestamp precoded the object's creation. Fixes: #156401 Release note: None 156410: *: address a couple of nits r=yuzefovich a=yuzefovich We can use `settings.Fraction` for non-negative float with max 1.0. Also fix up one comment. (Noticed this while reviewing the probabilistic transaction tracing backport.) Epic: None Release note: None 156468: sql: increase timeout for inspect tests r=bghal a=bghal The `sql/inspect.TestInspectMetrics` test was flaking in CI. Increasing the size will increase the timeout. Epic: none Fixes: #156197 Fixes: #156082 Fixes: #156238 Release note: None Co-authored-by: Faizan Qazi <faizan@cockroachlabs.com> Co-authored-by: Yahor Yuzefovich <yahor@cockroachlabs.com> Co-authored-by: Brendan Gerrity <brendan.gerrity@cockroachlabs.com>
4 parents 78edad0 + b76e68c + c9554bb + 394c043 commit 73c10e8

File tree

8 files changed

+36
-6
lines changed

8 files changed

+36
-6
lines changed

pkg/crosscluster/settings.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ var ReplanThreshold = settings.RegisterFloatSetting(
5959
"fraction of nodes in the producer or consumer job that would need to change to refresh the"+
6060
" physical execution plan. If set to 0, the physical plan will not automatically refresh.",
6161
0.1,
62-
settings.NonNegativeFloatWithMaximum(1),
62+
settings.Fraction,
6363
settings.WithName("physical_replication.consumer.replan_flow_threshold"),
6464
)
6565

@@ -116,7 +116,7 @@ var LogicalReplanThreshold = settings.RegisterFloatSetting(
116116
"fraction of nodes in the producer or consumer job that would need to change to refresh the"+
117117
" physical execution plan. If set to 0, the physical plan will not automatically refresh.",
118118
0.1,
119-
settings.NonNegativeFloatWithMaximum(1),
119+
settings.Fraction,
120120
)
121121

122122
var LogicalReplanFrequency = settings.RegisterDurationSetting(

pkg/sql/catalog/lease/descriptor_set.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ func (l *descriptorSet) findIndex(version descpb.DescriptorVersion) (int, bool)
8484
return i, false
8585
}
8686

87+
func (l *descriptorSet) findOldest() *descriptorVersionState {
88+
if len(l.data) == 0 {
89+
return nil
90+
}
91+
return l.data[0]
92+
}
93+
8794
func (l *descriptorSet) findNewest() *descriptorVersionState {
8895
if len(l.data) == 0 {
8996
return nil

pkg/sql/catalog/lease/descriptor_state.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ func (t *descriptorState) findForTimestampImpl(
105105
readTimestamp hlc.Timestamp,
106106
expensiveLogEnabled bool,
107107
) (*descriptorVersionState, bool, error) {
108+
// Normally this is true if an older timestamp is intentionally used for
109+
// locked leasing.
110+
hasDifferentReadTimeStamp := leaseTimestamp != readTimestamp
108111
// Walk back the versions to find one that is valid for the timestamp.
109112
for i := len(t.mu.active.data) - 1; i >= 0; i-- {
110113
// Check to see if the ModificationTime is valid. If only the initial version
@@ -115,7 +118,7 @@ func (t *descriptorState) findForTimestampImpl(
115118
// Existing valid descriptor version.
116119
desc.incRefCount(ctx, expensiveLogEnabled)
117120
return desc, latest, nil
118-
} else if !latest && readTimestamp != leaseTimestamp {
121+
} else if !latest && hasDifferentReadTimeStamp {
119122
// The lease timestamp is not compatible with the read timestamp, since
120123
// the descriptor returned will be expired. This means we are seeing the
121124
// first read of this descriptor, since the prior version was not locked.
@@ -133,6 +136,16 @@ func (t *descriptorState) findForTimestampImpl(
133136
}
134137
}
135138

139+
// If we have the initial version of the descriptor, and it satisfies the read
140+
// timestamp, then the object was just created. We can confirm it satisfies
141+
// the request, by executing findForTimestampImpl with the readTimestamp instead.
142+
if oldest := t.mu.active.findOldest(); hasDifferentReadTimeStamp &&
143+
oldest != nil &&
144+
oldest.GetVersion() == 1 &&
145+
oldest.GetModificationTime().LessEq(readTimestamp) {
146+
return t.findForTimestampImpl(ctx, readTimestamp, readTimestamp, expensiveLogEnabled)
147+
}
148+
136149
return nil, false, errReadOlderVersion
137150
}
138151

pkg/sql/catalog/lease/lease_internal_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,10 @@ func TestLeaseManagerLockedTimestampBasic(t *testing.T) {
17471747
st := cluster.MakeTestingClusterSettings()
17481748
ctx := context.Background()
17491749
LockedLeaseTimestamp.Override(ctx, &st.SV, true)
1750+
// Intentionally disable WaitForInitialVersion support, so that we can run
1751+
// historical queries at timestamps before the lease manager is fully caught
1752+
// up.
1753+
WaitForInitialVersion.Override(ctx, &st.SV, false)
17501754
srv, db, _ := serverutils.StartServer(
17511755
t, base.TestServerArgs{
17521756
// Avoid using tenants since async tenant migration steps can acquire
@@ -1770,6 +1774,11 @@ func TestLeaseManagerLockedTimestampBasic(t *testing.T) {
17701774
r := sqlutils.MakeSQLRunner(db)
17711775

17721776
r.Exec(t, "CREATE TABLE t1(n int)")
1777+
// These queries will be intentionally executed before the lease manager is
1778+
// fully aware of their existence, since WaitForInitialVersion support is
1779+
// disabled. We should be forced to use a non-locked timestamp to be aware
1780+
// of the tables existence.
1781+
r.Exec(t, "SELECT * FROM t1")
17731782
r.Exec(t, "INSERT INTO t1 VALUES (1)")
17741783

17751784
grp := ctxgroup.WithContext(context.Background())

pkg/sql/exec_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ var TraceTxnSampleRate = settings.RegisterFloatSetting(
293293
"will have tracing enabled, and only those which exceed the configured "+
294294
"threshold will be logged.",
295295
1.0,
296-
settings.NonNegativeFloatWithMaximum(1.0),
296+
settings.Fraction,
297297
settings.WithPublic)
298298

299299
// TraceTxnOutputJaegerJSON sets the output format of transaction trace logs.

pkg/sql/inspect/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ go_library(
6868

6969
go_test(
7070
name = "inspect_test",
71+
size = "large",
7172
srcs = [
7273
"index_consistency_check_test.go",
7374
"inspect_job_test.go",

pkg/sql/stats/histogram.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ var MaxFractionHistogramMCVs = settings.RegisterFloatSetting(
6363
"sql.stats.histogram_buckets.max_fraction_most_common_values",
6464
"maximum fraction of histogram buckets to use for most common values",
6565
0.1,
66-
settings.NonNegativeFloatWithMaximum(1),
66+
settings.Fraction,
6767
settings.WithPublic)
6868

6969
// HistogramVersion identifies histogram versions.

pkg/util/log/logtestutils/log_spy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (s *LogSpy) Reset() {
8686
s.mu.logs = []logpb.Entry{}
8787
}
8888

89-
// ReadAll consumes the specified number of logs contained within
89+
// Read consumes the specified number of logs contained within
9090
// the spy and returns them as a list. Once the logs are consumed
9191
// they cannot be read again.
9292
func (s *LogSpy) Read(n int) []logpb.Entry {

0 commit comments

Comments
 (0)