Skip to content

Commit 9d0d231

Browse files
committed
testserver: make ForceTableGC agnostic of secondary tenants
Release note: None
1 parent b972a27 commit 9d0d231

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

pkg/server/testserver.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,13 @@ func (t *TestTenant) TracerI() interface{} {
906906
return t.Tracer()
907907
}
908908

909+
// ForceTableGC is part of the serverutils.ApplicationLayerInterface.
910+
func (t *TestTenant) ForceTableGC(
911+
ctx context.Context, database, table string, timestamp hlc.Timestamp,
912+
) error {
913+
return internalForceTableGC(ctx, t, database, table, timestamp)
914+
}
915+
909916
// SettingsWatcher is part of the serverutils.ApplicationLayerInterface.
910917
func (t *TestTenant) SettingsWatcher() interface{} {
911918
return t.sql.settingsWatcher
@@ -1856,38 +1863,33 @@ func (ts *TestServer) Tracer() *tracing.Tracer {
18561863
return ts.node.storeCfg.AmbientCtx.Tracer
18571864
}
18581865

1859-
// ForceTableGC is part of the serverutils.TestServerInterface.
1866+
// ForceTableGC is part of the serverutils.ApplicationLayerInterface.
18601867
func (ts *TestServer) ForceTableGC(
18611868
ctx context.Context, database, table string, timestamp hlc.Timestamp,
18621869
) error {
1863-
tableIDQuery := `
1864-
SELECT tables.id FROM system.namespace tables
1865-
JOIN system.namespace dbs ON dbs.id = tables."parentID"
1866-
WHERE dbs.name = $1 AND tables.name = $2
1867-
`
1868-
row, err := ts.sqlServer.internalExecutor.QueryRowEx(
1869-
ctx, "resolve-table-id", nil, /* txn */
1870-
sessiondata.RootUserSessionDataOverride,
1871-
tableIDQuery, database, table)
1870+
return internalForceTableGC(ctx, ts.SystemLayer(), database, table, timestamp)
1871+
}
1872+
1873+
func internalForceTableGC(
1874+
ctx context.Context,
1875+
app serverutils.ApplicationLayerInterface,
1876+
database, table string,
1877+
timestamp hlc.Timestamp,
1878+
) error {
1879+
tableID, err := app.QueryTableID(ctx, username.RootUserName(), database, table)
18721880
if err != nil {
18731881
return err
18741882
}
1875-
if row == nil {
1876-
return errors.Errorf("table not found")
1877-
}
1878-
if len(row) != 1 {
1879-
return errors.AssertionFailedf("expected 1 column from internal query")
1880-
}
1881-
tableID := uint32(*row[0].(*tree.DInt))
1882-
tblKey := keys.SystemSQLCodec.TablePrefix(tableID)
1883+
1884+
tblKey := app.Codec().TablePrefix(uint32(tableID))
18831885
gcr := kvpb.GCRequest{
18841886
RequestHeader: kvpb.RequestHeader{
18851887
Key: tblKey,
18861888
EndKey: tblKey.PrefixEnd(),
18871889
},
18881890
Threshold: timestamp,
18891891
}
1890-
_, pErr := kv.SendWrapped(ctx, ts.distSender, &gcr)
1892+
_, pErr := kv.SendWrapped(ctx, app.DistSenderI().(kv.Sender), &gcr)
18911893
return pErr.GoError()
18921894
}
18931895

pkg/testutils/serverutils/test_tenant_shim.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ type ApplicationLayerInterface interface {
302302
ctx context.Context, span roachpb.Span,
303303
) (*serverpb.TableStatsResponse, error)
304304

305+
// ForceTableGC sends a GCRequest for the ranges corresponding to a table.
306+
//
307+
// An error will be returned if the same table name exists in multiple schemas
308+
// inside the specified database.
309+
ForceTableGC(ctx context.Context, database, table string, timestamp hlc.Timestamp) error
310+
305311
// TODO(irfansharif): We'd benefit from an API to construct a *gosql.DB, or
306312
// better yet, a *sqlutils.SQLRunner. We use it all the time, constructing
307313
// it by hand each time.

0 commit comments

Comments
 (0)