Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

chainHead: Add support for storage pagination and cancellation #14755

Merged
merged 19 commits into from
Aug 24, 2023

Conversation

lexnv
Copy link
Contributor

@lexnv lexnv commented Aug 11, 2023

This PR adds configurable pagination for the storage query types: DescendantHashes and DescendantValues with the possibility to cancel the operation after the WaitingForContinue event is generated.

  • implement chainHead_unstable_continue method
  • implement chainHead_unstable_stopOperation method
  • add configurable pagination limit after which the WaitingForContinue event is generated
  • iterable storage queries are placed in a queue for providing fairness across multiple queries of the same operation
  • limiter object from chainHead: Limit ongoing operations #14699 is refactored inside an Operations object for better ergonomics
  • registering an operation shares a lock-free state between the backend and frontend for efficient signaling of continue or stop
    • RegisteredOperation object is returned to the backend (chainHead event generation) via the BlockGuard
    • OperationState object is returned to the frontend and has direct user access via chainHead_unstable_continue and chainHead_unstable_stopOperation
  • RegisteredOperation in RAII manner (on drop) releases the capacity permit for the operation and unregisters the operation from the subscription state
  • integration-tests for the continue and stop operations (via check_continue_operation and stop_storage_operation)

Builds on top of: #14699
Closes: #14549
Closes: #14639

// @paritytech/subxt-team

@lexnv lexnv added A0-please_review Pull request needs code review. C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit B1-note_worthy Changes should be noted in the release notes T2-API This PR/Issue is related to APIs. labels Aug 11, 2023
@lexnv lexnv requested review from jsdw and skunert August 11, 2023 11:33
@lexnv lexnv self-assigned this Aug 11, 2023
@lexnv lexnv changed the title chainHead: Add support storage pagination and cancellation chainHead: Add support for storage pagination and cancellation Aug 11, 2023
Base automatically changed from lexnv/chainhead_limits to master August 15, 2023 12:17
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
@@ -36,6 +36,7 @@ tokio = { version = "1.22.0", features = ["sync"] }
array-bytes = "6.1"
log = "0.4.17"
futures-util = { version = "0.3.19", default-features = false }
async-channel = "1.8.0"
Copy link
Member

@niklasad1 niklasad1 Aug 22, 2023

Choose a reason for hiding this comment

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

Can you explain why async-channel is used here?

You already got the futures-channel and tokio sync in the dependency tree so I don't follow why this dependency is introduced as the both tokio and futures-channel provides an API for the stuff you implemented on top of the channel

EDIT: tokio::sync::mpsc creates a buffer with 1 and futures_channel a buffer with 1 + num senders, so I guess you want exactly one here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense! I can't actually remember if I picked the async-channel here since it doesn't require the receiver part to be mutable 🤔

I'll change a bit the API since it's worth not adding extra dependencies, thanks!

Copy link
Member

Choose a reason for hiding this comment

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

ah, didn't notice that :D

.requested_continue
.store(true, std::sync::atomic::Ordering::Release);

let _ = self.recv_continue.recv().await;
Copy link
Member

Choose a reason for hiding this comment

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

what if the channel is closed i.e, returns TrySendError::Closed or can't that happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The sender part of the channel should be around until this RegisteredOperation is dropped, since it object is the only one that can remove the operation from tracking (the operations: Arc<Mutex<HashMap<String, OperationState>>> field), will add a comment :D

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Copy link
Contributor

@skunert skunert left a comment

Choose a reason for hiding this comment

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

Looks nice!

Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

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

👍

@lexnv lexnv merged commit 92633bb into master Aug 24, 2023
49 checks passed
@lexnv lexnv deleted the lexnv/chainhead_pag branch August 24, 2023 11:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B1-note_worthy Changes should be noted in the release notes C1-low PR touches the given topic and has a low impact on builders. D3-trivial 🧸 PR contains trivial changes in a runtime directory that do not require an audit T2-API This PR/Issue is related to APIs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RPC-Spec-V2] Cancel ongoing operations [RPC-Spec-V2] Storage: Add support for pagination
3 participants