Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvserver,inspectz: add rac2 inspectz support #130270

Merged
merged 5 commits into from
Sep 12, 2024

Conversation

kvoli
Copy link
Collaborator

@kvoli kvoli commented Sep 6, 2024

The existing flow control tables are:

crdb_internal.kv_flow_controller
crdb_internal.kv_flow_control_handles
crdb_internal.kv_flow_token_deductions

Which are used in testing to assert on flow control stream state and
transitions.

Introduce another set of three tables, most of which are identical to the
exsting tables but populating the table data using rac2.

crdb_internal.kv_flow_controller_v2
crdb_internal.kv_flow_control_handles_v2
crdb_internal.kv_flow_token_deductions_v2

crdb_internal.kv_flow_controller_v2 has two additional columns,
tracking the amount of available (regular|elastic) send tokens. The
schema is:

CREATE TABLE crdb_internal.kv_flow_controller_v2 (
  tenant_id                     INT NOT NULL,
  store_id                      INT NOT NULL,
  available_eval_regular_tokens INT NOT NULL,
  available_eval_elastic_tokens INT NOT NULL,
  available_send_regular_tokens INT NOT NULL,
  available_send_elastic_tokens INT NOT NULL
);

Note that unless rac2 is enabled, the tables are unlikely to show
anything interesting. Both tables (v1 and v2) are kept for
compatibility, with an intent to replace the v1 tables with the v2 ones
after v1 replication flow control is removed entirely from the code.

Resolves: #128091
Release note: None

@kvoli kvoli self-assigned this Sep 6, 2024
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@kvoli kvoli force-pushed the 240906.rac-inspectz branch 7 times, most recently from 2505725 to 2ddb17f Compare September 9, 2024 18:28
Copy link

blathers-crl bot commented Sep 9, 2024

Your pull request contains more than 1000 changes. It is strongly encouraged to split big PRs into smaller chunks.

🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

@kvoli kvoli force-pushed the 240906.rac-inspectz branch 2 times, most recently from b8a8599 to eadf9a4 Compare September 9, 2024 19:11
@kvoli kvoli changed the title .*: [dnm] instrument rac2 inspectz kvserver,inspectz: add rac2 inspectz support Sep 9, 2024
@kvoli kvoli force-pushed the 240906.rac-inspectz branch from eadf9a4 to 1d7082d Compare September 9, 2024 21:30
@kvoli kvoli requested a review from sumeerbhola September 9, 2024 21:31
@kvoli
Copy link
Collaborator Author

kvoli commented Sep 9, 2024

Failure is from some missing crdb_internal datadriven test updates, I'll sort these out. Should be ready for a look.

@kvoli kvoli marked this pull request as ready for review September 9, 2024 21:31
@kvoli kvoli requested review from a team as code owners September 9, 2024 21:31
Copy link
Collaborator

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 6 of 6 files at r1, 13 of 13 files at r2, 7 of 7 files at r3, 4 of 4 files at r4, 4 of 4 files at r5, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @kvoli)


-- commits line 29 at r2:
nit: deductions.


-- commits line 83 at r5:
nit: existing


pkg/inspectz/inspectz.go line 148 at r4 (raw file):

// KVFlowHandlesV2 implements the InspectzServer interface.
func (s *Server) KVFlowHandlesV2(

This seems the same as Server.KVFlowHandles except for using handlesV2. Can this be unified into one function?


pkg/kv/kvserver/kvflowcontrol/kvflowcontrol.go line 323 at r3 (raw file):

	// Inspect returns the set of ranges that have an embedded
	// kvflowcontrol.Handle. It's used to power /inspectz.
	Inspect() []roachpb.RangeID

Now that we have a specialized lookup method for the inspectz path, do we need LookupInspect to return an InspectHandle or can we simply make it return (kvflowinspectpb.Handle, bool)?


pkg/kv/kvserver/kvflowcontrol/kvflowinspectpb/kvflowinspect.proto line 84 at r1 (raw file):

// Stream represents a given kvflowcontrol.Stream and the number of tokens
// available for it (as maintained by the node-level kvflowcontrol.Controller,
// or in >= v25.1, by the node level StreamTokenCounterProvider).

v24.3?


pkg/kv/kvserver/kvflowcontrol/kvflowinspectpb/kvflowinspect.proto line 93 at r1 (raw file):

    (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.StoreID"];
  // AvailableEvalRegularTokens represents the currently available tokens for
  // regular replication traffic, deducted before evaluation.

should this say "deducted for evaluation"?
(we don't actually deduct them before evaluation)


pkg/kv/kvserver/kvflowcontrol/rac2/range_controller.go line 422 at r2 (raw file):

func (rc *rangeController) Inspect(ctx context.Context) kvflowinspectpb.Handle {
	rc.mu.Lock()
	defer rc.mu.Unlock()

rc.mu does not protect replicaMap, IIRC.
We are relying on external synchronization, specifically raftMu for this.

As mentioned in https://cockroachlabs.slack.com/archives/C06UFBJ743F/p1726018900176919?thread_ts=1726008270.371049&cid=C06UFBJ743F, I think it is acceptable to rename this InspectRaftMuLocked and have the caller acquire raftMu. The higher latency is fine for inspectz and querying the internal tables.


pkg/kv/kvserver/kvflowcontrol/rac2/store_stream.go line 112 at r2 (raw file):

	slices.SortFunc(streams, func(a, b kvflowinspectpb.Stream) int { // for determinism
		return cmp.Or(
			cmp.Compare(a.TenantID.ToUint64(), b.TenantID.ToUint64()),

is there a reason this is sorting the tuple (tenant-id, store-id), while rangeController.Inspect is sorting (store-id, tenant-id)?


pkg/server/server.go line 1134 at r4 (raw file):

		cfg.BaseConfig.AmbientCtx,
		node.storeCfg.KVFlowHandles,
		kvserver.MakeStoresForRACv2(stores),

It just happens that MakeStoresForRACv2 is casting stores and does not have some additional state, so calling MakeStoresForRACv2 a second time does not accidentally create a second object when it is expected to be a singleton. We shouldn't rely on this. I think we already have storesForRACv2 as a local variable from earlier in this function, and should use it here.


pkg/kv/kvserver/kvflowcontrol/rac2/testdata/range_controller/inspect line 224 at r2 (raw file):


# Change the replica on s3 to StateSnapshot. This should untrack all entries
# and result in the stream token counts being updated accordingly.

I think we should not consider s3 to have a connected stream. Currently the code does

		if rs.sendStream == nil {
			continue
		}

and since it was in StateReplicate and transitioned to StateSnapshot we still have the replicaSendStream and print the state below. Up to you whether you want to change this now, or wait until the equivalent of #130168 where all transitions to StateSnapshot close the replicaSendStream.

@kvoli kvoli force-pushed the 240906.rac-inspectz branch from 1d7082d to 24e0156 Compare September 12, 2024 15:51
Copy link
Collaborator Author

@kvoli kvoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TYFTR! Addressed the comments, ptal.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @kvoli and @sumeerbhola)


-- commits line 29 at r2:

Previously, sumeerbhola wrote…

nit: deductions.

Updated.


-- commits line 83 at r5:

Previously, sumeerbhola wrote…

nit: existing

Updated.


pkg/inspectz/inspectz.go line 148 at r4 (raw file):

Previously, sumeerbhola wrote…

This seems the same as Server.KVFlowHandles except for using handlesV2. Can this be unified into one function?

We need to have both methods for the internal tables to call. I've simplified the logic however to unify the logic into a function.


pkg/kv/kvserver/kvflowcontrol/kvflowcontrol.go line 323 at r3 (raw file):

Previously, sumeerbhola wrote…

Now that we have a specialized lookup method for the inspectz path, do we need LookupInspect to return an InspectHandle or can we simply make it return (kvflowinspectpb.Handle, bool)?

We can, updated.


pkg/kv/kvserver/kvflowcontrol/kvflowinspectpb/kvflowinspect.proto line 84 at r1 (raw file):

Previously, sumeerbhola wrote…

v24.3?

Should be v24.3, I've mixed these up a few times w/ the innovation release.


pkg/kv/kvserver/kvflowcontrol/kvflowinspectpb/kvflowinspect.proto line 93 at r1 (raw file):

Previously, sumeerbhola wrote…

should this say "deducted for evaluation"?
(we don't actually deduct them before evaluation)

It should. Updated.


pkg/kv/kvserver/kvflowcontrol/rac2/range_controller.go line 422 at r2 (raw file):

Previously, sumeerbhola wrote…

rc.mu does not protect replicaMap, IIRC.
We are relying on external synchronization, specifically raftMu for this.

As mentioned in https://cockroachlabs.slack.com/archives/C06UFBJ743F/p1726018900176919?thread_ts=1726008270.371049&cid=C06UFBJ743F, I think it is acceptable to rename this InspectRaftMuLocked and have the caller acquire raftMu. The higher latency is fine for inspectz and querying the internal tables.

It doesn't. Updated the method naming and removed the locking.


pkg/kv/kvserver/kvflowcontrol/rac2/store_stream.go line 112 at r2 (raw file):

Previously, sumeerbhola wrote…

is there a reason this is sorting the tuple (tenant-id, store-id), while rangeController.Inspect is sorting (store-id, tenant-id)?

There is no reason. I've updated rangeController to sort on tenant, store.


pkg/server/server.go line 1134 at r4 (raw file):

Previously, sumeerbhola wrote…

It just happens that MakeStoresForRACv2 is casting stores and does not have some additional state, so calling MakeStoresForRACv2 a second time does not accidentally create a second object when it is expected to be a singleton. We shouldn't rely on this. I think we already have storesForRACv2 as a local variable from earlier in this function, and should use it here.

Updated to use the local var.


pkg/kv/kvserver/kvflowcontrol/rac2/testdata/range_controller/inspect line 224 at r2 (raw file):

Previously, sumeerbhola wrote…

I think we should not consider s3 to have a connected stream. Currently the code does

		if rs.sendStream == nil {
			continue
		}

and since it was in StateReplicate and transitioned to StateSnapshot we still have the replicaSendStream and print the state below. Up to you whether you want to change this now, or wait until the equivalent of #130168 where all transitions to StateSnapshot close the replicaSendStream.

I'll wait until the equivalent of #130168, you're right it shouldn't be included.

@kvoli kvoli force-pushed the 240906.rac-inspectz branch 2 times, most recently from 8d178a9 to a003dc5 Compare September 12, 2024 17:09
@kvoli kvoli requested review from a team as code owners September 12, 2024 17:09
@kvoli kvoli requested review from xinhaoz and removed request for a team September 12, 2024 17:09
@kvoli kvoli removed request for a team, xinhaoz, arjunmahishi and aa-joshi September 12, 2024 18:55
Copy link
Collaborator

@sumeerbhola sumeerbhola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 27 files at r6, 5 of 16 files at r7, 6 of 9 files at r8, 3 of 4 files at r9, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @kvoli)


pkg/inspectz/inspectz.go line 115 at r10 (raw file):

	ctx context.Context, request *kvflowinspectpb.ControllerRequest,
) (*kvflowinspectpb.ControllerResponse, error) {
	return &kvflowinspectpb.ControllerResponse{

can this use the kvFlowController method?

@kvoli kvoli force-pushed the 240906.rac-inspectz branch 2 times, most recently from 79c4cee to e0dd39e Compare September 12, 2024 21:12
@kvoli kvoli requested a review from a team as a code owner September 12, 2024 21:12
@kvoli kvoli requested review from mw5h and removed request for a team September 12, 2024 21:12
@kvoli kvoli force-pushed the 240906.rac-inspectz branch from e0dd39e to 2023936 Compare September 12, 2024 21:13
Copy link
Collaborator Author

@kvoli kvoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TYFTR! I pushed a few more test file changes related to the new internal tables to appease logic tests which are affected.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @mw5h and @sumeerbhola)


pkg/inspectz/inspectz.go line 115 at r10 (raw file):

Previously, sumeerbhola wrote…

can this use the kvFlowController method?

It can, I missed it. Done.

@kvoli kvoli force-pushed the 240906.rac-inspectz branch from 2023936 to 3aa33df Compare September 12, 2024 21:24
@kvoli
Copy link
Collaborator Author

kvoli commented Sep 12, 2024

bors r=sumeerbhola

@craig
Copy link
Contributor

craig bot commented Sep 12, 2024

Build failed:

@kvoli
Copy link
Collaborator Author

kvoli commented Sep 12, 2024

bors r-

@kvoli
Copy link
Collaborator Author

kvoli commented Sep 12, 2024

Merge skew, going to rebase and go again.

The `kvflowinspectpb.Stream` represents a replication stream state and
is used in tests and `inspectz` related observability.

`kvflowinspectpb.Stream` used to contain two available token fields,
broken into work class. As rac2 is being added, two additional token
fields are required, accounting for send tokens.

Rename the existing fields with `Eval` added and introduce two more
fields, mirroring the existing ones as `Send`.

Part of: cockroachdb#128091
Release note: None
Implement `Inspect` methods on the `RangeController`, `TokenTracker` and
`StreamTokenCounterProvider`. These methods will be used to power the
`inspectz` endpoint (mostly unused) and `crdb_internal` tables
(primarily testing).

`RangeController.Inspect` returns a `kvflowinspectpb.Handle`, identical
to the `Handle` abstraction in v1, containing all streams and their
token deductions/state.

`TokenTracker.Inspect` returns the tracked deductions.

`StreamTokenCounterProvider.Inspect` returns the token state of all
streams, where `StreamTokenCounterProvider.InspectStream` returns the
token state of the given stream.

Part of: cockroachdb#128091
Release note: None
The previous patch introduced `Inspect` methods mapping to `Handle`,
`ConnectedStream`, `TrackedDeduction` and `Stream`. Extract the
`Inspect` methods into their own interfaces which are implemented by
rac2.

The methods are then hooked into `storesForRAC2`, which can be accessed
in a similar manner to the v1 methods.

Part of: cockroachdb#128091
Release note: None
Rename the existing `inspectz/(kvflowhandles|kvflowcontroller)` endpoint
to `inspectz/v1/(kvflowhandles|kvflowcontroller)`, and introduce the v2
endpoint serving the same types,
`inspectz/v2/(kvflowhandles|kvflowcontroller)`.

Note that these endpoints are not used internally in any webpages or
testing and are not relied upon. Internal tables call
`KVFlowHandles(V1)` or `KVFlowController(V1)` directly to populate
themselves.

Part of: cockroachdb#128091
Release note: None
The existing flow control tables are:

```
crdb_internal.kv_flow_controller
crdb_internal.kv_flow_control_handles
crdb_internal.kv_flow_token_deductions
```

Which are used in testing to assert on flow control stream state and
transitions.

Introduce another set of three tables, most of which are identical to
the existing tables but populating the table data using rac2.

```
crdb_internal.kv_flow_controller_v2
crdb_internal.kv_flow_control_handles_v2
crdb_internal.kv_flow_token_deductions_v2
```

`crdb_internal.kv_flow_controller_v2` has two additional columns,
tracking the amount of available (regular|elastic) send tokens. The
schema is:

```
CREATE TABLE crdb_internal.kv_flow_controller_v2 (
  tenant_id                     INT NOT NULL,
  store_id                      INT NOT NULL,
  available_eval_regular_tokens INT NOT NULL,
  available_eval_elastic_tokens INT NOT NULL,
  available_send_regular_tokens INT NOT NULL,
  available_send_elastic_tokens INT NOT NULL
);
```

Note that unless rac2 is enabled, the tables are unlikely to show
anything interesting. Both tables (v1 and v2) are kept for
compatibility, with an intent to replace the v1 tables with the v2 ones
after v1 replication flow control is removed entirely from the code.

Resolves: cockroachdb#128091
Release note: None
@kvoli kvoli force-pushed the 240906.rac-inspectz branch from 3aa33df to c0a5058 Compare September 12, 2024 22:37
@kvoli
Copy link
Collaborator Author

kvoli commented Sep 12, 2024

bors r=sumeerbhola

@craig craig bot merged commit 66ff432 into cockroachdb:master Sep 12, 2024
23 checks passed
msbutler pushed a commit to msbutler/cockroach that referenced this pull request Sep 13, 2024
130270: kvserver,inspectz: add rac2 inspectz support  r=sumeerbhola a=kvoli

The existing flow control tables are:

```
crdb_internal.kv_flow_controller
crdb_internal.kv_flow_control_handles
crdb_internal.kv_flow_token_deductions
```

Which are used in testing to assert on flow control stream state and
transitions.

Introduce another set of three tables, most of which are identical to the
exsting tables but populating the table data using rac2.

```
crdb_internal.kv_flow_controller_v2
crdb_internal.kv_flow_control_handles_v2
crdb_internal.kv_flow_token_deductions_v2
```

`crdb_internal.kv_flow_controller_v2` has two additional columns,
tracking the amount of available (regular|elastic) send tokens. The
schema is:

```
CREATE TABLE crdb_internal.kv_flow_controller_v2 (
  tenant_id                     INT NOT NULL,
  store_id                      INT NOT NULL,
  available_eval_regular_tokens INT NOT NULL,
  available_eval_elastic_tokens INT NOT NULL,
  available_send_regular_tokens INT NOT NULL,
  available_send_elastic_tokens INT NOT NULL
);
```

Note that unless rac2 is enabled, the tables are unlikely to show
anything interesting. Both tables (v1 and v2) are kept for
compatibility, with an intent to replace the v1 tables with the v2 ones
after v1 replication flow control is removed entirely from the code.

Resolves: cockroachdb#128091
Release note: None

Co-authored-by: Austen McClernon <[email protected]>
@msbutler
Copy link
Collaborator

@kvoli it looks like this pr modified the crdb_internal_catalog logic test to verify the schema of every crdb_internal vtable. what was the motivation for adding this check? I ask because now every time anybody updates a crdb_internal table (which my team at least does all the time), they need to rewrite this test, which is a minor annoyance and could lead to merge conflicts.

@kvoli
Copy link
Collaborator Author

kvoli commented Sep 25, 2024

@msbutler that was unintentional, I assumed it was necessary from gleaning other PRs but from your message I am guessing thats not correct. We can and should remove it if its causing inconvenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kvflowcontrol: add inspectz pages for replication ac v2
4 participants