Skip to content
This repository was archived by the owner on Dec 22, 2021. It is now read-only.

Conversation

@phaylon
Copy link
Contributor

@phaylon phaylon commented Mar 22, 2018

Implements PERL-791 "Change stream support"

Overview:

  • Introduces MongoDB::ChangeStream as the reconnecting wrapper around change stream aggregations returned from $collection->watch.
  • Adjusts ::_CommandCursorOp for tailable ::Op::_Aggregate instances.
  • Adjusts ::_Aggregate to deal with maxAwaitTimeMS.
  • Adds watch to ::Collection.
  • Adds MongoDB::InvalidOperationError.
  • Tests for default usage, maxAwaitTimeMS, resumeAfter, fullDocument.

@coveralls
Copy link

coveralls commented Mar 22, 2018

Coverage Status

Coverage decreased (-0.6%) to 81.673% when pulling fa7dde8 on shadow-dot-cat:phaylon/PERL-791-fixed into 08c6ea9 on mongodb:master.

Copy link
Contributor

@xdg xdg left a comment

Choose a reason for hiding this comment

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

I haven't gotten to the tests, yet, but here are the comments on the code. All minor stuff; looks good!


use namespace::clean -except => 'meta';

has _cursor => (
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to call this _result to clearly differentiate it from the legacy cursor type.

init_arg => 'resume_after',
predicate => '_has_resume_token',
lazy => 1,
builder => '_build_resume_token',
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a builder?

required => 1,
);

has options => (
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rename "aggregation_options" to make it clear these are not the exact same as the options passed to watch.

sub _build_cursor {
my ($self) = @_;

my $pipeline = $self->pipeline;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this extraneous?


my $pipeline = $self->pipeline;

my @pipeline = @{ $self->pipeline || [] };
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the || [] isn't necessary anymore given required and the type constraint.

=head1 SYNOPSIS
$stream = $collection->watch( $pipeline, $options );
while (my $change = $stream->next) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please wrap this in an infinite loop with a comment about how the inner loop exits when there are no changes available.

my $stream = $collection->watch( \@pipeline );
my $stream = $collection->watch( \@pipeline, \%options );
while (my $change = $stream->next) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Also wrap in an infinite loop here.

my $options = $self->options;
my $is_2_6 = $link->does_write_commands;

my $query_flags = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this unused?

isa => Num,
);

has cursorType => (
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is unnecessary. For aggregation, if there's maxAwaitTimeMS, then we can conclude that it's a tailable await.

$max_time_ms = $self->maxAwaitTimeMS if $self->maxAwaitTimeMS;
}
elsif ($self->isa('MongoDB::Op::_Aggregate') &&
$self->cursorType eq 'tailable_await') {
Copy link
Contributor

Choose a reason for hiding this comment

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

As I said above, I think it's sufficient to just check if isa MongoDB::Op::_Aggregate (and that maxAwaitTimeMS is true) without an extra cursor_type.

Copy link
Contributor

@xdg xdg left a comment

Choose a reason for hiding this comment

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

The test don't fully cover the spec test cases but those are really complicated to test and I think what we have is good enough. I can verify from inspection that the rest of the code does what it's expected to do.

I have only one more minor request, I think.

notification for partial updates will include both a delta describing the
changes to the document, as well as a copy of the entire document that
was changed from some time after the change occurred.
* C<resumeAfter> - The logical starting point for this change stream.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add to this that it must be the _id from a document returned from calling next on the ChangeStream object.

@phaylon
Copy link
Contributor Author

phaylon commented Mar 29, 2018

@xdg Thanks for the review! All fixes for the issues should now be in the branch.

@xdg
Copy link
Contributor

xdg commented Mar 29, 2018

LGTM. I'll squash and merge. Thanks!

@xdg
Copy link
Contributor

xdg commented Mar 29, 2018

Squashed and merged as f7b8339

@xdg xdg closed this Mar 29, 2018
@TBSliver TBSliver deleted the phaylon/PERL-791-fixed branch June 13, 2019 14:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants