Skip to content

Commit

Permalink
Merge #24855
Browse files Browse the repository at this point in the history
24855: ui: add data distribution debug page (aka replica matrix) r=vilterp a=vilterp

![image](https://user-images.githubusercontent.com/7341/41315292-0f7d284a-6e5d-11e8-81cb-cacd978cc519.png)

Split off from #20500, which had some CR comments from four months ago. Many have been addressed, but need to comb through again.

Note: if one of its API calls returns an error, it will display the spinner forever. Sadly, the cluster viz has the same problem (as well as many other pages, probably). Kind of want to address this with some changes to `Loader` as part of #24011, but maybe should just address it here.

Co-authored-by: Pete Vilter <[email protected]>
  • Loading branch information
craig[bot] and Pete Vilter committed Jun 14, 2018
2 parents b7466ce + 721de4c commit 0673874
Show file tree
Hide file tree
Showing 16 changed files with 1,596 additions and 336 deletions.
24 changes: 12 additions & 12 deletions pkg/server/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -1359,13 +1359,13 @@ func (s *adminServer) Decommission(
return s.DecommissionStatus(ctx, &serverpb.DecommissionStatusRequest{NodeIDs: nodeIDs})
}

// ReplicaMatrix returns a count of replicas on each node for each table.
func (s *adminServer) ReplicaMatrix(
ctx context.Context, req *serverpb.ReplicaMatrixRequest,
) (*serverpb.ReplicaMatrixResponse, error) {
resp := &serverpb.ReplicaMatrixResponse{
DatabaseInfo: make(map[string]serverpb.ReplicaMatrixResponse_DatabaseInfo),
ZoneConfigs: make(map[int64]serverpb.ReplicaMatrixResponse_ZoneConfig),
// DataDistribution returns a count of replicas on each node for each table.
func (s *adminServer) DataDistribution(
ctx context.Context, req *serverpb.DataDistributionRequest,
) (*serverpb.DataDistributionResponse, error) {
resp := &serverpb.DataDistributionResponse{
DatabaseInfo: make(map[string]serverpb.DataDistributionResponse_DatabaseInfo),
ZoneConfigs: make(map[int64]serverpb.DataDistributionResponse_ZoneConfig),
}

// Get ids and names for databases and tables.
Expand All @@ -1384,7 +1384,7 @@ func (s *adminServer) ReplicaMatrix(
}

// Used later when we're scanning Meta2 and only have IDs, not names.
tableInfosByTableID := map[uint64]serverpb.ReplicaMatrixResponse_TableInfo{}
tableInfosByTableID := map[uint64]serverpb.DataDistributionResponse_TableInfo{}

for _, row := range rows1 {
tableName := (*string)(row[0].(*tree.DString))
Expand All @@ -1394,8 +1394,8 @@ func (s *adminServer) ReplicaMatrix(
// Insert database if it doesn't exist.
dbInfo, ok := resp.DatabaseInfo[*dbName]
if !ok {
dbInfo = serverpb.ReplicaMatrixResponse_DatabaseInfo{
TableInfo: make(map[string]serverpb.ReplicaMatrixResponse_TableInfo),
dbInfo = serverpb.DataDistributionResponse_DatabaseInfo{
TableInfo: make(map[string]serverpb.DataDistributionResponse_TableInfo),
}
resp.DatabaseInfo[*dbName] = dbInfo
}
Expand All @@ -1422,7 +1422,7 @@ func (s *adminServer) ReplicaMatrix(
zcID := int64(tree.MustBeDInt(zcRow[0]))

// Insert table.
tableInfo := serverpb.ReplicaMatrixResponse_TableInfo{
tableInfo := serverpb.DataDistributionResponse_TableInfo{
ReplicaCountByNodeId: make(map[roachpb.NodeID]int64),
ZoneConfigId: zcID,
}
Expand Down Expand Up @@ -1492,7 +1492,7 @@ func (s *adminServer) ReplicaMatrix(
return nil, s.serverError(err)
}

resp.ZoneConfigs[zcID] = serverpb.ReplicaMatrixResponse_ZoneConfig{
resp.ZoneConfigs[zcID] = serverpb.DataDistributionResponse_ZoneConfig{
CliSpecifier: zcCliSpecifier,
Config: zcProto,
ConfigYaml: string(zcYaml),
Expand Down
18 changes: 9 additions & 9 deletions pkg/server/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,7 @@ func TestAdminAPIFullRangeLog(t *testing.T) {
}
}

func TestAdminAPIReplicaMatrix(t *testing.T) {
func TestAdminAPIDataDistribution(t *testing.T) {
defer leaktest.AfterTest(t)()

t.Skip("#24802")
Expand All @@ -1328,12 +1328,12 @@ func TestAdminAPIReplicaMatrix(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)`)

// Verify that we see their replicas in the ReplicaMatrix response, evenly spread
// Verify that we see their replicas in the DataDistribution response, evenly spread
// across the test cluster's three nodes.

expectedResp := map[string]serverpb.ReplicaMatrixResponse_DatabaseInfo{
expectedResp := map[string]serverpb.DataDistributionResponse_DatabaseInfo{
"roachblog": {
TableInfo: map[string]serverpb.ReplicaMatrixResponse_TableInfo{
TableInfo: map[string]serverpb.DataDistributionResponse_TableInfo{
"posts": {
ReplicaCountByNodeId: map[roachpb.NodeID]int64{
1: 1,
Expand All @@ -1351,7 +1351,7 @@ func TestAdminAPIReplicaMatrix(t *testing.T) {
},
},
`sp'ec\ch"ars`: {
TableInfo: map[string]serverpb.ReplicaMatrixResponse_TableInfo{
TableInfo: map[string]serverpb.DataDistributionResponse_TableInfo{
`more\spec'chars`: {
ReplicaCountByNodeId: map[roachpb.NodeID]int64{
1: 1,
Expand All @@ -1365,7 +1365,7 @@ func TestAdminAPIReplicaMatrix(t *testing.T) {

// Wait for the new tables' ranges to be created and replicated.
testutils.SucceedsSoon(t, func() error {
var resp serverpb.ReplicaMatrixResponse
var resp serverpb.DataDistributionResponse
if err := getAdminJSONProto(firstServer, "replica_matrix", &resp); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1399,7 +1399,7 @@ func TestAdminAPIReplicaMatrix(t *testing.T) {

// Verify that we see the zone config and its effects.
testutils.SucceedsSoon(t, func() error {
var resp serverpb.ReplicaMatrixResponse
var resp serverpb.DataDistributionResponse
if err := getAdminJSONProto(firstServer, "replica_matrix", &resp); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -1428,7 +1428,7 @@ func TestAdminAPIReplicaMatrix(t *testing.T) {
})
}

func BenchmarkAdminAPIReplicaMatrix(b *testing.B) {
func BenchmarkAdminAPIDataDistribution(b *testing.B) {
testCluster := serverutils.StartTestCluster(b, 3, base.TestClusterArgs{})
defer testCluster.Stopper().Stop(context.Background())

Expand All @@ -1448,7 +1448,7 @@ func BenchmarkAdminAPIReplicaMatrix(b *testing.B) {

b.ResetTimer()
for n := 0; n < b.N; n++ {
var resp serverpb.ReplicaMatrixResponse
var resp serverpb.DataDistributionResponse
if err := getAdminJSONProto(firstServer, "replica_matrix", &resp); err != nil {
b.Fatal(err)
}
Expand Down
Loading

0 comments on commit 0673874

Please sign in to comment.