Skip to content

Commit dc97025

Browse files
committed
testutils: remove ForceTableGC from ApplicationLayerInterface
In 9d0d231 we made `ForceTableGC` helper method of the test server work with secondary tenants and moved it into the ApplicationLayer interface. The method works by issuing the KV GCRequest command on the range containing the user table. However, with secondary tenants (both in shared-process and external-process modes) IIUC we don't add split points between all tables, so it's possible that when trying to GC the "user" table we also GC the "system" table. This showed up as a failure in TestStatsWithLowTTL where an update to a cluster setting was never observed by the tenant because the settings-watcher rangefeed failed since it ran into the GC threshold and exited. I think if we're mucking with KV GC requests it makes sense that such tests would be specific to the system tenant, so this commit removes ForceTableGC method from the ApplicationLayer interface and adjusts a couple of tests to only work with system tenants. Release note: None
1 parent 3b2811c commit dc97025

File tree

5 files changed

+26
-38
lines changed

5 files changed

+26
-38
lines changed

pkg/backup/backup_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10502,6 +10502,7 @@ func TestBackupDBWithViewOnAdjacentDBRange(t *testing.T) {
1050210502
},
1050310503
})
1050410504
defer cleanupFn()
10505+
srv0 := tc.StorageLayer(0)
1050510506
s0 := tc.ApplicationLayer(0)
1050610507

1050710508
// Speeds up the test.
@@ -10532,7 +10533,7 @@ func TestBackupDBWithViewOnAdjacentDBRange(t *testing.T) {
1053210533
time.Sleep(5 * time.Second)
1053310534

1053410535
// Force GC on da.t2 to advance its GC threshold.
10535-
err := s0.ForceTableGC(context.Background(), "da", "t2", s0.Clock().Now().Add(-int64(1*time.Second), 0))
10536+
err := srv0.ForceTableGC(context.Background(), "da", "t2", s0.Clock().Now().Add(-int64(1*time.Second), 0))
1053610537
require.NoError(t, err)
1053710538

1053810539
// This statement should succeed as we are not backing up the span for dbview,

pkg/server/testserver.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,13 +1297,6 @@ func (t *testTenant) TracerI() interface{} {
12971297
return t.Tracer()
12981298
}
12991299

1300-
// ForceTableGC is part of the serverutils.ApplicationLayerInterface.
1301-
func (t *testTenant) ForceTableGC(
1302-
ctx context.Context, database, table string, timestamp hlc.Timestamp,
1303-
) error {
1304-
return internalForceTableGC(ctx, t, database, table, timestamp)
1305-
}
1306-
13071300
// DefaultZoneConfig is part of the serverutils.ApplicationLayerInterface.
13081301
func (t *testTenant) DefaultZoneConfig() zonepb.ZoneConfig {
13091302
return *t.SystemConfigProvider().GetSystemConfig().DefaultZoneConfig
@@ -2294,33 +2287,24 @@ func (ts *testServer) Tracer() *tracing.Tracer {
22942287
return ts.node.storeCfg.AmbientCtx.Tracer
22952288
}
22962289

2297-
// ForceTableGC is part of the serverutils.ApplicationLayerInterface.
2290+
// ForceTableGC is part of the serverutils.StorageLayerInterface.
22982291
func (ts *testServer) ForceTableGC(
22992292
ctx context.Context, database, table string, timestamp hlc.Timestamp,
23002293
) error {
2301-
return internalForceTableGC(ctx, ts, database, table, timestamp)
2302-
}
2303-
2304-
func internalForceTableGC(
2305-
ctx context.Context,
2306-
app serverutils.ApplicationLayerInterface,
2307-
database, table string,
2308-
timestamp hlc.Timestamp,
2309-
) error {
2310-
tableID, err := app.QueryTableID(ctx, username.RootUserName(), database, table)
2294+
tableID, err := ts.QueryTableID(ctx, username.RootUserName(), database, table)
23112295
if err != nil {
23122296
return err
23132297
}
23142298

2315-
tblKey := app.Codec().TablePrefix(uint32(tableID))
2299+
tblKey := ts.Codec().TablePrefix(uint32(tableID))
23162300
gcr := kvpb.GCRequest{
23172301
RequestHeader: kvpb.RequestHeader{
23182302
Key: tblKey,
23192303
EndKey: tblKey.PrefixEnd(),
23202304
},
23212305
Threshold: timestamp,
23222306
}
2323-
_, pErr := kv.SendWrapped(ctx, app.DistSenderI().(kv.Sender), &gcr)
2307+
_, pErr := kv.SendWrapped(ctx, ts.DistSenderI().(kv.Sender), &gcr)
23242308
return pErr.GoError()
23252309
}
23262310

pkg/sql/create_stats_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestStatsWithLowTTL(t *testing.T) {
4242
var blockTableReader atomic.Bool
4343
blockCh := make(chan struct{})
4444

45-
s, db, _ := serverutils.StartServer(t, base.TestServerArgs{
45+
srv, db, _ := serverutils.StartServer(t, base.TestServerArgs{
4646
Knobs: base.TestingKnobs{
4747
DistSQL: &execinfra.TestingKnobs{
4848
// Set the batch size small to avoid having to use a large
@@ -59,12 +59,11 @@ func TestStatsWithLowTTL(t *testing.T) {
5959
},
6060
},
6161
},
62-
// In external-process mode the tenant doesn't have kvpb.GCRequest
63-
// capability (and this capability can't be granted at the time of
64-
// writing either), so we skip the external mode only.
65-
DefaultTestTenant: base.TestSkipForExternalProcessMode(),
62+
// ForceTableGC is only available for the system tenant.
63+
DefaultTestTenant: base.TestIsSpecificToStorageLayerAndNeedsASystemTenant,
6664
})
67-
defer s.Stopper().Stop(context.Background())
65+
defer srv.Stopper().Stop(context.Background())
66+
s := srv.ApplicationLayer()
6867

6968
r := sqlutils.MakeSQLRunner(db)
7069
r.Exec(t, `SET CLUSTER SETTING sql.stats.automatic_collection.enabled = false;`)
@@ -141,7 +140,7 @@ func TestStatsWithLowTTL(t *testing.T) {
141140
nextPK++
142141
}
143142
// Force a table GC of values older than 2 seconds.
144-
if err := s.ForceTableGC(
143+
if err := srv.ForceTableGC(
145144
context.Background(), "defaultdb", "t", s.Clock().Now().Add(-int64(2*time.Second), 0),
146145
); err != nil {
147146
goroutineErr = err

pkg/sql/user_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,8 @@ func TestUserLoginAfterGC(t *testing.T) {
3636
ctx := context.Background()
3737

3838
srv, db, _ := serverutils.StartServer(t, base.TestServerArgs{
39-
// In external-process mode the tenant doesn't have kvpb.GCRequest
40-
// capability (and this capability can't be granted at the time of
41-
// writing either), so we skip the external mode only.
42-
DefaultTestTenant: base.TestSkipForExternalProcessMode(),
39+
// ForceTableGC is only available for the system tenant.
40+
DefaultTestTenant: base.TestIsSpecificToStorageLayerAndNeedsASystemTenant,
4341
})
4442
defer srv.Stopper().Stop(ctx)
4543
s := srv.ApplicationLayer()
@@ -55,7 +53,7 @@ func TestUserLoginAfterGC(t *testing.T) {
5553
time.Sleep(2 * time.Second)
5654

5755
// Force a table GC with a threshold of 500ms in the past.
58-
err = s.ForceTableGC(ctx, "system", "role_members", s.Clock().Now().Add(-int64(500*time.Millisecond), 0))
56+
err = srv.ForceTableGC(ctx, "system", "role_members", s.Clock().Now().Add(-int64(500*time.Millisecond), 0))
5957
require.NoError(t, err)
6058

6159
// Verify that newuser can still log in.

pkg/testutils/serverutils/api.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,6 @@ type ApplicationLayerInterface interface {
463463
ctx context.Context, span roachpb.Span,
464464
) (*serverpb.TableStatsResponse, error)
465465

466-
// ForceTableGC forces a KV GC round on the key range for the given table.
467-
ForceTableGC(
468-
ctx context.Context, database, table string, timestamp hlc.Timestamp,
469-
) error
470-
471466
// DefaultZoneConfig is a convenience function that accesses
472467
// .SystemConfigProvider().GetSystemConfig().DefaultZoneConfig.
473468
DefaultZoneConfig() zonepb.ZoneConfig
@@ -732,6 +727,17 @@ type StorageLayerInterface interface {
732727

733728
// RaftConfig retrieves a copy of the raft configuration.
734729
RaftConfig() base.RaftConfig
730+
731+
// ForceTableGC forces a KV GC round on the key range for the given table.
732+
//
733+
// Note that we don't provide this functionality as part of the
734+
// ApplicationLayerInterface because on secondary tenants we don't put
735+
// split points between all tables, so the KV GC request could affect other
736+
// system tables (since they could share the underlying range with the user
737+
// table).
738+
ForceTableGC(
739+
ctx context.Context, database, table string, timestamp hlc.Timestamp,
740+
) error
735741
}
736742

737743
// TestServerFactory encompasses the actual implementation of the shim

0 commit comments

Comments
 (0)