Skip to content

Commit 66ab6c3

Browse files
committed
Merge branch 'v1.5'
2 parents 258f3c6 + 176d6bd commit 66ab6c3

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

src/MongoDB/Session.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ zend_class_entry* php_phongo_session_ce;
3838
return; \
3939
}
4040

41+
static bool php_phongo_topology_is_sharded_cluster(mongoc_client_t* client)
42+
{
43+
mongoc_server_description_t* sd = mongoc_client_select_server(client, true, NULL, NULL);
44+
45+
return (sd && !strcmp(mongoc_server_description_type(sd), php_phongo_server_description_type_map[PHONGO_SERVER_MONGOS].name));
46+
}
47+
4148
static bool php_phongo_session_get_timestamp_parts(zval* obj, uint32_t* timestamp, uint32_t* increment TSRMLS_DC)
4249
{
4350
bool retval = false;
@@ -325,6 +332,11 @@ static PHP_METHOD(Session, startTransaction)
325332
return;
326333
}
327334

335+
if (php_phongo_topology_is_sharded_cluster(mongoc_client_session_get_client(intern->client_session))) {
336+
phongo_throw_exception(PHONGO_ERROR_RUNTIME TSRMLS_CC, "PHP MongoDB driver %s does not support running multi-document transactions on sharded clusters", PHP_MONGODB_VERSION);
337+
return;
338+
}
339+
328340
if (!mongoc_client_session_start_transaction(intern->client_session, txn_options, &error)) {
329341
phongo_throw_exception_from_bson_error_t(&error TSRMLS_CC);
330342
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
MongoDB\Driver\Session::startTransaction() does not support sharded clusters
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_libmongoc_crypto() ?>
6+
<?php skip_if_not_mongos(); ?>
7+
<?php skip_if_server_version('<', '4.0'); ?>
8+
--FILE--
9+
<?php
10+
require_once __DIR__ . "/../utils/basic.inc";
11+
12+
$manager = new MongoDB\Driver\Manager(URI);
13+
$session = $manager->startSession();
14+
15+
echo throws(function() use ($session) {
16+
$session->startTransaction();
17+
}, 'MongoDB\Driver\Exception\RuntimeException'), "\n";
18+
19+
?>
20+
===DONE===
21+
<?php exit(0); ?>
22+
--EXPECTF--
23+
OK: Got MongoDB\Driver\Exception\RuntimeException
24+
PHP MongoDB driver %s does not support running multi-document transactions on sharded clusters
25+
===DONE===

0 commit comments

Comments
 (0)