9
9
"context"
10
10
"testing"
11
11
12
+ "github.com/cockroachdb/cockroach/pkg/base"
12
13
"github.com/cockroachdb/cockroach/pkg/config"
13
14
"github.com/cockroachdb/cockroach/pkg/config/zonepb"
14
15
"github.com/cockroachdb/cockroach/pkg/keys"
@@ -36,12 +37,14 @@ import (
36
37
)
37
38
38
39
var configID = descpb .ID (1 )
39
- var configDescKey = catalogkeys .MakeDescMetadataKey (keys .SystemSQLCodec , descpb .ID (bootstrap .TestingUserDescID (0 )))
40
40
41
41
// forceNewConfig forces a system config update by writing a bogus descriptor with an
42
42
// incremented value inside. It then repeatedly fetches the gossip config until the
43
43
// just-written descriptor is found.
44
44
func forceNewConfig (t testing.TB , s serverutils.TestServerInterface ) * config.SystemConfig {
45
+ var configDescKey = catalogkeys .MakeDescMetadataKey (
46
+ s .Codec (), descpb .ID (bootstrap .TestingUserDescID (0 )))
47
+
45
48
configID ++
46
49
configDesc := & descpb.Descriptor {
47
50
Union : & descpb.Descriptor_Database {
@@ -59,15 +62,12 @@ func forceNewConfig(t testing.TB, s serverutils.TestServerInterface) *config.Sys
59
62
}); err != nil {
60
63
t .Fatal (err )
61
64
}
62
- return waitForConfigChange (t , s )
63
- }
64
65
65
- func waitForConfigChange (t testing.TB , s serverutils.TestServerInterface ) * config.SystemConfig {
66
- var foundDesc descpb.Descriptor
67
66
var cfg * config.SystemConfig
68
67
testutils .SucceedsSoon (t , func () error {
69
- if cfg = s .SystemConfigProvider ().GetSystemConfig (); cfg != nil {
68
+ if cfg = s .ApplicationLayer (). SystemConfigProvider ().GetSystemConfig (); cfg != nil {
70
69
if val := cfg .GetValue (configDescKey ); val != nil {
70
+ var foundDesc descpb.Descriptor
71
71
if err := val .GetProto (& foundDesc ); err != nil {
72
72
t .Fatal (err )
73
73
}
@@ -86,7 +86,7 @@ func waitForConfigChange(t testing.TB, s serverutils.TestServerInterface) *confi
86
86
func TestGetZoneConfig (t * testing.T ) {
87
87
defer leaktest .AfterTest (t )()
88
88
defer log .Scope (t ).Close (t )
89
- params , _ := createTestServerParams ()
89
+ params , _ := createTestServerParamsAllowTenants ()
90
90
defaultZoneConfig := zonepb .DefaultSystemZoneConfig ()
91
91
defaultZoneConfig .NumReplicas = proto .Int32 (1 )
92
92
defaultZoneConfig .RangeMinBytes = proto .Int64 (1 << 20 )
@@ -101,10 +101,12 @@ func TestGetZoneConfig(t *testing.T) {
101
101
s , sqlDB , _ := serverutils .StartServer (t , params )
102
102
defer s .Stopper ().Stop (context .Background ())
103
103
// Set the closed_timestamp interval to be short to shorten the test duration.
104
- tdb := sqlutils .MakeSQLRunner (sqlDB )
105
- tdb .Exec (t , `SET CLUSTER SETTING kv.closed_timestamp.target_duration = '20ms'` )
106
- tdb .Exec (t , `SET CLUSTER SETTING kv.closed_timestamp.side_transport_interval = '20ms'` )
107
- tdb .Exec (t , `SET CLUSTER SETTING kv.rangefeed.closed_timestamp_refresh_interval = '20ms'` )
104
+ systemDB := sqlutils .MakeSQLRunner (s .SystemLayer ().SQLConn (t ))
105
+ systemDB .Exec (t , `SET CLUSTER SETTING kv.closed_timestamp.target_duration = '20ms'` )
106
+ systemDB .Exec (t , `SET CLUSTER SETTING kv.closed_timestamp.side_transport_interval = '20ms'` )
107
+ systemDB .Exec (t , `SET CLUSTER SETTING kv.rangefeed.closed_timestamp_refresh_interval = '20ms'` )
108
+
109
+ codec := s .Codec ()
108
110
109
111
type testCase struct {
110
112
objectID uint32
@@ -119,9 +121,10 @@ func TestGetZoneConfig(t *testing.T) {
119
121
cfg := forceNewConfig (t , s )
120
122
121
123
for tcNum , tc := range testCases {
122
- // Verify SystemConfig.GetZoneConfigForKey.
123
- {
124
- key := append (roachpb .RKey (keys .SystemSQLCodec .TablePrefix (tc .objectID )), tc .keySuffix ... )
124
+ // Verify SystemConfig.GetZoneConfigForKey. GetZoneConfigForKey is
125
+ // exclusive to the system tenant.
126
+ if ! s .StartedDefaultTestTenant () {
127
+ key := append (roachpb .RKey (codec .TablePrefix (tc .objectID )), tc .keySuffix ... )
125
128
_ , zoneCfg , err := config .TestingGetSystemTenantZoneConfigForKey (cfg , key ) // Complete ZoneConfig
126
129
if err != nil {
127
130
t .Fatalf ("#%d: err=%s" , tcNum , err )
@@ -203,10 +206,10 @@ func TestGetZoneConfig(t *testing.T) {
203
206
tb21 := sqlutils .QueryTableID (t , sqlDB , "db2" , "public" , "tb1" )
204
207
tb22 := sqlutils .QueryTableID (t , sqlDB , "db2" , "public" , "tb2" )
205
208
206
- // We have no custom zone configs.
209
+ t . Logf ( "Verifying with no custom zone configs" )
207
210
verifyZoneConfigs ([]testCase {
208
- {0 , nil , "" , defaultZoneConfig },
209
- {1 , nil , "" , defaultZoneConfig },
211
+ {keys . RootNamespaceID , nil , "" , defaultZoneConfig },
212
+ {keys . SystemDatabaseID , nil , "" , defaultZoneConfig },
210
213
{db1 , nil , "" , defaultZoneConfig },
211
214
{db2 , nil , "" , defaultZoneConfig },
212
215
{tb11 , nil , "" , defaultZoneConfig },
@@ -287,9 +290,10 @@ func TestGetZoneConfig(t *testing.T) {
287
290
}
288
291
}
289
292
293
+ t .Logf ("Verifying with custom zone configs" )
290
294
verifyZoneConfigs ([]testCase {
291
- {0 , nil , "" , defaultZoneConfig },
292
- {1 , nil , "" , defaultZoneConfig },
295
+ {keys . RootNamespaceID , nil , "" , defaultZoneConfig },
296
+ {keys . SystemDatabaseID , nil , "" , defaultZoneConfig },
293
297
{db1 , nil , "" , db1Cfg },
294
298
{db2 , nil , "" , defaultZoneConfig },
295
299
{tb11 , nil , "" , tb11Cfg },
@@ -319,7 +323,7 @@ func TestGetZoneConfig(t *testing.T) {
319
323
func TestCascadingZoneConfig (t * testing.T ) {
320
324
defer leaktest .AfterTest (t )()
321
325
defer log .Scope (t ).Close (t )
322
- params , _ := createTestServerParams ()
326
+ params , _ := createTestServerParamsAllowTenants ()
323
327
324
328
defaultZoneConfig := zonepb .DefaultZoneConfig ()
325
329
defaultZoneConfig .NumReplicas = proto .Int32 (1 )
@@ -335,10 +339,12 @@ func TestCascadingZoneConfig(t *testing.T) {
335
339
s , sqlDB , _ := serverutils .StartServer (t , params )
336
340
defer s .Stopper ().Stop (context .Background ())
337
341
// Set the closed_timestamp interval to be short to shorten the test duration.
338
- tdb := sqlutils .MakeSQLRunner (sqlDB )
339
- tdb .Exec (t , `SET CLUSTER SETTING kv.closed_timestamp.target_duration = '20ms'` )
340
- tdb .Exec (t , `SET CLUSTER SETTING kv.closed_timestamp.side_transport_interval = '20ms'` )
341
- tdb .Exec (t , `SET CLUSTER SETTING kv.rangefeed.closed_timestamp_refresh_interval = '20ms'` )
342
+ systemDB := sqlutils .MakeSQLRunner (s .SystemLayer ().SQLConn (t ))
343
+ systemDB .Exec (t , `SET CLUSTER SETTING kv.closed_timestamp.target_duration = '20ms'` )
344
+ systemDB .Exec (t , `SET CLUSTER SETTING kv.closed_timestamp.side_transport_interval = '20ms'` )
345
+ systemDB .Exec (t , `SET CLUSTER SETTING kv.rangefeed.closed_timestamp_refresh_interval = '20ms'` )
346
+
347
+ codec := s .Codec ()
342
348
343
349
type testCase struct {
344
350
objectID uint32
@@ -353,9 +359,10 @@ func TestCascadingZoneConfig(t *testing.T) {
353
359
cfg := forceNewConfig (t , s )
354
360
355
361
for tcNum , tc := range testCases {
356
- // Verify SystemConfig.GetZoneConfigForKey.
357
- {
358
- key := append (roachpb .RKey (keys .SystemSQLCodec .TablePrefix (tc .objectID )), tc .keySuffix ... )
362
+ // Verify SystemConfig.GetZoneConfigForKey. GetZoneConfigForKey is
363
+ // exclusive to the system tenant.
364
+ if ! s .StartedDefaultTestTenant () {
365
+ key := append (roachpb .RKey (codec .TablePrefix (tc .objectID )), tc .keySuffix ... )
359
366
_ , zoneCfg , err := config .TestingGetSystemTenantZoneConfigForKey (cfg , key ) // Complete ZoneConfig
360
367
if err != nil {
361
368
t .Fatalf ("#%d: err=%s" , tcNum , err )
@@ -438,10 +445,10 @@ func TestCascadingZoneConfig(t *testing.T) {
438
445
tb21 := sqlutils .QueryTableID (t , sqlDB , "db2" , "public" , "tb1" )
439
446
tb22 := sqlutils .QueryTableID (t , sqlDB , "db2" , "public" , "tb2" )
440
447
441
- // We have no custom zone configs.
448
+ t . Logf ( "Verifying with no custom zone configs" )
442
449
verifyZoneConfigs ([]testCase {
443
- {0 , nil , "" , defaultZoneConfig },
444
- {1 , nil , "" , defaultZoneConfig },
450
+ {keys . RootNamespaceID , nil , "" , defaultZoneConfig },
451
+ {keys . SystemDatabaseID , nil , "" , defaultZoneConfig },
445
452
{db1 , nil , "" , defaultZoneConfig },
446
453
{db2 , nil , "" , defaultZoneConfig },
447
454
{tb11 , nil , "" , defaultZoneConfig },
@@ -567,9 +574,10 @@ func TestCascadingZoneConfig(t *testing.T) {
567
574
}
568
575
}
569
576
577
+ t .Logf ("Verifying with custom zone configs" )
570
578
verifyZoneConfigs ([]testCase {
571
- {0 , nil , "" , defaultZoneConfig },
572
- {1 , nil , "" , defaultZoneConfig },
579
+ {keys . RootNamespaceID , nil , "" , defaultZoneConfig },
580
+ {keys . SystemDatabaseID , nil , "" , defaultZoneConfig },
573
581
{db1 , nil , "" , expectedDb1Cfg },
574
582
{db2 , nil , "" , defaultZoneConfig },
575
583
{tb11 , nil , "" , expectedTb11Cfg },
@@ -641,7 +649,9 @@ func BenchmarkGetZoneConfig(b *testing.B) {
641
649
defer leaktest .AfterTest (b )()
642
650
defer log .Scope (b ).Close (b )
643
651
644
- params , _ := createTestServerParams ()
652
+ params , _ := createTestServerParamsAllowTenants ()
653
+ // GetZoneConfigForKey is exclusive to the system tenant.
654
+ params .DefaultTestTenant = base .TestIsSpecificToStorageLayerAndNeedsASystemTenant
645
655
s , sqlDB , _ := serverutils .StartServer (b , params )
646
656
defer s .Stopper ().Stop (context .Background ())
647
657
// Set the closed_timestamp interval to be short to shorten the test duration.
@@ -651,7 +661,7 @@ func BenchmarkGetZoneConfig(b *testing.B) {
651
661
tdb .Exec (b , `SET CLUSTER SETTING kv.rangefeed.closed_timestamp_refresh_interval = '20ms'` )
652
662
cfg := forceNewConfig (b , s )
653
663
654
- key := roachpb .RKey (keys . SystemSQLCodec .TablePrefix (bootstrap .TestingUserDescID (0 )))
664
+ key := roachpb .RKey (s . Codec () .TablePrefix (bootstrap .TestingUserDescID (0 )))
655
665
b .ResetTimer ()
656
666
for i := 0 ; i < b .N ; i ++ {
657
667
_ , _ , err := config .TestingGetSystemTenantZoneConfigForKey (cfg , key )
0 commit comments