Skip to content

PHPC-1761: Snapshot Reads #1243

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

Merged
merged 6 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ if test "$PHP_MONGODB" != "no"; then
PHP_MONGODB_JSONSL_SOURCES="jsonsl.c"

dnl Generated with: find src/libmongoc/src/libmongoc/src/mongoc -name '*.c' -print0 | cut -sz -d / -f 7- | sort -dz | tr '\000' ' '
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"
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"

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' ' '
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"
Expand Down
2 changes: 1 addition & 1 deletion config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ if (PHP_MONGODB != "no") {
var PHP_MONGODB_JSONSL_SOURCES="jsonsl.c";

// Generated with: find src/libmongoc/src/libmongoc/src/mongoc -name '*.c' -print0 | cut -sz -d / -f 7- | sort -dz | tr '\000' ' '
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";
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";

EXTENSION("mongodb", "php_phongo.c phongo_compat.c", null, PHP_MONGODB_CFLAGS);
MONGODB_ADD_SOURCES("/src", "bson.c bson-encode.c phongo_apm.c");
Expand Down
2 changes: 1 addition & 1 deletion src/LIBMONGOC_VERSION_CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.18.0
1.11.1-20210804+git230369cd07
Copy link
Member Author

Choose a reason for hiding this comment

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

Disregard "1.11.1" here, as it's related to an outstanding issue with calc_release_version.py (CDRIVER-3315).

12 changes: 12 additions & 0 deletions src/MongoDB/Manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,18 @@ static PHP_METHOD(Manager, startSession)
}
}

if (options && php_array_existsc(options, "snapshot")) {
if (!cs_opts) {
cs_opts = mongoc_session_opts_new();
}
mongoc_session_opts_set_snapshot(cs_opts, php_array_fetchc_bool(options, "snapshot"));
}

if (cs_opts && mongoc_session_opts_get_causal_consistency(cs_opts) && mongoc_session_opts_get_snapshot(cs_opts)) {
phongo_throw_exception(PHONGO_ERROR_INVALID_ARGUMENT, "Only one of \"causalConsistency\" and \"snapshot\" can be enabled");
Copy link
Member Author

Choose a reason for hiding this comment

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

libmongoc also raises this error through mongoc_client_start_session; however, the code/domain used for that would lead to a PHPC throwing a RuntimeException. I handled this manually so we can ensure an InvalidArgumentException is thrown, which makes more sense since this is just option validation.

goto cleanup;
}

/* If the Manager was created in a different process, reset the client so
* that its session pool is cleared. This will ensure that we do not re-use
* a server session (i.e. LSID) created by a parent process. */
Expand Down
1 change: 1 addition & 0 deletions src/MongoDB/ReadConcern.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ void php_phongo_readconcern_init_ce(INIT_FUNC_ARGS) /* {{{ */
zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("MAJORITY"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_MAJORITY));
zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("LINEARIZABLE"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_LINEARIZABLE));
zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("AVAILABLE"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_AVAILABLE));
zend_declare_class_constant_stringl(php_phongo_readconcern_ce, ZEND_STRL("SNAPSHOT"), ZEND_STRL(MONGOC_READ_CONCERN_LEVEL_SNAPSHOT));
} /* }}} */

/*
Expand Down
2 changes: 2 additions & 0 deletions src/MongoDB/Session.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,10 @@ static HashTable* php_phongo_session_get_debug_info(phongo_compat_object_handler
if (intern->client_session) {
const mongoc_session_opt_t* cs_opts = mongoc_client_session_get_opts(intern->client_session);
ADD_ASSOC_BOOL_EX(&retval, "causalConsistency", mongoc_session_opts_get_causal_consistency(cs_opts));
ADD_ASSOC_BOOL_EX(&retval, "snapshot", mongoc_session_opts_get_snapshot(cs_opts));
} else {
ADD_ASSOC_NULL_EX(&retval, "causalConsistency");
ADD_ASSOC_NULL_EX(&retval, "snapshot");
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: Session.c doesn't actually have getters for the options passed to Manager::startSession(). Session::getTransactionOptions() doesn't directly correlate with the defaultTransactionOptions session option, since it's (a) the combined options from starting a transaction and merging those options with the session's own defaults and (b) only relevant when a session is in an active transaction.

I forget if we considered adding an API for the startSession() options in the past, but I don't feel strongly about it.

}

if (intern->client_session) {
Expand Down
2 changes: 1 addition & 1 deletion src/libmongoc
Submodule libmongoc updated 155 files
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
--TEST--
MongoDB\Driver\Session with wrong defaultTransactionOptions
MongoDB\Driver\Manager::startSession() with wrong defaultTransactionOptions
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_not_libmongoc_crypto(); ?>
<?php skip_if_not_live(); ?>
<?php skip_if_server_version('<', '3.6'); ?>
Copy link
Member Author

Choose a reason for hiding this comment

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

The previous tests were missing a SKIPIF entirely.

--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";
Expand Down Expand Up @@ -40,7 +45,7 @@ foreach ($options as $txnOptions) {
$manager->startSession([
'defaultTransactionOptions' => $txnOptions
]);
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n";
}

echo raises(function() use ($manager) {
Expand Down
30 changes: 30 additions & 0 deletions tests/manager/manager-startSession_error-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
MongoDB\Driver\Manager::startSession() snapshot and causalConsistency cannot both be true
--DESCRIPTION--
Session spec prose test #1
https://github.com/mongodb/specifications/blob/master/source/sessions/tests/README.rst#prose-tests
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_not_libmongoc_crypto(); ?>
<?php skip_if_not_live(); ?>
<?php skip_if_server_version('<', '3.6'); ?>
--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";

$manager = create_test_manager();

echo throws(function() use ($manager) {
$manager->startSession([
'causalConsistency' => true,
'snapshot' => true,
]);
}, MongoDB\Driver\Exception\InvalidArgumentException::class), "\n";

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
Only one of "causalConsistency" and "snapshot" can be enabled
===DONE===
2 changes: 2 additions & 0 deletions tests/readConcern/readconcern-bsonserialize-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ $tests = [
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::LOCAL),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::SNAPSHOT),
];

foreach ($tests as $test) {
Expand All @@ -26,4 +27,5 @@ foreach ($tests as $test) {
{ "level" : "local" }
{ "level" : "majority" }
{ "level" : "available" }
{ "level" : "snapshot" }
===DONE===
5 changes: 5 additions & 0 deletions tests/readConcern/readconcern-bsonserialize-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ $tests = [
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::LOCAL),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::SNAPSHOT),
];

foreach ($tests as $test) {
Expand Down Expand Up @@ -39,4 +40,8 @@ object(stdClass)#%d (%d) {
["level"]=>
string(9) "available"
}
object(stdClass)#%d (%d) {
["level"]=>
string(8) "snapshot"
}
===DONE===
2 changes: 2 additions & 0 deletions tests/readConcern/readconcern-constants.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var_dump(MongoDB\Driver\ReadConcern::LINEARIZABLE);
var_dump(MongoDB\Driver\ReadConcern::LOCAL);
var_dump(MongoDB\Driver\ReadConcern::MAJORITY);
var_dump(MongoDB\Driver\ReadConcern::AVAILABLE);
var_dump(MongoDB\Driver\ReadConcern::SNAPSHOT);

?>
===DONE===
Expand All @@ -16,4 +17,5 @@ string(12) "linearizable"
string(5) "local"
string(8) "majority"
string(9) "available"
string(8) "snapshot"
===DONE===
5 changes: 5 additions & 0 deletions tests/readConcern/readconcern-debug-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ $tests = [
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::LOCAL),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::SNAPSHOT),
];

foreach ($tests as $test) {
Expand Down Expand Up @@ -39,4 +40,8 @@ object(MongoDB\Driver\ReadConcern)#%d (%d) {
["level"]=>
string(9) "available"
}
object(MongoDB\Driver\ReadConcern)#%d (%d) {
["level"]=>
string(8) "snapshot"
}
===DONE===
12 changes: 12 additions & 0 deletions tests/readConcern/readconcern-serialization-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ $tests = [
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::LOCAL),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::SNAPSHOT),
];

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

object(MongoDB\Driver\ReadConcern)#%d (%d) {
["level"]=>
string(8) "snapshot"
}
bool(true)
C:26:"MongoDB\Driver\ReadConcern":33:{a:1:{s:5:"level";s:8:"snapshot";}}
object(MongoDB\Driver\ReadConcern)#%d (%d) {
["level"]=>
string(8) "snapshot"
}

===DONE===
5 changes: 5 additions & 0 deletions tests/readConcern/readconcern-set_state-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ $tests = [
MongoDB\Driver\ReadConcern::LINEARIZABLE,
MongoDB\Driver\ReadConcern::LOCAL,
MongoDB\Driver\ReadConcern::MAJORITY,
MongoDB\Driver\ReadConcern::SNAPSHOT,
];

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

MongoDB\Driver\ReadConcern::__set_state(array(
%w'level' => 'snapshot',
))

MongoDB\Driver\ReadConcern::__set_state(array(
))

Expand Down
4 changes: 4 additions & 0 deletions tests/readConcern/readconcern-var_export-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ $tests = [
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::LOCAL),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::MAJORITY),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::AVAILABLE),
new MongoDB\Driver\ReadConcern(MongoDB\Driver\ReadConcern::SNAPSHOT),
];

foreach ($tests as $test) {
Expand All @@ -35,4 +36,7 @@ MongoDB\Driver\ReadConcern::__set_state(array(
MongoDB\Driver\ReadConcern::__set_state(array(
'level' => 'available',
))
MongoDB\Driver\ReadConcern::__set_state(array(
'level' => 'snapshot',
))
===DONE===
34 changes: 34 additions & 0 deletions tests/session/session-004.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
MongoDB\Driver\Session spec test: snapshot option is incompatible with writes
--DESCRIPTION--
PHPC-1875: Disable writes on snapshot sessions
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_not_libmongoc_crypto(); ?>
<?php skip_if_not_live(); ?>
<?php skip_if_server_version('<', '5.0'); ?>
--FILE--
<?php
require_once __DIR__ . "/../utils/basic.inc";

$manager = create_test_manager();
$session = $manager->startSession(['snapshot' => true]);

$bulk = new MongoDB\Driver\BulkWrite();
$bulk->insert(['x' => 1]);

try {
$manager->executeBulkWrite(NS, $bulk, ['session' => $session]);
} catch (MongoDB\Driver\Exception\BulkWriteException $e) {
/* Note: we intentionally do not assert the server's error message for the
* client specifying a read concern on a write command. It is sufficient to
* assert that the error code is InvalidOptions(72). */
var_dump($e->getCode() === 72);
}

?>
===DONE===
<?php exit(0); ?>
--EXPECT--
bool(true)
===DONE===
Loading