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

kvflowcontrol: add store stream token watcher interface #128011

Closed
Tracked by #123509
kvoli opened this issue Jul 31, 2024 · 0 comments · Fixed by #128195
Closed
Tracked by #123509

kvflowcontrol: add store stream token watcher interface #128011

kvoli opened this issue Jul 31, 2024 · 0 comments · Fixed by #128195
Assignees
Labels
A-replication-admission-control-v2 Related to introduction of replication AC v2 C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-kv KV Team

Comments

@kvoli
Copy link
Collaborator

kvoli commented Jul 31, 2024

Define a new interface in kvflowcontrol which supports a similar interface to:

// TokenWaitingHandle is the interface for waiting for positive tokens.
type TokenWaitingHandle interface {
	// WaitChannel is the channel that will be signaled if tokens are possibly
	// available. If signaled, the caller must call
	// TryDeductAndUnblockNextWaiter.
	WaitChannel() <-chan struct{}
	// TryDeductAndUnblockNextWaiter is called to deduct some tokens. The tokens
	// parameter can be zero, when the waiter is only waiting for positive
	// tokens (such as when waiting before eval). granted <= tokens and the
	// tokens that have been deducted. haveTokens is true iff there are tokens
	// available after this grant. When the tokens parameter is zero, granted
	// will be zero, and haveTokens represents whether there were positive
	// tokens. If the caller is unsatisfied with the return values, it can
	// resume waiting using WaitChannel.
	TryDeductAndUnblockNextWaiter(tokens kvflowcontrol.Tokens) (granted kvflowcontrol.Tokens, haveTokens bool)
}

// StoreStreamSendTokensWatcher implements a watcher interface that will use
// at most one goroutine per SendTokenCounter and WorkClass that has no send
// tokens. Replicas (from different ranges) waiting for those tokens will call
// NotifyWhenAvailable to queue up for those send tokens.
type StoreStreamSendTokensWatcher interface {
	// NotifyWhenAvailable queues up for tokens for a given token counter and
	// work class. When tokens are available, tokensGrantedNotification is
	// called. It is the caller's responsibility to call CancelHandle() when
	// tokens are no longer needed, or when the caller is done.
	NotifyWhenAvailable(
		stc TokenCounter,
		wc admissionpb.WorkClass,
		tokensGrantedNotification TokenAvailableNotification,
	) StoreStreamSendTokenHandleID
	// UpdateHandle updates the given handle to watch the given work class,
	// removing it from watching the existing work class, if the work class is
	// different.
	UpdateHandle(handle StoreStreamSendTokenHandleID, wc admissionpb.WorkClass)
	// CancelHandle cancels the given handle, stopping it from being notified
	// when tokens are available.
	CancelHandle(handle StoreStreamSendTokenHandleID)
	// String returns a string representation of the store stream send tokens
	// watcher.
	String() string
}

const InvalidStoreStreamSendTokenHandleID StoreStreamSendTokenHandleID = 0

// TokenAvailableNotification is an interface that is called when tokens are
// available.
type TokenAvailableNotification interface {
	// Notify is called when tokens are available to be granted.
	Notify(context.Context)
}

See https://github.com/sumeerbhola/cockroach/blob/2064b279e95bbd68b0a7898503168d384cd0158c/pkg/kv/kvserver/kvflowcontrol/kvflowconnectedstream/store_stream.go#L142-L192

Jira issue: CRDB-40750

Epic CRDB-37515

@kvoli kvoli added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-replication-admission-control-v2 Related to introduction of replication AC v2 labels Jul 31, 2024
@blathers-crl blathers-crl bot added the T-kv KV Team label Jul 31, 2024
@kvoli kvoli self-assigned this Aug 2, 2024
kvoli added a commit to kvoli/cockroach that referenced this issue Aug 2, 2024
Introduce the `StreamTokenWatcher` interface, which will be used to
watch and be notified when there are tokens available.

Resolves: cockroachdb#128011
Release note: None
kvoli added a commit to kvoli/cockroach that referenced this issue Aug 2, 2024
Introduce the `StreamTokenWatcher` interface, which will be used to
watch and be notified when there are tokens available.

Resolves: cockroachdb#128011
Release note: None
kvoli added a commit to kvoli/cockroach that referenced this issue Aug 5, 2024
Introduce the `StreamTokenWatcher` interface, which will be used to
watch and be notified when there are tokens available.

Resolves: cockroachdb#128011
Release note: None
kvoli added a commit to kvoli/cockroach that referenced this issue Aug 5, 2024
Introduce the `StreamTokenWatcher` interface, which will be used to
watch and be notified when there are tokens available.

Resolves: cockroachdb#128011
Release note: None
kvoli added a commit to kvoli/cockroach that referenced this issue Aug 5, 2024
Introduce the `SendTokenWatcher` interface, which will be used to watch
and be notified when there are elastic send tokens available. It is
intended to be used when a send queue develops and the caller wishes to
be notified of available elastic send tokens, in order to dequeue and
send entries.

Resolves: cockroachdb#128011
Release note: None
kvoli added a commit to kvoli/cockroach that referenced this issue Aug 5, 2024
Introduce the `SendTokenWatcher` interface, which will be used to watch
and be notified when there are elastic send tokens available. It is
intended to be used when a send queue develops and the caller wishes to
be notified of available elastic send tokens, in order to dequeue and
send entries.

`SendTokenWatcherProvider` is also introduced, which will be used to
access `SendTokenWatcher` for a given stream.

Resolves: cockroachdb#128011
Release note: None
craig bot pushed a commit that referenced this issue Aug 5, 2024
128195: kvflowcontrol: introduce v2 flow control core interfaces r=sumeerbhola a=kvoli

Introduce the `TokenCounter` interface, underneath a new package, `rac2`.
The `TokenCounter` will be used by replication flow control v2 in a
similar, but distinct manner from the token buckets in v1. Notably, the
`TokenCounter` supports returning an encapsulated handle that may be
used in waiting for available tokens, `TokenWaitingHandle`.

Resolves: #128014
Release note: None

---

Introduce the `StreamTokenCounterProvider` interface, which will be used
by replication flow control v2 to access the `TokenCounter` for a given
tenant, store stream.

Note the original interface in the v2 prototype included two additional
methods for metrics gathering which are omitted here.

Resolves: #128010
Release note: None

---

Introduce the `StreamTokenWatcher` interface, which will be used to
watch and be notified when there are tokens available.

Resolves: #128011
Release note: None

---

Introduce the `RangeController` interface, which provides flow control
for replication traffic in KV, for a range.

Resolves: #128021
Release note: None

Co-authored-by: Austen McClernon <[email protected]>
@craig craig bot closed this as completed in 76ad720 Aug 5, 2024
@github-project-automation github-project-automation bot moved this to Incoming in KV Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-replication-admission-control-v2 Related to introduction of replication AC v2 C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-kv KV Team
Projects
No open projects
Status: Incoming
Development

Successfully merging a pull request may close this issue.

1 participant