-
Notifications
You must be signed in to change notification settings - Fork 100
PERL-912/PERL-936 #166
PERL-912/PERL-936 #166
Conversation
xdg
left a comment
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.
Looks like a great start! As a general point, I'd like to have the ChangeStreams.pm "_op_args" only be the cached _op_args fields from Collection (and the manually assembled equivalents in Database and MongoClient). All the watch API specific arguments and options should be in private variables. You'll see some notes to that effect in my comments.
lib/MongoDB/ChangeStream.pm
Outdated
| ArrayOfHashRef | ||
| ); | ||
| use Types::Standard qw( | ||
| Bool |
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.
Please use "Boolish" from MongoDB::_Types instead here and everywhere else instead, as it handles overloaded objects in a way the built-ins don't.
lib/MongoDB/ChangeStream.pm
Outdated
| use Types::Standard qw( | ||
| Bool | ||
| InstanceOf | ||
| Int |
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.
Ditto Intish
lib/MongoDB/ChangeStream.pm
Outdated
|
|
||
| has start_at_operation_time => ( | ||
| is => 'ro', | ||
| isa => Maybe[Int], |
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.
This is going to need to be a BSON::Timestamp, not Int, so that users can pass in the BSON::Timestamp they get back from session operation time.
It should also be private
lib/MongoDB/Collection.pm
Outdated
| C<startAtOperationTime> | ||
| * C<maxAwaitTimeMS> - The maximum number of milliseconds for the server | ||
| to wait before responding. | ||
| * C<startAtOperationTime> - A timestamp specifying at what point in time |
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.
clarify that this should be a BSON::Timestamp
lib/MongoDB/Collection.pm
Outdated
|
|
||
| my $session = $self->_get_session_from_hashref( $options ); | ||
|
|
||
| # boolify some options |
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.
Don't need these for change streams
lib/MongoDB/ChangeStream.pm
Outdated
| isa => MongoDBCollection, | ||
| ); | ||
|
|
||
| has pipeline => ( |
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.
On reflection, pipeline and full_document should be private, too. The only public method (other than the constructor) should be next.
lib/MongoDB/ChangeStream.pm
Outdated
| has _op_args => ( | ||
| is => 'ro', | ||
| isa => HashRef, | ||
| default => sub { {} }, |
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.
This needs to be required without a default.
lib/MongoDB/ChangeStream.pm
Outdated
| pipeline => $self->pipeline, | ||
| all_changes_for_cluster => $self->all_changes_for_cluster, | ||
| changes_received => $self->_changes_received, | ||
| defined($self->start_at_operation_time) |
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 wonder if this should use _has_start_at_operation_time for consistency with resume token. Think again about it, but I'm not set on it if there is a good reason to check for definedness.
lib/MongoDB/Op/_ChangeStream.pm
Outdated
| my @pipeline = ( | ||
| {'$changeStream' => { | ||
| (defined($start_op_time) | ||
| ? (startAtOperationTime => BSON::Timestamp->new( |
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.
If we make startAtOperationTime a BSON::Timestamp then this conversion isn't needed.
lib/MongoDB/Op/_ChangeStream.pm
Outdated
|
|
||
| # For explain, we give the whole response as fields have changed in | ||
| # different server versions | ||
| if ( $options->{explain} ) { |
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.
dont' need explain
xdg
left a comment
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.
One minor nit. Otherwise LGTM. Thanks!
lib/MongoDB/ChangeStream.pm
Outdated
| init_arg => 'start_at_operation_time', | ||
| predicate => '_has_start_at_operation_time', | ||
| coerce => sub { | ||
| ref($_[0]) ? $_[0] : BSON::Timestamp->new($_[0]) |
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.
If you're wanting to allow seconds, I'd prefer to have this be BSON::Timestamp->new( seconds => $_[0]) rather than relying on BUILDARGS to fix up the legacy constructor format.
|
Rebased and merged. |
Note: This includes code for the fallback of
startAtOperationTime, but disables it because:Resume of change stream was not possible, as the resume point may no longer be in the oplogOtherwise this PR includes the following changes:
Op::_ChangeStreamas adapted version ofOp::_AggregateMongoDB::ChangeStreamuse the newOpfor command construction logicstartAtOperationTime(with disabled fallback, see above)t/changestream_spec.twatchmethods to::Databaseand::MongoClientsessionas recognized option to thewatchmethods