Skip to content

Conversation

jmikola
Copy link
Member

@jmikola jmikola commented Dec 19, 2017

@jmikola jmikola changed the title [WIP] PHPC-987: Casually consistent reads PHPC-987: Casually consistent reads Dec 19, 2017
@jmikola jmikola requested a review from derickr December 19, 2017 23:39
Copy link
Contributor

@derickr derickr left a comment

Choose a reason for hiding this comment

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

Fails to compile on PHP 5 with zts: https://travis-ci.org/mongodb/mongo-php-driver/jobs/318906532#L1550

On PHP 7 there is a test failure: https://travis-ci.org/mongodb/mongo-php-driver/jobs/318906525#L1933

Please fix the commit message, there is nothing casual about this (it's causally).

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm uncomfortable with calling methods through the PHP/Zend layer here. Is there no other way to obtain the timestamp?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can certainly add logic to check for a Timestamp object and access these properties directly without invoking methods, and will do so.

That said, there is no other solution if we're dealing with a non-Timestamp TimestampInterface.

In my testing, if the getTimestamp() throws, getIncrement() is never even called. This may be the result of logic inside zend_call_method that no-ops if a previous call failed or an exception has already been thrown. I still found that a bit odd, as here I am invoking zend_call_method twice without logic in-between. If you're more comfortable with it, I can also split up those calls and check for errors between them, instead of a combined check for undefined ztimestamp and zincrement down below.

Copy link
Contributor

Choose a reason for hiding this comment

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

As this goes through zend_execute, I expected that the throw would abort further calls. I think it's better to check for EG(exception) in between. But you're right on the non-Timestamp TimestampInterface. I now believe you shouldn't short-cut it as an exception for "Timestamp" too.

Copy link
Member Author

Choose a reason for hiding this comment

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

The IS_UNDEF check was inspired by what I saw in zend_interfaces.c:

I actually think the best approach is checking for (Z_TYPE(retval) == IS_UNDEF || EG(exception)), as is done in the last example (zend_user_serialize).

I personally don't see any harm in optimizing for the common use case (Timestamp instance), and simply forgot to make that change before I last updated this PR. I'll leave it out for now given your feedback, but we can always add it in later if you change your mind.

@jmikola
Copy link
Member Author

jmikola commented Dec 20, 2017

Fails to compile on PHP 5 with zts. On PHP 7 there is a test failure.

I'll look into the test failures and revise. This was admittedly pushed up for review as I was headed out the door last night (wanted you to see something before this morning), so I can't say I'm surprised.

@jmikola jmikola force-pushed the phpc-987 branch 2 times, most recently from 3971fbc to d33158f Compare December 20, 2017 21:18
Copy link
Contributor

@derickr derickr left a comment

Choose a reason for hiding this comment

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

I'm sorta lgtm on this, I wouldn't want to hold up the comment about calling methods through the Zend layer for getTimestamp/getIncrement. But I do think it's not a nice way of doing it. But probably better than a short-cut, and I've no idea right now how to do this better.

Copy link
Contributor

Choose a reason for hiding this comment

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

As this goes through zend_execute, I expected that the throw would abort further calls. I think it's better to check for EG(exception) in between. But you're right on the non-Timestamp TimestampInterface. I now believe you shouldn't short-cut it as an exception for "Timestamp" too.

@jmikola jmikola changed the title PHPC-987: Casually consistent reads PHPC-987: Causally consistent reads Dec 21, 2017
@jmikola jmikola merged commit d99153b into mongodb:master Dec 21, 2017
jmikola added a commit that referenced this pull request Dec 21, 2017
@jmikola jmikola deleted the phpc-987 branch December 21, 2017 03:39
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.

2 participants