-
Notifications
You must be signed in to change notification settings - Fork 180
RUST-521 Implement naive streaming and resume token caching for change streams #531
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
Merged
abr-egn
merged 27 commits into
mongodb:master
from
abr-egn:RUST-521/change-stream-stream
Dec 15, 2021
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
629774b
session with_type
abr-egn 2557955
resume_token
abr-egn 15d93c9
initial resume token
abr-egn e4819a3
execute_watch helper
abr-egn 7bbc26c
initial resume token
abr-egn f2bb095
rustfmt
abr-egn 49ecb29
execute_watch_with_session
abr-egn 18da865
populate initial resume token only when buffer is empty
abr-egn 9fb7e48
shift resume token to cursor
abr-egn 8211cfb
use RawDocumentBuf for token
abr-egn 2ca6f9d
populate resume token from getmore response
abr-egn 58684d5
cache token when yielding values
abr-egn 0eb841e
use RawBson for resume token
abr-egn 98cba67
clippy
abr-egn d69d3e6
factor out cursor buffer polling
abr-egn 62e0d02
move resume token tracking to change stream
abr-egn 67b420f
fix lost field from rebase
abr-egn b5081ec
common utility for poll_next impl
abr-egn 9cf8eb5
next_in_batch
abr-egn 5d11cee
clean up resume token extraction
abr-egn cdcb246
session machinery
abr-egn fb522fa
session next_in_batch
abr-egn b3108f3
documentation
abr-egn 451424b
rustfmt
abr-egn f7ef6e2
clippy
abr-egn b45f321
better ResumeToken::initial
abr-egn 225695b
still alive
abr-egn 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 hidden or 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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
//! Contains the types related to a `ChangeStream` event. | ||
use crate::coll::Namespace; | ||
use bson::{Bson, Document}; | ||
use std::convert::TryInto; | ||
|
||
use crate::{ | ||
coll::Namespace, | ||
cursor::CursorSpecification, | ||
error::Result, | ||
options::ChangeStreamOptions, | ||
}; | ||
|
||
use bson::{Bson, Document, RawBson, RawDocument, RawDocumentBuf}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// An opaque token used for resuming an interrupted | ||
|
@@ -15,7 +23,28 @@ use serde::{Deserialize, Serialize}; | |
/// [here](https://docs.mongodb.com/manual/changeStreams/#change-stream-resume-token) for more | ||
/// information on resume tokens. | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct ResumeToken(pub(crate) Bson); | ||
pub struct ResumeToken(pub(crate) RawBson); | ||
|
||
impl ResumeToken { | ||
pub(crate) fn initial( | ||
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. nit: can we update this so that both values don't always need to be created? e.g.
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. That's much nicer, thank you! |
||
options: &Option<ChangeStreamOptions>, | ||
spec: &CursorSpecification, | ||
) -> Option<ResumeToken> { | ||
match &spec.post_batch_resume_token { | ||
// Token from initial response from `aggregate` | ||
Some(token) if spec.initial_buffer.is_empty() => Some(token.clone()), | ||
// Token from options passed to `watch` | ||
_ => options | ||
.as_ref() | ||
.and_then(|o| o.start_after.as_ref().or_else(|| o.resume_after.as_ref())) | ||
.cloned(), | ||
} | ||
} | ||
|
||
pub(crate) fn from_raw(doc: Option<RawDocumentBuf>) -> Option<ResumeToken> { | ||
doc.map(|doc| ResumeToken(RawBson::Document(doc))) | ||
} | ||
} | ||
|
||
/// A `ChangeStreamEvent` represents a | ||
/// [change event](https://docs.mongodb.com/manual/reference/change-events/) in the associated change stream. | ||
|
This file contains hidden or 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 hidden or 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.
Using
RawBson
here means the token can be essentially handled as a (nearly) uninterpreted byte blob.