-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: implemented submit chunking for RFD #0010 #737
Draft
patrickjcasey
wants to merge
1
commit into
main
Choose a base branch
from
patrickjcasey/rfd10-proto-changes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,11 +36,20 @@ fn estimate_size(msg: &PluginQuery) -> usize { | |
} | ||
|
||
pub fn chunk_with_size(msg: PluginQuery, max_est_size: usize) -> Result<Vec<PluginQuery>> { | ||
// Chunking only does something on response objects, mostly because | ||
// we don't have a state to represent "SubmitInProgress" | ||
if msg.state == QueryState::Submit as i32 { | ||
return Ok(vec![msg]); | ||
} | ||
// in_progress_state - the state the PluginQuery is in for all queries in the resulting Vec, | ||
// EXCEPT the last one | ||
// | ||
// completion_state - the state the PluginQuery is in if it is the last chunked message | ||
let (in_progress_state, completion_state) = match msg.state() { | ||
// if the message gets chunked, then it must either be a reply or submission that is in process | ||
QueryState::Unspecified => return Err(anyhow!("msg in Unspecified query state")), | ||
QueryState::SubmitInProgress | QueryState::SubmitComplete => { | ||
(QueryState::SubmitInProgress, QueryState::SubmitComplete) | ||
} | ||
QueryState::ReplyInProgress | QueryState::ReplyComplete => { | ||
(QueryState::ReplyInProgress, QueryState::ReplyComplete) | ||
} | ||
}; | ||
|
||
let mut out: Vec<PluginQuery> = vec![]; | ||
let mut base: PluginQuery = msg; | ||
|
@@ -58,9 +67,9 @@ pub fn chunk_with_size(msg: PluginQuery, max_est_size: usize) -> Result<Vec<Plug | |
// For this loop, we want to take at most MAX_SIZE bytes because that's | ||
// all that can fit in a PluginQuery | ||
let mut remaining = max_est_size; | ||
let mut query = PluginQuery { | ||
let mut chunked_query = PluginQuery { | ||
id: base.id, | ||
state: QueryState::ReplyInProgress as i32, | ||
state: in_progress_state as i32, | ||
publisher_name: base.publisher_name.clone(), | ||
plugin_name: base.plugin_name.clone(), | ||
query_name: base.query_name.clone(), | ||
|
@@ -71,15 +80,15 @@ pub fn chunk_with_size(msg: PluginQuery, max_est_size: usize) -> Result<Vec<Plug | |
|
||
if remaining > 0 && base.key.bytes().len() > 0 { | ||
// steal from key | ||
query.key = drain_at_most_n_bytes(&mut base.key, remaining)?; | ||
remaining -= query.key.bytes().len(); | ||
chunked_query.key = drain_at_most_n_bytes(&mut base.key, remaining)?; | ||
remaining -= chunked_query.key.bytes().len(); | ||
made_progress = true; | ||
} | ||
|
||
if remaining > 0 && base.output.bytes().len() > 0 { | ||
// steal from output | ||
query.output = drain_at_most_n_bytes(&mut base.output, remaining)?; | ||
remaining -= query.output.bytes().len(); | ||
chunked_query.output = drain_at_most_n_bytes(&mut base.output, remaining)?; | ||
remaining -= chunked_query.output.bytes().len(); | ||
made_progress = true; | ||
} | ||
|
||
|
@@ -96,7 +105,7 @@ pub fn chunk_with_size(msg: PluginQuery, max_est_size: usize) -> Result<Vec<Plug | |
} else if c_bytes <= remaining { | ||
// steal this concern | ||
let concern = base.concern.swap_remove(i); | ||
query.concern.push(concern); | ||
chunked_query.concern.push(concern); | ||
remaining -= c_bytes; | ||
made_progress = true; | ||
} | ||
|
@@ -106,9 +115,14 @@ pub fn chunk_with_size(msg: PluginQuery, max_est_size: usize) -> Result<Vec<Plug | |
l -= 1; | ||
} | ||
|
||
out.push(query); | ||
out.push(chunked_query); | ||
} | ||
out.push(base); | ||
|
||
// ensure the last message in the chunked messages is set to the appropriate Complete state | ||
if let Some(last) = out.last_mut() { | ||
last.state = completion_state as i32; | ||
} | ||
Ok(out) | ||
} | ||
|
||
|
@@ -162,7 +176,9 @@ impl QuerySynthesizer { | |
.map_err(|_| Error::UnspecifiedQueryState)?; | ||
match state { | ||
QueryState::Unspecified => return Err(Error::UnspecifiedQueryState), | ||
QueryState::Submit => return Err(Error::ReceivedSubmitWhenExpectingReplyChunk), | ||
QueryState::SubmitInProgress | QueryState::SubmitComplete => { | ||
return Err(Error::ReceivedSubmitWhenExpectingReplyChunk) | ||
} | ||
QueryState::ReplyInProgress | QueryState::ReplyComplete => { | ||
if state == QueryState::ReplyComplete { | ||
raw.state = QueryState::ReplyComplete.into(); | ||
|
@@ -209,23 +225,40 @@ mod test { | |
|
||
#[test] | ||
fn test_chunking() { | ||
let query = PluginQuery { | ||
id: 0, | ||
state: QueryState::ReplyComplete as i32, | ||
publisher_name: "".to_owned(), | ||
plugin_name: "".to_owned(), | ||
query_name: "".to_owned(), | ||
// This key will cause the chunk not to occur on a char boundary | ||
key: "aこれは実験です".to_owned(), | ||
output: "".to_owned(), | ||
concern: vec!["< 10".to_owned(), "0123456789".to_owned()], | ||
}; | ||
let res = match chunk_with_size(query, 10) { | ||
Ok(r) => r, | ||
Err(e) => { | ||
panic!("{e}"); | ||
} | ||
}; | ||
assert_eq!(res.len(), 4); | ||
// test both reply and submission chunking | ||
let states = [ | ||
(QueryState::SubmitInProgress, QueryState::SubmitComplete), | ||
(QueryState::ReplyInProgress, QueryState::ReplyComplete), | ||
]; | ||
|
||
for (intermediate_state, final_state) in states.into_iter() { | ||
let query = PluginQuery { | ||
id: 0, | ||
state: final_state as i32, | ||
publisher_name: "".to_owned(), | ||
plugin_name: "".to_owned(), | ||
query_name: "".to_owned(), | ||
// This key will cause the chunk not to occur on a char boundary | ||
key: "aこれは実験です".to_owned(), | ||
output: "".to_owned(), | ||
concern: vec!["< 10".to_owned(), "0123456789".to_owned()], | ||
}; | ||
let res = match chunk_with_size(query, 10) { | ||
Ok(r) => r, | ||
Err(e) => { | ||
panic!("{e}"); | ||
} | ||
}; | ||
// ensure first 3 are ...InProgress | ||
assert_eq!( | ||
res.iter() | ||
.filter(|x| x.state() == intermediate_state) | ||
.count(), | ||
3 | ||
); | ||
// ensure last one is ...Complete | ||
assert_eq!(res.last().unwrap().state(), final_state); | ||
assert_eq!(res.len(), 4); | ||
} | ||
Comment on lines
+259
to
+262
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure the above |
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the
QuerySynthesizer
needs to be modified as well to support de-chunking chunkedSubmit
queries.