Skip to content

Conversation

derickr
Copy link
Contributor

@derickr derickr commented Jul 17, 2018

@derickr derickr requested a review from jmikola July 17, 2018 13:03
@@ -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)
Copy link
Member

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.

Copy link
Contributor Author

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...

Copy link
Member

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().

return;
}

RETURN_BOOL(!!mongoc_client_session_in_transaction(intern->client_session));
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the !!.

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)
Copy link
Member

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.

Copy link
Contributor Author

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()
Copy link
Member

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.

Copy link
Contributor Author

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.

@derickr derickr force-pushed the PHPC-1231-session-is-in-transaction branch from 52fc511 to 3493de9 Compare July 17, 2018 15:57
Copy link
Contributor Author

@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.

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)
Copy link
Contributor Author

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...

return;
}

RETURN_BOOL(!!mongoc_client_session_in_transaction(intern->client_session));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the !!.

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)
Copy link
Contributor Author

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()
Copy link
Contributor Author

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());
Copy link
Member

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.

@derickr derickr force-pushed the PHPC-1231-session-is-in-transaction branch from 3493de9 to a917c35 Compare July 17, 2018 16:09
@derickr derickr merged commit a917c35 into mongodb:master Jul 17, 2018
derickr added a commit that referenced this pull request Jul 17, 2018
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