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

chain: ShardManager: add ability to serve partial chunks from ShardChunk #6377

Merged
merged 16 commits into from
Mar 9, 2022

Conversation

mina86
Copy link
Contributor

@mina86 mina86 commented Mar 2, 2022

Add ability to respond to PartialEncodedChunkRequest from ShardChunk
objects in addition to PartialEncodedChunk. In practice this is currently
dead code since there is no scenario in which the former is in the storage
while the latter isn’t but the plan is to start garbage collecting
ColPartialChunks column at which point we’ll have to serve requests from
data in ColChunks column.

Issue: #6242

Add ability to respond to PartialEncodedChunkRequest from ShardChunk
objects in addition to PartialEncodedChunk.  In practice this is currently
dead code since there is no scenario in which the former is in the storage
while the latter isn’t but the plan is to start garbage collecting
ColPartialChunks column at which point we’ll have to serve requests from
data in ColChunks column.

Issue: #6242
mm-near
mm-near previously requested changes Mar 3, 2022
@@ -1075,6 +1089,136 @@ impl ShardsManager {
)
}

fn prepare_partial_encoded_chunk_response_from_chunk(
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we should move it to a separate file (to keep this lib.rs a little bit smaller?)

Copy link
Contributor Author

@mina86 mina86 Mar 3, 2022

Choose a reason for hiding this comment

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

It’s not immediately obvious to be me what should be moved to separate file though to be honest. Code that handles partial encoded chunk requests is less than 250 lines so moving just it wouldn’t really help reduce the size of lib.rs which is 2700 lines. This would need some more care and thought to figure out which of the methods in the struct belong together in a separate file.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I don't think this makes sense to move to a separate file, as it seems to be pretty entangled with the rest.

The easiest wins in terms of keeping files small and logic clean are usually around various small helpers. Things like RequestPool or SealsManager seem like better candidates for extraction.

chain/chunks/src/lib.rs Outdated Show resolved Hide resolved
chain/chunks/src/lib.rs Show resolved Hide resolved
) {
debug!(target: "chunks", "Received partial encoded chunk request for {:?}, part_ordinals: {:?}, shards: {:?}, I'm {:?}", request.chunk_hash.0, request.part_ords, request.tracking_shards, self.me);

let response = if let Some(entry) = self.encoded_chunks.get(&request.chunk_hash) {
Self::prepare_partial_encoded_chunk_response_from_cache(request, entry)
} else if let Ok(partial_chunk) = chain_store.get_partial_chunk(&request.chunk_hash) {
Self::prepare_partial_encoded_chunk_response_from_partial(request, partial_chunk)
} else if let Ok(chunk) = chain_store.get_chunk(&request.chunk_hash).map(|ch| ch.clone()) {
// Note: we need to clone the chunk because otherwise we would be
Copy link
Contributor

Choose a reason for hiding this comment

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

we should have metrics for all 3 cases here (can be done in separate PR)

@mina86 mina86 dismissed mm-near’s stale review March 5, 2022 05:48

Comments addressed.

Copy link
Contributor

@mzhangmzz mzhangmzz left a comment

Choose a reason for hiding this comment

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

I agree with Marcin that we want to have some measurement of how long it takes to process a partial encode chunk part request by reconstructing the chunk parts, since it might not be cheap. Another question we need to answer after we have the measurement is whether we want to cache the results for some time, since the node requesting for these parts may resend the request again.

chain/chunks/src/lib.rs Outdated Show resolved Hide resolved
chain/chunks/src/lib.rs Outdated Show resolved Hide resolved
chain/chunks/src/lib.rs Outdated Show resolved Hide resolved
@mina86 mina86 requested review from mm-near and mzhangmzz March 8, 2022 03:01
@@ -33,3 +34,4 @@ assert_matches = "1.5.0"
[features]
byzantine_asserts = ["near-chain/byzantine_asserts"]
expensive_tests = []
test_features = []
Copy link
Contributor

Choose a reason for hiding this comment

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

comment. Also maybe we should call it 'reconstruct_partial_chunk_on_the_fly' or something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’m planning to make GCing a configurable feature.

chain/chunks/src/lib.rs Outdated Show resolved Hide resolved
chain/chunks/Cargo.toml Outdated Show resolved Hide resolved
chain/chunks/src/lib.rs Show resolved Hide resolved
chain/chunks/src/lib.rs Outdated Show resolved Hide resolved
chain/chunks/src/lib.rs Outdated Show resolved Hide resolved
chain/chunks/src/lib.rs Outdated Show resolved Hide resolved
chain/chunks/src/lib.rs Outdated Show resolved Hide resolved
chain/chunks/src/lib.rs Show resolved Hide resolved
core/primitives/src/sharding.rs Show resolved Hide resolved
integration-tests/Cargo.toml Outdated Show resolved Hide resolved
chain/chunks-primitives/src/error.rs Outdated Show resolved Hide resolved
chain/chunks/src/lib.rs Outdated Show resolved Hide resolved
@mina86 mina86 merged commit 09041ec into master Mar 9, 2022
@mina86 mina86 deleted the mpn-a branch March 9, 2022 20:28
mina86 added a commit to mina86/nearcore that referenced this pull request Apr 7, 2022
…unk (near#6377)

This is commit 09041ec upstream.

Add ability to respond to PartialEncodedChunkRequest from ShardChunk
objects in addition to PartialEncodedChunk.  In practice this is currently
dead code since there is no scenario in which the former is in the storage
while the latter isn’t but the plan is to start garbage collecting
ColPartialChunks column at which point we’ll have to serve requests from
data in ColChunks column.

Issue: near#6242
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.

4 participants