forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kvclient, server: implement SpanStats for use with coalesced ranges
This commit provides a re-implementation of fetching the MVCC stats and range count for a given span. The previous implementation relied on the assumption that 1 range can contain at most 1 table/index. Since cockroachdbGH-79700, this assumption is no longer true. This re-implementation has three components. The first is spanstats.Accessor, which provides an interface for accessing span stats from KV. The second is spanstatsaccessor.LocalAccessor, which provides an implementation of the interface for callers that are co-located on a KV node. The third is an implementation by kvtenantccl.Connector, which provides an implementation of the interface for non co-located callers, like SQL pods. The interaction between these components is illustrated below: System Tenant +----------------------------------------------------+ | | | | | KV Node fan-out | | +----------+ | | | | | | +-------------------------------v----+ | | | | | | | | | serverpb.InternalSpanStatsServer +-----+ | | | | | | +----------------+-------------------+ | | | | | roachpb.InternalSpanStatsResponse | | | | | | | | v | | +----------------------------------+ | | | | | | | spanstatsaccessor.LocalAccessor | | | | | | | +-----------------+----------------+ | | | | | +---------------------+ | | roachpb.InternalSpanStatsResponse | | | | | | | v v | | +-------------------------+ +-----------+ | | | | | | | | | serverpb.StatusServer | | SQLServer | | | | | | | | | +------------+------------+ +-----------+ | | | | | | | +----------------------+-----------------------------+ | | serverpb.SpanStatsResponse | | | | | Secondary Tenant | +----------------------+------------------------------+ | | | | +------------v-------------+ | | | | | | | kvtenantccl.Connector | | | | | | | +------------+-------------+ | | | | | | | | +--------------------+ | | roachpb.InternalSpanStatsResponse| | | | | | | | | | | +-----------------v-------+ +------v------+ | | | | | | | | | serverpb.StatusServer | | SQLServer | | | | | | | | | +-------------------------+ +-------------+ | | | | | | | +-----------------------------------------------------+ Resolves cockroachdb#84105 Part of: https://cockroachlabs.atlassian.net/browse/CRDB-22711 Release note (backward-incompatible change): The SpanStatsRequest message field 'node_id' has changed from type 'string' to type 'int32'.
- Loading branch information
Zach Lite
committed
Feb 7, 2023
1 parent
9444613
commit 0516358
Showing
31 changed files
with
706 additions
and
240 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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"], | ||
) | ||
|
||
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,32 @@ | ||
// 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" | ||
) | ||
|
||
// 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, | ||
) (*roachpb.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,51 @@ | ||
// 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 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 stats to servers that are co-located on the KV | ||
// node. | ||
type LocalAccessor struct { | ||
spanStatsServer serverpb.InternalSpanStatsServer | ||
} | ||
|
||
// New returns a new instance of AccessorImpl. | ||
func New(server serverpb.InternalSpanStatsServer) *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, | ||
) (*roachpb.InternalSpanStatsResponse, error) { | ||
res, err := a.spanStatsServer.GetSpanStatsInternal(ctx, | ||
&roachpb.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/cockroachdb/cockroach/pkg/roachpb | ||
|
||
go 1.19 |
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,35 @@ | ||
// 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. | ||
|
||
syntax = "proto3"; | ||
package cockroach.roachpb; | ||
option go_package = "roachpb"; | ||
|
||
import "roachpb/data.proto"; | ||
import "storage/enginepb/mvcc.proto"; | ||
import "gogoproto/gogo.proto"; | ||
import "google/api/annotations.proto"; | ||
|
||
// InternalSpanStatsRequest | ||
message InternalSpanStatsRequest { | ||
Span span = 1 [(gogoproto.nullable) = false]; | ||
|
||
// A node_id of `0` indicates the server should issue a fan-out to all nodes. | ||
int32 node_id = 2 [(gogoproto.customname) = "NodeID", | ||
(gogoproto.casttype) = "NodeID"]; | ||
} | ||
|
||
// InternalSpanStatsResponse | ||
message InternalSpanStatsResponse { | ||
int32 range_count = 2; | ||
uint64 approximate_disk_bytes = 3; | ||
cockroach.storage.enginepb.MVCCStats total_stats = 1 | ||
[ (gogoproto.nullable) = false ]; | ||
} |
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.