-
Notifications
You must be signed in to change notification settings - Fork 209
PHPC-1231: Add Session::isInTransaction to indicate whether a transaction is active #882
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
PHPC-1231: Add Session::isInTransaction to indicate whether a transaction is active #882
Conversation
@@ -390,6 +390,24 @@ static PHP_METHOD(Session, endSession) | |||
mongoc_client_session_destroy(intern->client_session); | |||
} /* }}} */ | |||
|
|||
/* {{{ proto void MongoDB\Driver\Session::isInTransaction(void) | |||
Returns whether a multi-document transaction is in progress */ | |||
static PHP_METHOD(Session, isInTransaction) |
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 method name looks strange to me, but I think it's preferable to the more verbose option of isTransactionInProgress()
or the like.
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.
Change it to inTransaction
? Don't like that much either...
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 didn't want to suggest inTransaction
because it's not consistent with prefixing boolean-returning methods with "is". Totally OK with sticking with isInTransaction()
.
src/MongoDB/Session.c
Outdated
return; | ||
} | ||
|
||
RETURN_BOOL(!!mongoc_client_session_in_transaction(intern->client_session)); |
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.
Is the quick bool cast with !!
necessary? The function returns a bool
and _mongoc_client_session_in_txn()
uses true
and false
return values.
I would imagine there are a few other places where we trust libmongoc's bool
return values.
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.
Removed the !!
.
src/MongoDB/Session.c
Outdated
PHP_ME(Session, advanceClusterTime, ai_Session_advanceClusterTime, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) | ||
PHP_ME(Session, advanceOperationTime, ai_Session_advanceOperationTime, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) | ||
PHP_ME(Session, commitTransaction, ai_Session_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) | ||
PHP_ME(Session, endSession, ai_Session_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) | ||
PHP_ME(Session, isInTransaction, ai_Session_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) |
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.
Since it looks like you're alphabetizing these, isInTransaction
should go after the get
methods.
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.
Yeah, I had alphabetised them in the first commit, ... and then put the new one in the wrong place :-)
@@ -0,0 +1,36 @@ | |||
--TEST-- | |||
MongoDB\Driver\Session::isInTransaction() |
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 think this test would do well to cover both the "started" and "in progress" transaction states. At the moment, I believe it only covers "started", which is before the first command is sent. See test_in_transaction()
for a good example. Ideally, we should just port that to a PHP test.
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.
Our test was basically that test already, but I added two sections that actually have an operation in the transaction too.
52fc511
to
3493de9
Compare
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.
Updated
@@ -390,6 +390,24 @@ static PHP_METHOD(Session, endSession) | |||
mongoc_client_session_destroy(intern->client_session); | |||
} /* }}} */ | |||
|
|||
/* {{{ proto void MongoDB\Driver\Session::isInTransaction(void) | |||
Returns whether a multi-document transaction is in progress */ | |||
static PHP_METHOD(Session, isInTransaction) |
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.
Change it to inTransaction
? Don't like that much either...
src/MongoDB/Session.c
Outdated
return; | ||
} | ||
|
||
RETURN_BOOL(!!mongoc_client_session_in_transaction(intern->client_session)); |
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.
Removed the !!
.
src/MongoDB/Session.c
Outdated
PHP_ME(Session, advanceClusterTime, ai_Session_advanceClusterTime, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) | ||
PHP_ME(Session, advanceOperationTime, ai_Session_advanceOperationTime, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) | ||
PHP_ME(Session, commitTransaction, ai_Session_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) | ||
PHP_ME(Session, endSession, ai_Session_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) | ||
PHP_ME(Session, isInTransaction, ai_Session_void, ZEND_ACC_PUBLIC | ZEND_ACC_FINAL) |
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.
Yeah, I had alphabetised them in the first commit, ... and then put the new one in the wrong place :-)
@@ -0,0 +1,36 @@ | |||
--TEST-- | |||
MongoDB\Driver\Session::isInTransaction() |
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.
Our test was basically that test already, but I added two sections that actually have an operation in the transaction too.
$session->startTransaction(); | ||
var_dump($session->isInTransaction()); | ||
$session->commitTransaction(); | ||
var_dump($session->isInTransaction()); |
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.
Given that transactions are started lazily during the first command, how does this interact when the only operation is an abort or commit? I assume the driver is still sending something in this case and the server just registers it as a no-op?
Perhaps a question for @ShaneHarvey.
3493de9
to
a917c35
Compare
https://jira.mongodb.org/browse/PHPC-1231