diff --git a/pkg/ccl/serverccl/admin_test.go b/pkg/ccl/serverccl/admin_test.go index a90e20a71eb4..d182a498499a 100644 --- a/pkg/ccl/serverccl/admin_test.go +++ b/pkg/ccl/serverccl/admin_test.go @@ -47,13 +47,14 @@ func TestAdminAPIDataDistributionPartitioning(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) + // Need to disable the test tenant because this test fails + // when run through a tenant (with internal server error). + // More investigation is required. Tracked with #76387. + disableDefaultTestTenant := true testCluster := serverutils.StartNewTestCluster(t, 3, base.TestClusterArgs{ ServerArgs: base.TestServerArgs{ - // Need to disable the test tenant because this test fails - // when run through a tenant (with internal server error). - // More investigation is required. Tracked with #76387. - DisableDefaultTestTenant: true, + DisableDefaultTestTenant: disableDefaultTestTenant, }, }) defer testCluster.Stopper().Stop(context.Background()) @@ -81,6 +82,11 @@ func TestAdminAPIDataDistributionPartitioning(t *testing.T) { sqlDB.Exec(t, `ALTER PARTITION us OF TABLE comments CONFIGURE ZONE USING gc.ttlseconds = 9001`) sqlDB.Exec(t, `ALTER PARTITION eu OF TABLE comments CONFIGURE ZONE USING gc.ttlseconds = 9002`) + if disableDefaultTestTenant { + // Make sure secondary tenants don't cause the endpoint to error. + sqlDB.Exec(t, "CREATE TENANT 'app'") + } + // Assert that we get all roachblog zone configs back. expectedZoneConfigNames := map[string]struct{}{ "PARTITION eu OF INDEX roachblog.public.comments@comments_pkey": {}, diff --git a/pkg/server/admin.go b/pkg/server/admin.go index cb29d6144129..f0c0f90111d8 100644 --- a/pkg/server/admin.go +++ b/pkg/server/admin.go @@ -3082,6 +3082,17 @@ func (s *adminServer) dataDistributionHelper( if err != nil { return err } + + // A range descriptor for a secondary tenant may not contain + // a table prefix. Often, the start key for a tenant will be just + // the tenant prefix itself, e.g. `/Tenant/2`. Once the tenant prefix + // is stripped inside `DecodeTablePrefix`, nothing (aka `/Min`) is left. + keySansPrefix, _ := keys.MakeSQLCodec(tenID).StripTenantPrefix(rangeDesc.StartKey.AsRawKey()) + if keys.MinKey.Equal(keySansPrefix) { + // There's no table prefix to be decoded. + // Try the next descriptor. + continue + } _, tableID, err := keys.MakeSQLCodec(tenID).DecodeTablePrefix(rangeDesc.StartKey.AsRawKey()) if err != nil { return err diff --git a/pkg/server/admin_test.go b/pkg/server/admin_test.go index 8bcd19b75580..d616d22b3e86 100644 --- a/pkg/server/admin_test.go +++ b/pkg/server/admin_test.go @@ -2220,6 +2220,9 @@ func TestAdminAPIDataDistribution(t *testing.T) { sqlDB.Exec(t, `CREATE DATABASE "sp'ec\ch""ars"`) sqlDB.Exec(t, `CREATE TABLE "sp'ec\ch""ars"."more\spec'chars" (id INT PRIMARY KEY)`) + // Make sure secondary tenants don't cause the endpoint to error. + sqlDB.Exec(t, "CREATE TENANT 'app'") + // Verify that we see their replicas in the DataDistribution response, evenly spread // across the test cluster's three nodes.