Skip to content

Commit 1c87a84

Browse files
authored
Merge pull request #140609 from cockroachdb/blathers/backport-release-25.1-140066
release-25.1: server: do not use MustBeDString on nullable result col
2 parents d414660 + ea82a41 commit 1c87a84

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

pkg/server/admin.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -3054,7 +3054,10 @@ func (s *adminServer) dataDistributionHelper(
30543054
for hasNext, err = it.Next(ctx); hasNext; hasNext, err = it.Next(ctx) {
30553055
row := it.Cur()
30563056
target := string(tree.MustBeDString(row[0]))
3057-
zcSQL := tree.MustBeDString(row[1])
3057+
var zcSQL string
3058+
if zcSQLDatum, ok := tree.AsDString(row[1]); ok {
3059+
zcSQL = string(zcSQLDatum)
3060+
}
30583061
zcBytes := tree.MustBeDBytes(row[2])
30593062
var zcProto zonepb.ZoneConfig
30603063
if err := protoutil.Unmarshal([]byte(zcBytes), &zcProto); err != nil {
@@ -3064,7 +3067,7 @@ func (s *adminServer) dataDistributionHelper(
30643067
resp.ZoneConfigs[target] = serverpb.DataDistributionResponse_ZoneConfig{
30653068
Target: target,
30663069
Config: zcProto,
3067-
ConfigSQL: string(zcSQL),
3070+
ConfigSQL: zcSQL,
30683071
}
30693072
}
30703073
if err != nil {

pkg/server/application_api/storage_inspection_test.go

+20-18
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func TestAdminAPIDataDistribution(t *testing.T) {
197197

198198
firstServer := tc.Server(0).ApplicationLayer()
199199

200-
sqlDB := sqlutils.MakeSQLRunner(tc.ServerConn(0))
200+
sqlDB := sqlutils.MakeSQLRunner(firstServer.SQLConn(t))
201201

202202
{
203203
// TODO(irfansharif): The data-distribution page and underyling APIs don't
@@ -217,6 +217,11 @@ func TestAdminAPIDataDistribution(t *testing.T) {
217217
post_id INT REFERENCES roachblog.posts,
218218
body text
219219
)`)
220+
221+
// Test for null raw sql config column in crdb_internal.zones,
222+
// see: https://github.com/cockroachdb/cockroach/issues/140044
223+
//sqlDB.Exec(t, `-- ALTER TABLE roachblog.posts CONFIGURE ZONE = ''`)
224+
220225
sqlDB.Exec(t, `CREATE SCHEMA roachblog."foo bar"`)
221226
sqlDB.Exec(t, `CREATE TABLE roachblog."foo bar".other_stuff(id INT PRIMARY KEY, body TEXT)`)
222227
// Test special characters in DB and table names.
@@ -265,31 +270,28 @@ func TestAdminAPIDataDistribution(t *testing.T) {
265270
},
266271
}
267272

268-
// Wait for the new tables' ranges to be created and replicated.
269-
testutils.SucceedsSoon(t, func() error {
270-
var resp serverpb.DataDistributionResponse
271-
if err := srvtestutils.GetAdminJSONProto(firstServer, "data_distribution", &resp); err != nil {
272-
t.Fatal(err)
273-
}
273+
require.NoError(t, tc.WaitForFullReplication())
274274

275-
delete(resp.DatabaseInfo, "system") // delete results for system database.
276-
if !reflect.DeepEqual(resp.DatabaseInfo, expectedDatabaseInfo) {
277-
return fmt.Errorf("expected %v; got %v", expectedDatabaseInfo, resp.DatabaseInfo)
278-
}
275+
// Wait for the new tables' ranges to be created and replicated.
276+
var resp serverpb.DataDistributionResponse
277+
if err := srvtestutils.GetAdminJSONProto(firstServer, "data_distribution", &resp); err != nil {
278+
t.Fatal(err)
279+
}
279280

280-
// Don't test anything about the zone configs for now; just verify that something is there.
281-
if len(resp.ZoneConfigs) == 0 {
282-
return fmt.Errorf("no zone configs returned")
283-
}
281+
delete(resp.DatabaseInfo, "system") // delete results for system database.
282+
if !reflect.DeepEqual(resp.DatabaseInfo, expectedDatabaseInfo) {
283+
t.Fatal("unexpected data distribution response", resp.DatabaseInfo)
284+
//return fmt.Errorf("expected %v; got %v", expectedDatabaseInfo, resp.DatabaseInfo)
285+
}
284286

285-
return nil
286-
})
287+
// Don't test anything about the zone configs for now; just verify that something is there.
288+
require.NotEmpty(t, resp.ZoneConfigs)
287289

288290
// Verify that the request still works after a table has been dropped,
289291
// and that dropped_at is set on the dropped table.
290292
sqlDB.Exec(t, `DROP TABLE roachblog.comments`)
291293

292-
var resp serverpb.DataDistributionResponse
294+
//var resp serverpb.DataDistributionResponse
293295
if err := srvtestutils.GetAdminJSONProto(firstServer, "data_distribution", &resp); err != nil {
294296
t.Fatal(err)
295297
}

0 commit comments

Comments
 (0)