Skip to content

Commit 72a16e5

Browse files
committed
rac2: add in-flight token counter for send tokens
This change is completely mechanical, with the core in the rac2 files: token_counter.go, store_stream.go, metrics.go. The inflight tokens are unused at the moment -- a future PR will use them in rangeController. Informs #155183 Epic: none Release note: None
1 parent 1e00b30 commit 72a16e5

File tree

70 files changed

+1217
-950
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1217
-950
lines changed

docs/generated/metrics/metrics.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12875,6 +12875,22 @@ layers:
1287512875
unit: COUNT
1287612876
aggregation: AVG
1287712877
derivative: NONE
12878+
- name: kvflowcontrol.streams.send.inflight.blocked_count
12879+
exported_name: kvflowcontrol_streams_send_inflight_blocked_count
12880+
description: Number of send replication streams with no flow tokens available for inflight requests
12881+
y_axis_label: Count
12882+
type: GAUGE
12883+
unit: COUNT
12884+
aggregation: AVG
12885+
derivative: NONE
12886+
- name: kvflowcontrol.streams.send.inflight.total_count
12887+
exported_name: kvflowcontrol_streams_send_inflight_total_count
12888+
description: Total number of send replication streams for inflight requests
12889+
y_axis_label: Count
12890+
type: GAUGE
12891+
unit: COUNT
12892+
aggregation: AVG
12893+
derivative: NONE
1287812894
- name: kvflowcontrol.streams.send.regular.blocked_count
1287912895
exported_name: kvflowcontrol_streams_send_regular_blocked_count
1288012896
description: Number of send replication streams with no flow tokens available for regular requests
@@ -13027,6 +13043,46 @@ layers:
1302713043
unit: BYTES
1302813044
aggregation: AVG
1302913045
derivative: NON_NEGATIVE_DERIVATIVE
13046+
- name: kvflowcontrol.tokens.send.inflight.available
13047+
exported_name: kvflowcontrol_tokens_send_inflight_available
13048+
description: Flow send tokens available for inflight requests, across all replication streams
13049+
y_axis_label: Bytes
13050+
type: GAUGE
13051+
unit: BYTES
13052+
aggregation: AVG
13053+
derivative: NONE
13054+
- name: kvflowcontrol.tokens.send.inflight.deducted
13055+
exported_name: kvflowcontrol_tokens_send_inflight_deducted
13056+
description: Flow send tokens deducted by inflight requests, across all replication streams
13057+
y_axis_label: Bytes
13058+
type: COUNTER
13059+
unit: BYTES
13060+
aggregation: AVG
13061+
derivative: NON_NEGATIVE_DERIVATIVE
13062+
- name: kvflowcontrol.tokens.send.inflight.returned
13063+
exported_name: kvflowcontrol_tokens_send_inflight_returned
13064+
description: Flow send tokens returned by inflight requests, across all replication streams
13065+
y_axis_label: Bytes
13066+
type: COUNTER
13067+
unit: BYTES
13068+
aggregation: AVG
13069+
derivative: NON_NEGATIVE_DERIVATIVE
13070+
- name: kvflowcontrol.tokens.send.inflight.returned.disconnect
13071+
exported_name: kvflowcontrol_tokens_send_inflight_returned_disconnect
13072+
description: Flow send tokens returned early by inflight due disconnects, across all replication stream, this is a subset of returned tokens
13073+
y_axis_label: Bytes
13074+
type: COUNTER
13075+
unit: BYTES
13076+
aggregation: AVG
13077+
derivative: NON_NEGATIVE_DERIVATIVE
13078+
- name: kvflowcontrol.tokens.send.inflight.unaccounted
13079+
exported_name: kvflowcontrol_tokens_send_inflight_unaccounted
13080+
description: Flow send tokens returned by inflight requests that were unaccounted for, across all replication streams
13081+
y_axis_label: Bytes
13082+
type: COUNTER
13083+
unit: BYTES
13084+
aggregation: AVG
13085+
derivative: NON_NEGATIVE_DERIVATIVE
1303013086
- name: kvflowcontrol.tokens.send.regular.available
1303113087
exported_name: kvflowcontrol_tokens_send_regular_available
1303213088
description: Flow send tokens available for regular requests, across all replication streams

pkg/kv/kvserver/flow_control_integration_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestFlowControlBasicV2(t *testing.T) {
136136
h.query(n1, `
137137
SELECT name, value
138138
FROM crdb_internal.node_metrics
139-
WHERE name LIKE '%kvflowcontrol%stream%'
139+
WHERE name LIKE '%kvflowcontrol%stream%' AND name NOT LIKE '%inflight%'
140140
ORDER BY name ASC;
141141
`)
142142

@@ -3819,15 +3819,16 @@ var flowPerStoreDeductionQueryHeaderStrs = []string{
38193819
"range_id", "store_id", "priority", "tokens"}
38203820

38213821
// v2FlowTokensQueryStr is the query string to fetch flow tokens metrics from
3822-
// the node metrics table.
3822+
// the node metrics table. We exclude the inflight metrics since they are
3823+
// non-deterministic.
38233824
const v2FlowTokensQueryStr = `
38243825
SELECT
38253826
name,
38263827
crdb_internal.humanize_bytes(value::INT8)
38273828
FROM
38283829
crdb_internal.node_metrics
38293830
WHERE
3830-
name LIKE '%kvflowcontrol%tokens%'
3831+
name LIKE '%kvflowcontrol%tokens%' AND name NOT LIKE '%inflight%'
38313832
ORDER BY
38323833
name ASC;
38333834
`

pkg/kv/kvserver/kvflowcontrol/kvflowcontrol.go

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ var RegularTokensPerStream = settings.RegisterByteSizeSetting(
8585
"kvadmission.flow_controller.regular_tokens_per_stream",
8686
"flow tokens available for regular work on a per-stream basis",
8787
16<<20, // 16 MiB
88-
validateTokenRange,
88+
validateTokenRange(maxTokensPerStream),
8989
)
9090

9191
// ElasticTokensPerStream determines the flow tokens available for elastic work
@@ -95,24 +95,37 @@ var ElasticTokensPerStream = settings.RegisterByteSizeSetting(
9595
"kvadmission.flow_controller.elastic_tokens_per_stream",
9696
"flow tokens available for elastic work on a per-stream basis",
9797
8<<20, // 8 MiB
98-
validateTokenRange,
98+
validateTokenRange(maxTokensPerStream),
99+
)
100+
101+
// InFlightTokensPerStream determines the flow tokens available for inflight
102+
// work on a per-stream basis.
103+
var InFlightTokensPerStream = settings.RegisterByteSizeSetting(
104+
settings.SystemOnly,
105+
"kvadmission.flow_controller.in_flight_tokens_per_stream",
106+
"flow tokens available for in-flight work on a per-stream basis",
107+
64<<20, // 64 MiB
108+
validateTokenRange(maxInFlightTokensPerStream),
99109
)
100110

101111
const (
102-
minTokensPerStream Tokens = 1 << 20 // 1 MiB
103-
maxTokensPerStream Tokens = 64 << 20 // 64 MiB
112+
minTokensPerStream Tokens = 1 << 20 // 1 MiB
113+
maxTokensPerStream Tokens = 64 << 20 // 64 MiB
114+
maxInFlightTokensPerStream = 512 << 20 // 512MiB
104115
)
105116

106-
var validateTokenRange = settings.WithValidateInt(func(b int64) error {
107-
t := Tokens(b)
108-
if t < minTokensPerStream {
109-
return fmt.Errorf("minimum flowed tokens allowed is %s, got %s", minTokensPerStream, t)
110-
}
111-
if t > maxTokensPerStream {
112-
return fmt.Errorf("maximum flow tokens allowed is %s, got %s", maxTokensPerStream, t)
113-
}
114-
return nil
115-
})
117+
func validateTokenRange(maxTokens Tokens) settings.SettingOption {
118+
return settings.WithValidateInt(func(b int64) error {
119+
t := Tokens(b)
120+
if t < minTokensPerStream {
121+
return fmt.Errorf("minimum flowed tokens allowed is %s, got %s", minTokensPerStream, t)
122+
}
123+
if t > maxTokens {
124+
return fmt.Errorf("maximum flow tokens allowed is %s, got %s", maxTokens, t)
125+
}
126+
return nil
127+
})
128+
}
116129

117130
// TokenCounterResetEpoch is an escape hatch for administrators that should
118131
// never be needed. By incrementing this epoch (or changing it to a value

0 commit comments

Comments
 (0)