-
Notifications
You must be signed in to change notification settings - Fork 209
PHPC-1140: Implement Transactions specification #850
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"releases": { | ||
"40-release": "/home/vagrant/4.0/usr/bin", | ||
"36-release": "/home/vagrant/3.6/usr/bin", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think anything is using this. It was only important as the first version listed under "releases", which made it the default. Now that "40-release" is here, I think we can just remove this. No objections if you want to keep it around, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll leave it for now. |
||
"30-release": "/home/vagrant/3.0/usr/bin" | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
#include "php_array_api.h" | ||
#include "phongo_compat.h" | ||
#include "php_phongo.h" | ||
#include "Session.h" | ||
|
||
#define PHONGO_MANAGER_URI_DEFAULT "mongodb://127.0.0.1/" | ||
|
||
|
@@ -655,11 +656,12 @@ static PHP_METHOD(Manager, selectServer) | |
Returns a new client session */ | ||
static PHP_METHOD(Manager, startSession) | ||
{ | ||
php_phongo_manager_t* intern; | ||
zval* options = NULL; | ||
mongoc_session_opt_t* cs_opts = NULL; | ||
mongoc_client_session_t* cs; | ||
bson_error_t error = { 0 }; | ||
php_phongo_manager_t* intern; | ||
zval* options = NULL; | ||
mongoc_session_opt_t* cs_opts = NULL; | ||
mongoc_client_session_t* cs; | ||
bson_error_t error = { 0 }; | ||
mongoc_transaction_opt_t* txn_opts = NULL; | ||
SUPPRESS_UNUSED_WARNING(return_value_ptr) | ||
SUPPRESS_UNUSED_WARNING(return_value_used) | ||
|
||
|
@@ -669,22 +671,56 @@ static PHP_METHOD(Manager, startSession) | |
return; | ||
} | ||
|
||
if (options && php_array_exists(options, "causalConsistency")) { | ||
if (options && php_array_existsc(options, "causalConsistency")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC this ensures we use |
||
cs_opts = mongoc_session_opts_new(); | ||
mongoc_session_opts_set_causal_consistency(cs_opts, php_array_fetchc_bool(options, "causalConsistency")); | ||
} | ||
|
||
cs = mongoc_client_start_session(intern->client, cs_opts, &error); | ||
if (options && php_array_existsc(options, "defaultTransactionOptions")) { | ||
zval* txn_options = php_array_fetchc(options, "defaultTransactionOptions"); | ||
|
||
if (cs_opts) { | ||
mongoc_session_opts_destroy(cs_opts); | ||
/* Thrown exception and return if the defaultTransactionOptions is not an array */ | ||
if (Z_TYPE_P(txn_options) != IS_ARRAY) { | ||
phongo_throw_exception( | ||
PHONGO_ERROR_INVALID_ARGUMENT TSRMLS_CC, | ||
"Expected \"defaultTransactionOptions\" option to be an array, %s given", | ||
PHONGO_ZVAL_CLASS_OR_TYPE_NAME_P(txn_options) | ||
); | ||
goto cleanup; | ||
} | ||
|
||
/* Parse transaction options */ | ||
txn_opts = php_mongodb_session_parse_transaction_options(txn_options TSRMLS_CC); | ||
|
||
/* If an exception is thrown while parsing, the txn_opts struct is also | ||
* NULL, so no need to free it here */ | ||
if (EG(exception)) { | ||
goto cleanup; | ||
} | ||
|
||
/* If the options are non-empty, add them to the client session opts struct */ | ||
if (txn_opts) { | ||
if (!cs_opts) { | ||
cs_opts = mongoc_session_opts_new(); | ||
} | ||
|
||
mongoc_session_opts_set_default_transaction_opts(cs_opts, txn_opts); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, done. And updated relevant comments. |
||
mongoc_transaction_opts_destroy(txn_opts); | ||
} | ||
} | ||
|
||
cs = mongoc_client_start_session(intern->client, cs_opts, &error); | ||
|
||
if (cs) { | ||
phongo_session_init(return_value, cs TSRMLS_CC); | ||
} else { | ||
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC); | ||
} | ||
|
||
cleanup: | ||
if (cs_opts) { | ||
mongoc_session_opts_destroy(cs_opts); | ||
} | ||
} /* }}} */ | ||
|
||
/* {{{ MongoDB\Driver\Manager function entries */ | ||
|
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.
Relevant: #851
I'm not sure this will be helpful for the transaction tests (pending PHPC-1184), since they require a replica set oplog to exist.
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 am aware of that. But some tests just need a 4.0.0 one to run at, as they don't actually talk to the Database yet. But libmongoc still does the version check with a single server.