Skip to content

Commit 0c9f44f

Browse files
craig[bot]dterikgrinaker
committed
107120: server,storage: breakdown byte counts in SpanStats by backing storage r=dt a=dt Release note: none. Epic: none. 107248: rpc: deflake `TestInitialHeartbeatFailedError` r=erikgrinaker a=erikgrinaker Resolves cockroachdb#107245. Epic: none Release note: None Co-authored-by: David Taylor <[email protected]> Co-authored-by: Erik Grinaker <[email protected]>
3 parents f26d46c + c404e88 + 72ccc26 commit 0c9f44f

File tree

9 files changed

+54
-21
lines changed

9 files changed

+54
-21
lines changed

pkg/cli/debug.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ func runDebugCompact(cmd *cobra.Command, args []string) error {
936936
}
937937

938938
{
939-
approxBytesBefore, err := db.ApproximateDiskBytes(roachpb.KeyMin, roachpb.KeyMax)
939+
approxBytesBefore, _, _, err := db.ApproximateDiskBytes(roachpb.KeyMin, roachpb.KeyMax)
940940
if err != nil {
941941
return errors.Wrap(err, "while computing approximate size before compaction")
942942
}
@@ -966,7 +966,7 @@ func runDebugCompact(cmd *cobra.Command, args []string) error {
966966
fmt.Printf("%s\n", db.GetMetrics())
967967

968968
{
969-
approxBytesAfter, err := db.ApproximateDiskBytes(roachpb.KeyMin, roachpb.KeyMax)
969+
approxBytesAfter, _, _, err := db.ApproximateDiskBytes(roachpb.KeyMin, roachpb.KeyMax)
970970
if err != nil {
971971
return errors.Wrap(err, "while computing approximate size after compaction")
972972
}

pkg/kv/kvserver/replica.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2336,7 +2336,8 @@ func (r *Replica) GetEngineCapacity() (roachpb.StoreCapacity, error) {
23362336
// GetApproximateDiskBytes returns an approximate measure of bytes in the store
23372337
// in the specified key range.
23382338
func (r *Replica) GetApproximateDiskBytes(from, to roachpb.Key) (uint64, error) {
2339-
return r.store.TODOEngine().ApproximateDiskBytes(from, to)
2339+
bytes, _, _, err := r.store.TODOEngine().ApproximateDiskBytes(from, to)
2340+
return bytes, err
23402341
}
23412342

23422343
func init() {

pkg/roachpb/span_stats.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,10 @@ var RangeDescPageSize = settings.RegisterIntSetting(
5656
return nil
5757
},
5858
)
59+
60+
func (m *SpanStats) Add(other *SpanStats) {
61+
m.TotalStats.Add(other.TotalStats)
62+
m.ApproximateDiskBytes += other.ApproximateDiskBytes
63+
m.RemoteFileBytes += other.RemoteFileBytes
64+
m.ExternalFileBytes += other.ExternalFileBytes
65+
}

pkg/roachpb/span_stats.proto

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,29 @@ message SpanStats {
4343
// range end, will have a range_count value of 1.
4444
int32 range_count = 2;
4545

46-
// The explicit jsontag prevents 'omitempty` from being added by default.
46+
// ApproximateDiskBytes is the approximate size "on-disk" in all files of the
47+
// data in the span. NB; this *includes* files stored remotely, not just on
48+
// _local_ disk; see the RemoteFileBytes field below.
49+
// NB: The explicit jsontag prevents 'omitempty` from being added by default.
4750
uint64 approximate_disk_bytes = 3 [(gogoproto.jsontag) = "approximate_disk_bytes"];
51+
52+
// RemoteFileBytes is the subset of ApproximateDiskBytes which are stored in
53+
// "remote" files (i.e. shared files and external files).
54+
uint64 remote_file_bytes = 5;
55+
56+
// ExternalFileBytes is the subset of RemoteFileBytes that are in "external"
57+
// files (not written/owned by this cluster, such as in restored backups).
58+
uint64 external_file_bytes = 6;
59+
60+
// NEXT ID: 7.
4861
}
4962

5063
message SpanStatsResponse {
51-
cockroach.storage.enginepb.MVCCStats total_stats = 1 [(gogoproto.nullable) = false];
52-
// See the range_count comment for the SpanStats proto.
53-
int32 range_count = 2;
54-
uint64 approximate_disk_bytes = 3;
64+
reserved 1;
65+
reserved 2;
66+
reserved 3;
67+
5568
map<string, SpanStats> span_to_stats = 4;
69+
70+
// NEXT ID: 5.
5671
}

pkg/rpc/context_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,7 +2556,9 @@ func TestInitialHeartbeatFailedError(t *testing.T) {
25562556
_, err = clientCtx.GRPCDialNode(remoteAddr, nodeID, SystemClass).Connect(ctx)
25572557
requireHeartbeatError(t, err)
25582558

2559-
// Start server listener.
2559+
// Start server listener. We set the ping handler to fail initially, to make
2560+
// sure no other actor creates an RPC connection.
2561+
failPing.Store(true)
25602562
s := newTestServer(t, serverCtx)
25612563
RegisterHeartbeatServer(s, &HeartbeatService{
25622564
clock: clock,
@@ -2582,10 +2584,12 @@ func TestInitialHeartbeatFailedError(t *testing.T) {
25822584
failPing.Store(true)
25832585
_, err = clientCtx.GRPCDialNode(remoteAddr, nodeID, SystemClass).Connect(ctx)
25842586
requireHeartbeatError(t, err)
2585-
failPing.Store(false)
25862587

2587-
// Stalled pings result in InitialHeartbeatFailedError.
2588+
// Stalled pings result in InitialHeartbeatFailedError. We're careful to
2589+
// enable the hang before disabling the error, to make sure no other
2590+
// actor establishes a connection in the meanwhile.
25882591
hangPing.Store(true)
2592+
failPing.Store(false)
25892593
_, err = clientCtx.GRPCDialNode(remoteAddr, nodeID, SystemClass).Connect(ctx)
25902594
requireHeartbeatError(t, err)
25912595
hangPing.Store(false)

pkg/server/span_stats_server.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ func (s *systemStatusServer) spanStatsFanOut(
8585
if !exists {
8686
res.SpanToStats[spanStr] = spanStats
8787
} else {
88-
res.SpanToStats[spanStr].ApproximateDiskBytes += spanStats.ApproximateDiskBytes
89-
res.SpanToStats[spanStr].TotalStats.Add(spanStats.TotalStats)
88+
res.SpanToStats[spanStr].Add(spanStats)
9089
}
9190
}
9291
}
@@ -218,11 +217,13 @@ func (s *systemStatusServer) statsForSpan(
218217
}
219218
// Finally, get the approximate disk bytes from each store.
220219
err = s.stores.VisitStores(func(store *kvserver.Store) error {
221-
approxDiskBytes, err := store.TODOEngine().ApproximateDiskBytes(rSpan.Key.AsRawKey(), rSpan.EndKey.AsRawKey())
220+
approxDiskBytes, remoteBytes, externalBytes, err := store.TODOEngine().ApproximateDiskBytes(rSpan.Key.AsRawKey(), rSpan.EndKey.AsRawKey())
222221
if err != nil {
223222
return err
224223
}
225224
spanStats.ApproximateDiskBytes += approxDiskBytes
225+
spanStats.RemoteFileBytes += remoteBytes
226+
spanStats.ExternalFileBytes += externalBytes
226227
return nil
227228
})
228229

pkg/storage/engine.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -988,8 +988,11 @@ type Engine interface {
988988
// When called, it may choose to block if the engine determines that it is in
989989
// or approaching a state where further ingestions may risk its health.
990990
PreIngestDelay(ctx context.Context)
991-
// ApproximateDiskBytes returns an approximation of the on-disk size for the given key span.
992-
ApproximateDiskBytes(from, to roachpb.Key) (uint64, error)
991+
// ApproximateDiskBytes returns an approximation of the on-disk size and file
992+
// counts for the given key span, along with how many of those bytes are on
993+
// remote, as well as specifically external remote, storage.
994+
ApproximateDiskBytes(from, to roachpb.Key) (total, remote, external uint64, _ error)
995+
993996
// CompactRange ensures that the specified range of key value pairs is
994997
// optimized for space efficiency.
995998
CompactRange(start, end roachpb.Key) error

pkg/storage/pebble.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,14 +2040,16 @@ func (p *Pebble) GetTableMetrics(start, end roachpb.Key) ([]enginepb.SSTableMetr
20402040
}
20412041

20422042
// ApproximateDiskBytes implements the Engine interface.
2043-
func (p *Pebble) ApproximateDiskBytes(from, to roachpb.Key) (uint64, error) {
2043+
func (p *Pebble) ApproximateDiskBytes(
2044+
from, to roachpb.Key,
2045+
) (bytes, remoteBytes, externalBytes uint64, _ error) {
20442046
fromEncoded := EngineKey{Key: from}.Encode()
20452047
toEncoded := EngineKey{Key: to}.Encode()
2046-
count, err := p.db.EstimateDiskUsage(fromEncoded, toEncoded)
2048+
bytes, remoteBytes, externalBytes, err := p.db.EstimateDiskUsageByBackingType(fromEncoded, toEncoded)
20472049
if err != nil {
2048-
return 0, err
2050+
return 0, 0, 0, err
20492051
}
2050-
return count, nil
2052+
return bytes, remoteBytes, externalBytes, nil
20512053
}
20522054

20532055
// Compact implements the Engine interface.

pkg/storage/pebble_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ func TestApproximateDiskBytes(t *testing.T) {
13741374
require.NoError(t, p.Flush())
13751375

13761376
approxBytes := func(span roachpb.Span) uint64 {
1377-
v, err := p.ApproximateDiskBytes(span.Key, span.EndKey)
1377+
v, _, _, err := p.ApproximateDiskBytes(span.Key, span.EndKey)
13781378
require.NoError(t, err)
13791379
t.Logf("%s (%x-%x): %d bytes", span, span.Key, span.EndKey, v)
13801380
return v

0 commit comments

Comments
 (0)