Skip to content

Commit ac49353

Browse files
authored
PHPC-1761: Snapshot Reads (#1243)
* Bump libmongoc to 1.19-dev * PHPC-1890: Constant for ReadConcern snapshot level * Move Manager::startSession() error test and delete obsolete test The deleted error test was redundant. It was originally created in ca4c52e to work around changes in PHP 8, but 60febd0 subsequently reintroduced a portable version of the test case. Also adds missing SKIPIF to startSession test. * PHPC-1889: Session snapshot option * PHPC-1875: Session with snapshot=true cannot perform writes * PHPC-1876: Session with snapshot=true requires MongoDB 5.0+
1 parent 2848ddd commit ac49353

26 files changed

+240
-30
lines changed

config.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ if test "$PHP_MONGODB" != "no"; then
387387
PHP_MONGODB_JSONSL_SOURCES="jsonsl.c"
388388

389389
dnl Generated with: find src/libmongoc/src/libmongoc/src/mongoc -name '*.c' -print0 | cut -sz -d / -f 7- | sort -dz | tr '\000' ' '
390-
PHP_MONGODB_MONGOC_SOURCES="mongoc-aggregate.c mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-change-stream.c mongoc-client.c mongoc-client-pool.c mongoc-client-session.c mongoc-client-side-encryption.c mongoc-cluster-aws.c mongoc-cluster.c mongoc-cluster-cyrus.c mongoc-cluster-sasl.c mongoc-cluster-sspi.c mongoc-cmd.c mongoc-collection.c mongoc-compression.c mongoc-counters.c mongoc-crypt.c mongoc-crypto.c mongoc-crypto-cng.c mongoc-crypto-common-crypto.c mongoc-crypto-openssl.c mongoc-cursor-array.c mongoc-cursor.c mongoc-cursor-change-stream.c mongoc-cursor-cmd.c mongoc-cursor-cmd-deprecated.c mongoc-cursor-find.c mongoc-cursor-find-cmd.c mongoc-cursor-find-opquery.c mongoc-cursor-legacy.c mongoc-cyrus.c mongoc-database.c mongoc-error.c mongoc-find-and-modify.c mongoc-gridfs-bucket.c mongoc-gridfs-bucket-file.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-handshake.c mongoc-host-list.c mongoc-http.c mongoc-index.c mongoc-init.c mongoc-interrupt.c mongoc-libressl.c mongoc-linux-distro-scanner.c mongoc-list.c mongoc-log.c mongoc-matcher.c mongoc-matcher-op.c mongoc-memcmp.c mongoc-ocsp-cache.c mongoc-openssl.c mongoc-optional.c mongoc-opts.c mongoc-opts-helpers.c mongoc-queue.c mongoc-rand-cng.c mongoc-rand-common-crypto.c mongoc-rand-openssl.c mongoc-read-concern.c mongoc-read-prefs.c mongoc-rpc.c mongoc-sasl.c mongoc-scram.c mongoc-secure-channel.c mongoc-secure-transport.c mongoc-server-api.c mongoc-server-description.c mongoc-server-monitor.c mongoc-server-stream.c mongoc-set.c mongoc-socket.c mongoc-ssl.c mongoc-sspi.c mongoc-stream-buffered.c mongoc-stream.c mongoc-stream-file.c mongoc-stream-gridfs.c mongoc-stream-gridfs-download.c mongoc-stream-gridfs-upload.c mongoc-stream-socket.c mongoc-stream-tls.c mongoc-stream-tls-libressl.c mongoc-stream-tls-openssl-bio.c mongoc-stream-tls-openssl.c mongoc-stream-tls-secure-channel.c mongoc-stream-tls-secure-transport.c mongoc-timeout.c mongoc-topology-background-monitoring.c mongoc-topology.c mongoc-topology-description-apm.c mongoc-topology-description.c mongoc-topology-scanner.c mongoc-uri.c mongoc-util.c mongoc-version-functions.c mongoc-write-command.c mongoc-write-command-legacy.c mongoc-write-concern.c"
390+
PHP_MONGODB_MONGOC_SOURCES="mongoc-aggregate.c mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-change-stream.c mongoc-client.c mongoc-client-pool.c mongoc-client-session.c mongoc-client-side-encryption.c mongoc-cluster-aws.c mongoc-cluster.c mongoc-cluster-cyrus.c mongoc-cluster-sasl.c mongoc-cluster-sspi.c mongoc-cmd.c mongoc-collection.c mongoc-compression.c mongoc-counters.c mongoc-crypt.c mongoc-crypto.c mongoc-crypto-cng.c mongoc-crypto-common-crypto.c mongoc-crypto-openssl.c mongoc-cursor-array.c mongoc-cursor.c mongoc-cursor-change-stream.c mongoc-cursor-cmd.c mongoc-cursor-cmd-deprecated.c mongoc-cursor-find.c mongoc-cursor-find-cmd.c mongoc-cursor-find-opquery.c mongoc-cursor-legacy.c mongoc-cyrus.c mongoc-database.c mongoc-error.c mongoc-find-and-modify.c mongoc-generation-map.c mongoc-gridfs-bucket.c mongoc-gridfs-bucket-file.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-handshake.c mongoc-host-list.c mongoc-http.c mongoc-index.c mongoc-init.c mongoc-interrupt.c mongoc-libressl.c mongoc-linux-distro-scanner.c mongoc-list.c mongoc-log.c mongoc-matcher.c mongoc-matcher-op.c mongoc-memcmp.c mongoc-ocsp-cache.c mongoc-openssl.c mongoc-optional.c mongoc-opts.c mongoc-opts-helpers.c mongoc-queue.c mongoc-rand-cng.c mongoc-rand-common-crypto.c mongoc-rand-openssl.c mongoc-read-concern.c mongoc-read-prefs.c mongoc-rpc.c mongoc-sasl.c mongoc-scram.c mongoc-secure-channel.c mongoc-secure-transport.c mongoc-server-api.c mongoc-server-description.c mongoc-server-monitor.c mongoc-server-stream.c mongoc-set.c mongoc-socket.c mongoc-ssl.c mongoc-sspi.c mongoc-stream-buffered.c mongoc-stream.c mongoc-stream-file.c mongoc-stream-gridfs.c mongoc-stream-gridfs-download.c mongoc-stream-gridfs-upload.c mongoc-stream-socket.c mongoc-stream-tls.c mongoc-stream-tls-libressl.c mongoc-stream-tls-openssl-bio.c mongoc-stream-tls-openssl.c mongoc-stream-tls-secure-channel.c mongoc-stream-tls-secure-transport.c mongoc-timeout.c mongoc-topology-background-monitoring.c mongoc-topology.c mongoc-topology-description-apm.c mongoc-topology-description.c mongoc-topology-scanner.c mongoc-uri.c mongoc-util.c mongoc-version-functions.c mongoc-write-command.c mongoc-write-command-legacy.c mongoc-write-concern.c"
391391

392392
dnl Generated with: find src/libmongoc/src/zlib-1.2.11 -maxdepth 1 -name '*.c' -print0 | cut -sz -d / -f 5- | sort -dz | tr '\000' ' '
393393
PHP_MONGODB_ZLIB_SOURCES="adler32.c compress.c crc32.c deflate.c gzclose.c gzlib.c gzread.c gzwrite.c infback.c inffast.c inflate.c inftrees.c trees.c uncompr.c zutil.c"

config.w32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ if (PHP_MONGODB != "no") {
115115
var PHP_MONGODB_JSONSL_SOURCES="jsonsl.c";
116116

117117
// Generated with: find src/libmongoc/src/libmongoc/src/mongoc -name '*.c' -print0 | cut -sz -d / -f 7- | sort -dz | tr '\000' ' '
118-
var PHP_MONGODB_MONGOC_SOURCES="mongoc-aggregate.c mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-change-stream.c mongoc-client.c mongoc-client-pool.c mongoc-client-session.c mongoc-client-side-encryption.c mongoc-cluster-aws.c mongoc-cluster.c mongoc-cluster-cyrus.c mongoc-cluster-sasl.c mongoc-cluster-sspi.c mongoc-cmd.c mongoc-collection.c mongoc-compression.c mongoc-counters.c mongoc-crypt.c mongoc-crypto.c mongoc-crypto-cng.c mongoc-crypto-common-crypto.c mongoc-crypto-openssl.c mongoc-cursor-array.c mongoc-cursor.c mongoc-cursor-change-stream.c mongoc-cursor-cmd.c mongoc-cursor-cmd-deprecated.c mongoc-cursor-find.c mongoc-cursor-find-cmd.c mongoc-cursor-find-opquery.c mongoc-cursor-legacy.c mongoc-cyrus.c mongoc-database.c mongoc-error.c mongoc-find-and-modify.c mongoc-gridfs-bucket.c mongoc-gridfs-bucket-file.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-handshake.c mongoc-host-list.c mongoc-http.c mongoc-index.c mongoc-init.c mongoc-interrupt.c mongoc-libressl.c mongoc-linux-distro-scanner.c mongoc-list.c mongoc-log.c mongoc-matcher.c mongoc-matcher-op.c mongoc-memcmp.c mongoc-ocsp-cache.c mongoc-openssl.c mongoc-optional.c mongoc-opts.c mongoc-opts-helpers.c mongoc-queue.c mongoc-rand-cng.c mongoc-rand-common-crypto.c mongoc-rand-openssl.c mongoc-read-concern.c mongoc-read-prefs.c mongoc-rpc.c mongoc-sasl.c mongoc-scram.c mongoc-secure-channel.c mongoc-secure-transport.c mongoc-server-api.c mongoc-server-description.c mongoc-server-monitor.c mongoc-server-stream.c mongoc-set.c mongoc-socket.c mongoc-ssl.c mongoc-sspi.c mongoc-stream-buffered.c mongoc-stream.c mongoc-stream-file.c mongoc-stream-gridfs.c mongoc-stream-gridfs-download.c mongoc-stream-gridfs-upload.c mongoc-stream-socket.c mongoc-stream-tls.c mongoc-stream-tls-libressl.c mongoc-stream-tls-openssl-bio.c mongoc-stream-tls-openssl.c mongoc-stream-tls-secure-channel.c mongoc-stream-tls-secure-transport.c mongoc-timeout.c mongoc-topology-background-monitoring.c mongoc-topology.c mongoc-topology-description-apm.c mongoc-topology-description.c mongoc-topology-scanner.c mongoc-uri.c mongoc-util.c mongoc-version-functions.c mongoc-write-command.c mongoc-write-command-legacy.c mongoc-write-concern.c";
118+
var PHP_MONGODB_MONGOC_SOURCES="mongoc-aggregate.c mongoc-apm.c mongoc-array.c mongoc-async.c mongoc-async-cmd.c mongoc-buffer.c mongoc-bulk-operation.c mongoc-change-stream.c mongoc-client.c mongoc-client-pool.c mongoc-client-session.c mongoc-client-side-encryption.c mongoc-cluster-aws.c mongoc-cluster.c mongoc-cluster-cyrus.c mongoc-cluster-sasl.c mongoc-cluster-sspi.c mongoc-cmd.c mongoc-collection.c mongoc-compression.c mongoc-counters.c mongoc-crypt.c mongoc-crypto.c mongoc-crypto-cng.c mongoc-crypto-common-crypto.c mongoc-crypto-openssl.c mongoc-cursor-array.c mongoc-cursor.c mongoc-cursor-change-stream.c mongoc-cursor-cmd.c mongoc-cursor-cmd-deprecated.c mongoc-cursor-find.c mongoc-cursor-find-cmd.c mongoc-cursor-find-opquery.c mongoc-cursor-legacy.c mongoc-cyrus.c mongoc-database.c mongoc-error.c mongoc-find-and-modify.c mongoc-generation-map.c mongoc-gridfs-bucket.c mongoc-gridfs-bucket-file.c mongoc-gridfs.c mongoc-gridfs-file.c mongoc-gridfs-file-list.c mongoc-gridfs-file-page.c mongoc-handshake.c mongoc-host-list.c mongoc-http.c mongoc-index.c mongoc-init.c mongoc-interrupt.c mongoc-libressl.c mongoc-linux-distro-scanner.c mongoc-list.c mongoc-log.c mongoc-matcher.c mongoc-matcher-op.c mongoc-memcmp.c mongoc-ocsp-cache.c mongoc-openssl.c mongoc-optional.c mongoc-opts.c mongoc-opts-helpers.c mongoc-queue.c mongoc-rand-cng.c mongoc-rand-common-crypto.c mongoc-rand-openssl.c mongoc-read-concern.c mongoc-read-prefs.c mongoc-rpc.c mongoc-sasl.c mongoc-scram.c mongoc-secure-channel.c mongoc-secure-transport.c mongoc-server-api.c mongoc-server-description.c mongoc-server-monitor.c mongoc-server-stream.c mongoc-set.c mongoc-socket.c mongoc-ssl.c mongoc-sspi.c mongoc-stream-buffered.c mongoc-stream.c mongoc-stream-file.c mongoc-stream-gridfs.c mongoc-stream-gridfs-download.c mongoc-stream-gridfs-upload.c mongoc-stream-socket.c mongoc-stream-tls.c mongoc-stream-tls-libressl.c mongoc-stream-tls-openssl-bio.c mongoc-stream-tls-openssl.c mongoc-stream-tls-secure-channel.c mongoc-stream-tls-secure-transport.c mongoc-timeout.c mongoc-topology-background-monitoring.c mongoc-topology.c mongoc-topology-description-apm.c mongoc-topology-description.c mongoc-topology-scanner.c mongoc-uri.c mongoc-util.c mongoc-version-functions.c mongoc-write-command.c mongoc-write-command-legacy.c mongoc-write-concern.c";
119119

120120
EXTENSION("mongodb", "php_phongo.c phongo_compat.c", null, PHP_MONGODB_CFLAGS);
121121
MONGODB_ADD_SOURCES("/src", "bson.c bson-encode.c phongo_apm.c");

src/LIBMONGOC_VERSION_CURRENT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.18.0
1+
1.11.1-20210804+git230369cd07

src/MongoDB/Manager.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,18 @@ static PHP_METHOD(Manager, startSession)
805805
}
806806
}
807807

808+
if (options && php_array_existsc(options, "snapshot")) {
809+
if (!cs_opts) {
810+
cs_opts = mongoc_session_opts_new();
811+
}
812+
mongoc_session_opts_set_snapshot(cs_opts, php_array_fetchc_bool(options, "snapshot"));
813+
}
814+
815+
if (cs_opts && mongoc_session_opts_get_causal_consistency(cs_opts) && mongoc_session_opts_get_snapshot(cs_opts)) {
816+
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Only one of \"causalConsistency\" and \"snapshot\" can be enabled");
817+
goto cleanup;
818+
}
819+
808820
/* If the Manager was created in a different process, reset the client so
809821
* that its session pool is cleared. This will ensure that we do not re-use
810822
* a server session (i.e. LSID) created by a parent process. */

src/MongoDB/ReadConcern.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ void php_phongo_readconcern_init_ce(INIT_FUNC_ARGS) /* {{{ */
370370
zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("MAJORITY"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_MAJORITY));
371371
zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("LINEARIZABLE"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_LINEARIZABLE));
372372
zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("AVAILABLE"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_AVAILABLE));
373+
zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("SNAPSHOT"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_SNAPSHOT));
373374
} /* }}} */
374375

375376
/*

src/MongoDB/Session.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,10 @@ static HashTable* php_phongo_session_get_debug_info(phongo_compat_object_handler
740740
if (intern->client_session) {
741741
const mongoc_session_opt_t* cs_opts = mongoc_client_session_get_opts(intern->client_session);
742742
ADD_ASSOC_BOOL_EX(&retval, "causalConsistency", mongoc_session_opts_get_causal_consistency(cs_opts));
743+
ADD_ASSOC_BOOL_EX(&retval, "snapshot", mongoc_session_opts_get_snapshot(cs_opts));
743744
} else {
744745
ADD_ASSOC_NULL_EX(&retval, "causalConsistency");
746+
ADD_ASSOC_NULL_EX(&retval, "snapshot");
745747
}
746748

747749
if (intern->client_session) {

src/libmongoc

Submodule libmongoc updated 155 files

tests/session/session_error-001.phpt renamed to tests/manager/manager-startSession_error-001.phpt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
--TEST--
2-
MongoDB\Driver\Session with wrong defaultTransactionOptions
2+
MongoDB\Driver\Manager::startSession() with wrong defaultTransactionOptions
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_not_libmongoc_crypto(); ?>
6+
<?php skip_if_not_live(); ?>
7+
<?php skip_if_server_version('<', '3.6'); ?>
38
--FILE--
49
<?php
510
require_once __DIR__ . "/../utils/basic.inc";
@@ -40,7 +45,7 @@ foreach ($options as $txnOptions) {
4045
$manager->startSession([
4146
'defaultTransactionOptions' => $txnOptions
4247
]);
43-
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
48+
}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n";
4449
}
4550

4651
echo raises(function() use ($manager) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
MongoDB\Driver\Manager::startSession() snapshot and causalConsistency cannot both be true
3+
--DESCRIPTION--
4+
Session spec prose test #1
5+
https://github.com/mongodb/specifications/blob/master/source/sessions/tests/README.rst#prose-tests
6+
--SKIPIF--
7+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
8+
<?php skip_if_not_libmongoc_crypto(); ?>
9+
<?php skip_if_not_live(); ?>
10+
<?php skip_if_server_version('<', '3.6'); ?>
11+
--FILE--
12+
<?php
13+
require_once __DIR__ . "/../utils/basic.inc";
14+
15+
$manager = create_test_manager();
16+
17+
echo throws(function() use ($manager) {
18+
$manager->startSession([
19+
'causalConsistency' => true,
20+
'snapshot' => true,
21+
]);
22+
}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n";
23+
24+
?>
25+
===DONE===
26+
<?php exit(0); ?>
27+
--EXPECT--
28+
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
29+
Only one of "causalConsistency" and "snapshot" can be enabled
30+
===DONE===

tests/readConcern/readconcern-bsonserialize-001.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ $tests = [
1111
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::LOCAL),
1212
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY),
1313
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
14+
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::SNAPSHOT),
1415
];
1516

1617
foreach ($tests as $test) {
@@ -26,4 +27,5 @@ foreach ($tests as $test) {
2627
{ "level" : "local" }
2728
{ "level" : "majority" }
2829
{ "level" : "available" }
30+
{ "level" : "snapshot" }
2931
===DONE===

tests/readConcern/readconcern-bsonserialize-002.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ $tests = [
1111
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::LOCAL),
1212
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY),
1313
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
14+
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::SNAPSHOT),
1415
];
1516

1617
foreach ($tests as $test) {
@@ -39,4 +40,8 @@ object(stdClass)#%d (%d) {
3940
["level"]=>
4041
string(9) "available"
4142
}
43+
object(stdClass)#%d (%d) {
44+
["level"]=>
45+
string(8) "snapshot"
46+
}
4247
===DONE===

tests/readConcern/readconcern-constants.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var_dump(MongoDB\Driver\ReadConcern::LINEARIZABLE);
77
var_dump(MongoDB\Driver\ReadConcern::LOCAL);
88
var_dump(MongoDB\Driver\ReadConcern::MAJORITY);
99
var_dump(MongoDB\Driver\ReadConcern::AVAILABLE);
10+
var_dump(MongoDB\Driver\ReadConcern::SNAPSHOT);
1011

1112
?>
1213
===DONE===
@@ -16,4 +17,5 @@ string(12) "linearizable"
1617
string(5) "local"
1718
string(8) "majority"
1819
string(9) "available"
20+
string(8) "snapshot"
1921
===DONE===

tests/readConcern/readconcern-debug-001.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ $tests = [
1111
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::LOCAL),
1212
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY),
1313
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
14+
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::SNAPSHOT),
1415
];
1516

1617
foreach ($tests as $test) {
@@ -39,4 +40,8 @@ object(MongoDB\Driver\ReadConcern)#%d (%d) {
3940
["level"]=>
4041
string(9) "available"
4142
}
43+
object(MongoDB\Driver\ReadConcern)#%d (%d) {
44+
["level"]=>
45+
string(8) "snapshot"
46+
}
4247
===DONE===

tests/readConcern/readconcern-serialization-001.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ $tests = [
1111
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::LOCAL),
1212
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY),
1313
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
14+
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::SNAPSHOT),
1415
];
1516

1617
foreach ($tests as $test) {
@@ -76,4 +77,15 @@ object(MongoDB\Driver\ReadConcern)#%d (%d) {
7677
string(9) "available"
7778
}
7879

80+
object(MongoDB\Driver\ReadConcern)#%d (%d) {
81+
["level"]=>
82+
string(8) "snapshot"
83+
}
84+
bool(true)
85+
C:26:"MongoDB\Driver\ReadConcern":33:{a:1:{s:5:"level";s:8:"snapshot";}}
86+
object(MongoDB\Driver\ReadConcern)#%d (%d) {
87+
["level"]=>
88+
string(8) "snapshot"
89+
}
90+
7991
===DONE===

tests/readConcern/readconcern-set_state-001.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ $tests = [
88
MongoDB\Driver\ReadConcern::LINEARIZABLE,
99
MongoDB\Driver\ReadConcern::LOCAL,
1010
MongoDB\Driver\ReadConcern::MAJORITY,
11+
MongoDB\Driver\ReadConcern::SNAPSHOT,
1112
];
1213

1314
foreach ($tests as $level) {
@@ -42,6 +43,10 @@ MongoDB\Driver\ReadConcern::__set_state(array(
4243
%w'level' => 'majority',
4344
))
4445

46+
MongoDB\Driver\ReadConcern::__set_state(array(
47+
%w'level' => 'snapshot',
48+
))
49+
4550
MongoDB\Driver\ReadConcern::__set_state(array(
4651
))
4752

tests/readConcern/readconcern-var_export-001.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ $tests = [
1111
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::LOCAL),
1212
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY),
1313
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
14+
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::SNAPSHOT),
1415
];
1516

1617
foreach ($tests as $test) {
@@ -35,4 +36,7 @@ MongoDB\Driver\ReadConcern::__set_state(array(
3536
MongoDB\Driver\ReadConcern::__set_state(array(
3637
'level' => 'available',
3738
))
39+
MongoDB\Driver\ReadConcern::__set_state(array(
40+
'level' => 'snapshot',
41+
))
3842
===DONE===

tests/session/session-004.phpt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
MongoDB\Driver\Session spec test: snapshot option is incompatible with writes
3+
--DESCRIPTION--
4+
PHPC-1875: Disable writes on snapshot sessions
5+
--SKIPIF--
6+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
7+
<?php skip_if_not_libmongoc_crypto(); ?>
8+
<?php skip_if_not_live(); ?>
9+
<?php skip_if_server_version('<', '5.0'); ?>
10+
--FILE--
11+
<?php
12+
require_once __DIR__ . "/../utils/basic.inc";
13+
14+
$manager = create_test_manager();
15+
$session = $manager->startSession(['snapshot' => true]);
16+
17+
$bulk = new MongoDB\Driver\BulkWrite();
18+
$bulk->insert(['x' => 1]);
19+
20+
try {
21+
$manager->executeBulkWrite(NS, $bulk, ['session' => $session]);
22+
} catch (MongoDB\Driver\Exception\BulkWriteException $e) {
23+
/* Note: we intentionally do not assert the server's error message for the
24+
* client specifying a read concern on a write command. It is sufficient to
25+
* assert that the error code is InvalidOptions(72). */
26+
var_dump($e->getCode() === 72);
27+
}
28+
29+
?>
30+
===DONE===
31+
<?php exit(0); ?>
32+
--EXPECT--
33+
bool(true)
34+
===DONE===

0 commit comments

Comments
 (0)