@@ -1260,18 +1260,6 @@ func (s *Server) newConnExecutor(
1260
1260
1261
1261
ex .extraTxnState .hasAdminRoleCache = HasAdminRoleCache {}
1262
1262
1263
- if lm := ex .server .cfg .LeaseManager ; executorType == executorTypeExec && lm != nil {
1264
- if desc , err := lm .Acquire (ctx , ex .server .cfg .Clock .Now (), keys .SystemDatabaseID ); err != nil {
1265
- log .Infof (ctx , "unable to lease system database to determine if PCR reader is in use: %s" , err )
1266
- } else {
1267
- defer desc .Release (ctx )
1268
- // The system database ReplicatedPCRVersion is set during reader tenant bootstrap,
1269
- // which guarantees that all user tenant sql connections to the reader tenant will
1270
- // correctly set this
1271
- ex .isPCRReaderCatalog = desc .Underlying ().(catalog.DatabaseDescriptor ).GetReplicatedPCRVersion () != 0
1272
- }
1273
- }
1274
-
1275
1263
if postSetupFn != nil {
1276
1264
postSetupFn (ex )
1277
1265
}
@@ -1875,6 +1863,10 @@ type connExecutor struct {
1875
1863
// PCR reader catalog, which is done by checking for the ReplicatedPCRVersion
1876
1864
// field on the system database (which is set during tenant bootstrap).
1877
1865
isPCRReaderCatalog bool
1866
+
1867
+ // isPCRReaderCatalogInit tracks if the system database has been queried
1868
+ // once for this connect to determine if this tenant is a reader catalog.
1869
+ isPCRReaderCatalogInit bool
1878
1870
}
1879
1871
1880
1872
// ctxHolder contains a connection's context and, while session tracing is
@@ -3839,10 +3831,43 @@ func (ex *connExecutor) initEvalCtx(ctx context.Context, evalCtx *extendedEvalCo
3839
3831
evalCtx .copyFromExecCfg (ex .server .cfg )
3840
3832
}
3841
3833
3834
+ // maybeInitPCRReaderCatalog leases the system database to determine if
3835
+ // we are connecting to a PCR reader catalog, if this has not been attempted
3836
+ // before.
3837
+ func (ex * connExecutor ) maybeInitPCRReaderCatalog (ctx context.Context ) {
3838
+ if ex .isPCRReaderCatalogInit {
3839
+ return
3840
+ }
3841
+ // Wait up to 30 seconds attempting to acquire the lease on the system
3842
+ // database. Normally we should already have a lease on this object,
3843
+ // unless there is some availability issue.
3844
+ const initPCRReaderCatalogTimeout = 30 * time .Second
3845
+ err := timeutil .RunWithTimeout (ctx , "detect-pcr-reader-catalog" , initPCRReaderCatalogTimeout ,
3846
+ func (ctx context.Context ) error {
3847
+ if lm := ex .server .cfg .LeaseManager ; ex .executorType == executorTypeExec && lm != nil {
3848
+ desc , err := lm .Acquire (ctx , ex .server .cfg .Clock .Now (), keys .SystemDatabaseID )
3849
+ if err != nil {
3850
+ return err
3851
+ }
3852
+ defer desc .Release (ctx )
3853
+ // The system database ReplicatedPCRVersion is set during reader tenant bootstrap,
3854
+ // which guarantees that all user tenant sql connections to the reader tenant will
3855
+ // correctly set this
3856
+ ex .isPCRReaderCatalog = desc .Underlying ().(catalog.DatabaseDescriptor ).GetReplicatedPCRVersion () != 0
3857
+ }
3858
+ return nil
3859
+ })
3860
+ if err != nil {
3861
+ log .Infof (ctx , "unable to lease system database to determine if PCR reader is in use: %s" , err )
3862
+ }
3863
+ ex .isPCRReaderCatalogInit = true
3864
+ }
3865
+
3842
3866
// GetPCRReaderTimestamp if the system database is setup as PCR
3843
3867
// catalog reader, then this function will return an non-zero timestamp
3844
3868
// to use for all read operations.
3845
3869
func (ex * connExecutor ) GetPCRReaderTimestamp () hlc.Timestamp {
3870
+ ex .maybeInitPCRReaderCatalog (ex .Ctx ())
3846
3871
if ex .isPCRReaderCatalog && ! ex .sessionData ().BypassPCRReaderCatalogAOST {
3847
3872
return ex .server .cfg .LeaseManager .GetSafeReplicationTS ()
3848
3873
}
0 commit comments