diff --git a/pkg/base/config.go b/pkg/base/config.go index dec64dd60ad8..6c723a3d06d6 100644 --- a/pkg/base/config.go +++ b/pkg/base/config.go @@ -143,6 +143,10 @@ const ( // DefaultDescriptorLeaseRenewalTimeout is the default time // before a lease expires when acquisition to renew the lease begins. DefaultDescriptorLeaseRenewalTimeout = time.Minute + + // DefaultLeaseRenewalCrossValidate is the default setting for if + // we should validate descriptors on lease renewals. + DefaultLeaseRenewalCrossValidate = false ) // DefaultCertsDirectory is the default value for the cert directory flag. diff --git a/pkg/bench/rttanalysis/testdata/benchmark_expectations b/pkg/bench/rttanalysis/testdata/benchmark_expectations index ce8b91c7fe35..f5f127ac4463 100644 --- a/pkg/bench/rttanalysis/testdata/benchmark_expectations +++ b/pkg/bench/rttanalysis/testdata/benchmark_expectations @@ -99,5 +99,5 @@ exp,benchmark 12,Truncate/truncate_2_column_2_rows 1,VirtualTableQueries/select_crdb_internal.invalid_objects_with_1_fk 1,VirtualTableQueries/select_crdb_internal.tables_with_1_fk -11,VirtualTableQueries/virtual_table_cache_with_point_lookups +9,VirtualTableQueries/virtual_table_cache_with_point_lookups 7,VirtualTableQueries/virtual_table_cache_with_schema_change diff --git a/pkg/sql/catalog/lease/storage.go b/pkg/sql/catalog/lease/storage.go index e6063bd7a581..14eec95b42b6 100644 --- a/pkg/sql/catalog/lease/storage.go +++ b/pkg/sql/catalog/lease/storage.go @@ -86,6 +86,14 @@ var LeaseRenewalDuration = settings.RegisterDurationSetting( "controls the default time before a lease expires when acquisition to renew the lease begins", base.DefaultDescriptorLeaseRenewalTimeout) +// LeaseRenewalCrossValidate controls if cross validation should be done during +// lease renewal. +var LeaseRenewalCrossValidate = settings.RegisterBoolSetting( + settings.TenantWritable, + "sql.catalog.descriptor_lease_renewal_cross_validation.enabled", + "controls if cross validation should be done during lease renewal", + base.DefaultLeaseRenewalCrossValidate) + func (s storage) leaseRenewalTimeout() time.Duration { return LeaseRenewalDuration.Get(&s.settings.SV) } @@ -99,6 +107,10 @@ func (s storage) jitteredLeaseDuration() time.Duration { 2*jitterFraction*rand.Float64())) } +func (s storage) crossValidateDuringRenewal() bool { + return LeaseRenewalCrossValidate.Get(&s.settings.SV) +} + // acquire a lease on the most recent version of a descriptor. If the lease // cannot be obtained because the descriptor is in the process of being dropped // or offline (currently only applicable to tables), the error will be of type @@ -148,7 +160,6 @@ func (s storage) acquire( // a monotonically increasing expiration. expiration = minExpiration.Add(int64(time.Millisecond), 0) } - desc, err = s.mustGetDescriptorByID(ctx, txn, id) if err != nil { return err @@ -291,13 +302,17 @@ func (s storage) mustGetDescriptorByID( return nil, err } desc := c.LookupDescriptor(id) + validationLevel := catalog.ValidationLevelSelfOnly + if s.crossValidateDuringRenewal() { + validationLevel = validate.ImmutableRead + } vd := catkv.NewCatalogReaderBackedValidationDereferencer(cr, txn, nil /* dvmpMaybe */) ve := validate.Validate( ctx, s.settings.Version.ActiveVersion(ctx), vd, catalog.ValidationReadTelemetry, - validate.ImmutableRead, + validationLevel, desc, ) if err := ve.CombinedError(); err != nil {