diff --git a/pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts b/pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts index c3a3837090c4..fd951dc1dfa4 100644 --- a/pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts +++ b/pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts @@ -69,8 +69,7 @@ function newDatabaseDetailsResponse(): DatabaseDetailsResponse { range_count: 0, }, replicaData: { - replicas: [], - regions: [], + storeIDs: [], }, indexStats: { num_index_recommendations: 0 }, }, @@ -294,7 +293,10 @@ const getDatabaseZoneConfig: DatabaseDetailsQuery = { // Database Stats type DatabaseDetailsStats = { spanStats: SqlApiQueryResponse; - replicaData: SqlApiQueryResponse; + replicaData: { + storeIDs: number[]; + error?: Error; + }; indexStats: SqlApiQueryResponse; }; @@ -345,44 +347,31 @@ const getDatabaseSpanStats: DatabaseDetailsQuery = { }; type DatabaseReplicasRegionsRow = { - replicas: number[]; - regions: string[]; + store_ids: number[]; }; const getDatabaseReplicasAndRegions: DatabaseDetailsQuery = { createStmt: dbName => { + // This query is meant to retrieve the per-database set of store ids. return { sql: Format( - `WITH - replicasAndregions as ( - SELECT - r.replicas, - ARRAY(SELECT DISTINCT split_part(split_part(unnest(replica_localities),',',1),'=',2)) as regions - FROM crdb_internal.tables as t - JOIN %1.crdb_internal.table_spans as s ON s.descriptor_id = t.table_id - JOIN crdb_internal.ranges_no_leases as r ON s.start_key < r.end_key AND s.end_key > r.start_key - WHERE t.database_name = $1 - ), - unique_replicas AS (SELECT array_agg(distinct(unnest(replicas))) as replicas FROM replicasAndRegions), - unique_regions AS (SELECT array_agg(distinct(unnest(regions))) as regions FROM replicasAndRegions) - SELECT replicas, regions FROM unique_replicas CROSS JOIN unique_regions`, + ` + SELECT array_agg(DISTINCT unnested_store_ids) AS store_ids + FROM [SHOW RANGES FROM DATABASE %1], unnest(replicas) AS unnested_store_ids +`, [new Identifier(dbName)], ), - arguments: [dbName], }; }, addToDatabaseDetail: ( txn_result: SqlTxnResult, resp: DatabaseDetailsResponse, ) => { - if (!txnResultIsEmpty(txn_result)) { - resp.stats.replicaData.regions = txn_result.rows[0].regions; - resp.stats.replicaData.replicas = txn_result.rows[0].replicas; - } if (txn_result.error) { resp.stats.replicaData.error = txn_result.error; } + resp.stats.replicaData.storeIDs = txn_result?.rows[0]?.store_ids ?? []; }, handleMaxSizeError: (_dbName, _response, _dbDetail) => { return Promise.resolve(false); diff --git a/pkg/ui/workspaces/cluster-ui/src/databases/combiners.ts b/pkg/ui/workspaces/cluster-ui/src/databases/combiners.ts index 71a28b4ea13f..2cc8b96fa0c9 100644 --- a/pkg/ui/workspaces/cluster-ui/src/databases/combiners.ts +++ b/pkg/ui/workspaces/cluster-ui/src/databases/combiners.ts @@ -69,9 +69,10 @@ const deriveDatabaseDetails = ( isTenant: boolean, ): DatabasesPageDataDatabase => { const dbStats = dbDetails?.data?.results.stats; - const nodes = dbStats?.replicaData.replicas || []; + // TODO #118957 (xinhaoz) Use store id to regions mapping. + const stores = dbStats?.replicaData.storeIDs || []; const nodesByRegionString = getNodesByRegionString( - nodes, + stores, nodeRegionsByID, isTenant, ); @@ -86,7 +87,7 @@ const deriveDatabaseDetails = ( name: database, spanStats: dbStats?.spanStats, tables: dbDetails?.data?.results.tablesResp, - nodes: nodes, + nodes: stores, nodesByRegionString, numIndexRecommendations, }; diff --git a/pkg/ui/workspaces/cluster-ui/src/store/databaseDetails/databaseDetails.saga.spec.ts b/pkg/ui/workspaces/cluster-ui/src/store/databaseDetails/databaseDetails.saga.spec.ts index 9f74ab630de0..0b053195b412 100644 --- a/pkg/ui/workspaces/cluster-ui/src/store/databaseDetails/databaseDetails.saga.spec.ts +++ b/pkg/ui/workspaces/cluster-ui/src/store/databaseDetails/databaseDetails.saga.spec.ts @@ -76,8 +76,7 @@ describe("DatabaseDetails sagas", () => { range_count: 20, }, replicaData: { - replicas: [1, 2, 3], - regions: ["this", "is", "a", "region"], + storeIDs: [1, 2, 3], }, indexStats: { num_index_recommendations: 4 }, }, diff --git a/pkg/ui/workspaces/db-console/src/util/api.spec.ts b/pkg/ui/workspaces/db-console/src/util/api.spec.ts index ba45d5a18643..1d77848b8b14 100644 --- a/pkg/ui/workspaces/db-console/src/util/api.spec.ts +++ b/pkg/ui/workspaces/db-console/src/util/api.spec.ts @@ -156,8 +156,7 @@ describe("rest api", function () { { rows: [ { - replicas: [1, 2, 3], - regions: ["gcp-europe-west1", "gcp-europe-west2"], + store_ids: [1, 2, 3], }, ], }, diff --git a/pkg/ui/workspaces/db-console/src/util/fakeApi.ts b/pkg/ui/workspaces/db-console/src/util/fakeApi.ts index f829515f77bb..8f5bed39f4bf 100644 --- a/pkg/ui/workspaces/db-console/src/util/fakeApi.ts +++ b/pkg/ui/workspaces/db-console/src/util/fakeApi.ts @@ -101,25 +101,6 @@ function stubGet(path: string, writer: $protobuf.Writer, prefix: string) { fetchMock.get(`${prefix}${path}`, writer.finish()); } -export function createMockDatabaseRangesForTable( - numRangesCreate: number, - numNodes: number, -): clusterUiApi.DatabaseDetailsRow[] { - const res = []; - const replicas = []; - for (let i = 1; i <= numNodes; i++) { - replicas.push(i); - } - for (let i = 0; i < numRangesCreate; i++) { - res.push({ - replicas: replicas, - regions: ["gcp-europe-west1", "gcp-europe-west2"], - range_size: 10, - }); - } - return res; -} - export function stubSqlApiCall( req: clusterUiApi.SqlExecutionRequest, mockTxnResults: mockSqlTxnResult[], diff --git a/pkg/ui/workspaces/db-console/src/views/databases/databasesPage/redux.spec.ts b/pkg/ui/workspaces/db-console/src/views/databases/databasesPage/redux.spec.ts index 2114fd0e71cd..24a3097549b5 100644 --- a/pkg/ui/workspaces/db-console/src/views/databases/databasesPage/redux.spec.ts +++ b/pkg/ui/workspaces/db-console/src/views/databases/databasesPage/redux.spec.ts @@ -246,16 +246,13 @@ describe("Databases Page", function () { { rows: [ { - replicas: [1, 2, 3], - regions: ["gcp-europe-west1", "gcp-europe-west2"], + store_ids: [1, 2, 3], }, { - replicas: [1, 2, 3], - regions: ["gcp-europe-west1", "gcp-europe-west2"], + store_ids: [1, 2, 3], }, { - replicas: [1, 2, 3], - regions: ["gcp-europe-west1", "gcp-europe-west2"], + store_ids: [1, 2, 3], }, ], },