-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit provides a new implementation of systemStatusServer.SpanS…
…tats, proposed in #84105. The goal is to provide accurate table/index stats since the assumption that 1 range can contain at most 1 table/index no longer holds. Part of: https://cockroachlabs.atlassian.net/browse/CRDB-22711 Release note: None add interface and abstract away access to KV rename accessor implementation
- Loading branch information
Zach Lite
committed
Feb 1, 2023
1 parent
e402d82
commit 69b6714
Showing
22 changed files
with
650 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("//build/bazelutil/unused_checker:unused.bzl", "get_x_data") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "spanstats", | ||
srcs = ["span_stats.go"], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvclient/spanstats", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/roachpb", | ||
"//pkg/server/serverpb", | ||
], | ||
) | ||
|
||
get_x_data(name = "get_x_data") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package spanstats | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/server/serverpb" | ||
) | ||
|
||
// Accessor mediates access to SpanStats by consumers across the KV/Tenant | ||
// boundary. | ||
type Accessor interface { | ||
|
||
// SpanStats returns the span stats between startKey and endKey. | ||
// The caller can request span stats from across the cluster by setting | ||
// nodeId to 0. The caller can request span stats from a specific node by | ||
// setting the value of nodeID accordingly. | ||
SpanStats( | ||
ctx context.Context, | ||
startKey, | ||
endKey roachpb.Key, | ||
nodeID roachpb.NodeID, | ||
) (*serverpb.InternalSpanStatsResponse, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
load("//build/bazelutil/unused_checker:unused.bzl", "get_x_data") | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "spanstatsaccessor", | ||
srcs = ["accessor.go"], | ||
importpath = "github.com/cockroachdb/cockroach/pkg/kv/kvclient/spanstats/spanstatsaccessor", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//pkg/roachpb", | ||
"//pkg/server/serverpb", | ||
], | ||
) | ||
|
||
get_x_data(name = "get_x_data") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package spanstatsaccessor | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/roachpb" | ||
"github.com/cockroachdb/cockroach/pkg/server/serverpb" | ||
) | ||
|
||
// LocalAccessor is an implementation of spanstats.Accessor that is meant | ||
// to provide access to span span stats to servers that are co-located on the KV | ||
// node. | ||
type LocalAccessor struct { | ||
spanStatsServer serverpb.SpanStatsServer | ||
} | ||
|
||
// New returns a new instance of AccessorImpl. | ||
func New(server serverpb.SpanStatsServer) *LocalAccessor { | ||
return &LocalAccessor{spanStatsServer: server} | ||
} | ||
|
||
// SpanStats implements the spanstats.Accessor interface. | ||
func (a *LocalAccessor) SpanStats( | ||
ctx context.Context, startKey, | ||
endKey roachpb.Key, nodeID roachpb.NodeID, | ||
) (*serverpb.InternalSpanStatsResponse, error) { | ||
|
||
res, err := a.spanStatsServer.GetSpanStats(ctx, | ||
&serverpb.InternalSpanStatsRequest{ | ||
Span: roachpb.Span{ | ||
Key: startKey, | ||
EndKey: endKey, | ||
}, | ||
NodeID: nodeID, | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.