Skip to content

PHPC-179 and PHPC-280: WriteConcern journal/fsync handling #42

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 3 commits into from
May 4, 2015
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
13 changes: 11 additions & 2 deletions php_phongo.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "mongoc-cursor-cursorid-private.h"
#include "mongoc-read-prefs-private.h"
#include "mongoc-bulk-operation-private.h"
#include "mongoc-write-concern-private.h"
#include "mongoc-trace.h"


Expand Down Expand Up @@ -1253,8 +1254,16 @@ void php_phongo_write_concern_to_zval(zval *retval, const mongoc_write_concern_t

add_assoc_bool_ex(retval, ZEND_STRS("wmajority"), mongoc_write_concern_get_wmajority(write_concern));
add_assoc_long_ex(retval, ZEND_STRS("wtimeout"), mongoc_write_concern_get_wtimeout(write_concern));
add_assoc_bool_ex(retval, ZEND_STRS("fsync"), mongoc_write_concern_get_fsync(write_concern));
add_assoc_bool_ex(retval, ZEND_STRS("journal"), mongoc_write_concern_get_journal(write_concern));
if (write_concern->fsync_ != MONGOC_WRITE_CONCERN_FSYNC_DEFAULT) {
add_assoc_bool_ex(retval, ZEND_STRS("fsync"), mongoc_write_concern_get_fsync(write_concern));
} else {
add_assoc_null_ex(retval, ZEND_STRS("fsync"));
}
if (write_concern->journal != MONGOC_WRITE_CONCERN_JOURNAL_DEFAULT) {
add_assoc_bool_ex(retval, ZEND_STRS("journal"), mongoc_write_concern_get_journal(write_concern));
} else {
add_assoc_null_ex(retval, ZEND_STRS("journal"));
}
} /* }}} */

void php_phongo_cursor_to_zval(zval *retval, php_phongo_cursor_t *cursor) /* {{{ */
Expand Down
10 changes: 3 additions & 7 deletions src/MongoDB/WriteConcern.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ zend_object_handlers php_phongo_handler_writeconcern;

#define PHONGO_WRITE_CONCERN_W_MAJORITY "majority"

/* {{{ proto MongoDB\Driver\WriteConcern WriteConcern::__construct(string $wstring[, integer $wtimeout[, boolean $journal[, boolean $fsync]]])
/* {{{ proto MongoDB\Driver\WriteConcern WriteConcern::__construct(integer|string $w[, integer $wtimeout[, boolean $journal[, boolean $fsync]]])
Constructs a new WriteConcern */
PHP_METHOD(WriteConcern, __construct)
{
Expand Down Expand Up @@ -87,14 +87,10 @@ PHP_METHOD(WriteConcern, __construct)

switch(ZEND_NUM_ARGS()) {
case 4:
if (fsync) {
mongoc_write_concern_set_fsync(intern->write_concern, true);
}
mongoc_write_concern_set_fsync(intern->write_concern, fsync);
/* fallthrough */
case 3:
if (journal) {
mongoc_write_concern_set_journal(intern->write_concern, true);
}
mongoc_write_concern_set_journal(intern->write_concern, journal);
/* fallthrough */
case 2:
if (wtimeout > 0) {
Expand Down
4 changes: 2 additions & 2 deletions tests/bulk/write-0002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ object(MongoDB\Driver\BulkWrite)#%d (%d) {
["wtimeout"]=>
int(1000)
["fsync"]=>
bool(false)
NULL
["journal"]=>
bool(false)
NULL
}
}
Inserted 2 documents to %s
Expand Down
4 changes: 2 additions & 2 deletions tests/replicaset/writeresult-getserver-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
["wtimeout"]=>
int(0)
["fsync"]=>
bool(false)
NULL
["journal"]=>
bool(false)
NULL
}
}
string(14) "192.168.112.10"
Expand Down
4 changes: 2 additions & 2 deletions tests/standalone/server-executeBulkWrite-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
["wtimeout"]=>
int(0)
["fsync"]=>
bool(false)
NULL
["journal"]=>
bool(false)
NULL
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/standalone/writeresult-isacknowledged-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
["wtimeout"]=>
int(0)
["fsync"]=>
bool(false)
NULL
["journal"]=>
bool(false)
NULL
}
}
===DONE===
4 changes: 2 additions & 2 deletions tests/standalone/writeresult-isacknowledged-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
["wtimeout"]=>
int(0)
["fsync"]=>
bool(false)
NULL
["journal"]=>
bool(false)
NULL
}
}
===DONE===
4 changes: 2 additions & 2 deletions tests/standalone/writeresult-isacknowledged-003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
["wtimeout"]=>
int(0)
["fsync"]=>
bool(false)
NULL
["journal"]=>
bool(false)
NULL
}
}
===DONE===
77 changes: 51 additions & 26 deletions tests/writeConcern/writeconcern-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ MongoDB\Driver\WriteConcern construction
<?php
require_once __DIR__ . "/../utils/basic.inc";

$w = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY);
$w2 = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
var_dump(new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY));
var_dump(new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000));

$w3 = new MongoDB\Driver\WriteConcern(2);
$w4 = new MongoDB\Driver\WriteConcern(2, 2000);
var_dump(new MongoDB\Driver\WriteConcern(2));
var_dump(new MongoDB\Driver\WriteConcern(2, 2000));

$w5 = new MongoDB\Driver\WriteConcern("tagname");
$w6 = new MongoDB\Driver\WriteConcern("string", 3000);
var_dump(new MongoDB\Driver\WriteConcern("tagname"));
var_dump(new MongoDB\Driver\WriteConcern("string", 3000));

$w7 = new MongoDB\Driver\WriteConcern("string", 3000, false, false);
$w8 = new MongoDB\Driver\WriteConcern("string", 3000, true, true);
var_dump(new MongoDB\Driver\WriteConcern("string", 4000, true));
Copy link
Member Author

Choose a reason for hiding this comment

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

I changed the test to use incrementing values for $wtimeout to make the test diffs easier to follow (on failure).

We're also adding two new tests here for setting $journal but not $fsync.

var_dump(new MongoDB\Driver\WriteConcern("string", 5000, false));

$w9 = new MongoDB\Driver\WriteConcern("string", 3000, true, false);
$w10= new MongoDB\Driver\WriteConcern("string", 3000, false, true);
var_dump(new MongoDB\Driver\WriteConcern("string", 6000, false, false));
var_dump(new MongoDB\Driver\WriteConcern("string", 7000, true, true));

var_dump($w, $w2, $w3, $w4, $w5, $w6, $w7, $w8, $w9, $w10);
var_dump(new MongoDB\Driver\WriteConcern("string", 8000, true, false));
var_dump(new MongoDB\Driver\WriteConcern("string", 9000, false, true));

try {
new MongoDB\Driver\WriteConcern("string", 3000, false, true, 1);
new MongoDB\Driver\WriteConcern("string", 10000, false, true, 1);
} catch(InvalidArgumentException $e) {
echo $e->getMessage(), "\n";
}
Expand All @@ -41,9 +42,9 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
["wtimeout"]=>
int(0)
["fsync"]=>
bool(false)
NULL
["journal"]=>
bool(false)
NULL
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
Expand All @@ -53,9 +54,9 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
["wtimeout"]=>
int(1000)
["fsync"]=>
bool(false)
NULL
["journal"]=>
bool(false)
NULL
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
Expand All @@ -65,9 +66,9 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
["wtimeout"]=>
int(0)
["fsync"]=>
bool(false)
NULL
["journal"]=>
bool(false)
NULL
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
Expand All @@ -77,9 +78,9 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
["wtimeout"]=>
int(2000)
["fsync"]=>
bool(false)
NULL
["journal"]=>
bool(false)
NULL
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
Expand All @@ -89,9 +90,9 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
["wtimeout"]=>
int(0)
["fsync"]=>
bool(false)
NULL
["journal"]=>
bool(false)
NULL
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
Expand All @@ -101,7 +102,31 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
["wtimeout"]=>
int(3000)
["fsync"]=>
NULL
["journal"]=>
NULL
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(6) "string"
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(4000)
["fsync"]=>
NULL
["journal"]=>
bool(true)
}
object(MongoDB\Driver\WriteConcern)#%d (%d) {
["w"]=>
string(6) "string"
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(5000)
["fsync"]=>
NULL
["journal"]=>
bool(false)
}
Expand All @@ -111,7 +136,7 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(3000)
int(6000)
["fsync"]=>
bool(false)
["journal"]=>
Expand All @@ -123,7 +148,7 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(3000)
int(7000)
["fsync"]=>
bool(true)
["journal"]=>
Expand All @@ -135,7 +160,7 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(3000)
int(8000)
["fsync"]=>
bool(false)
["journal"]=>
Expand All @@ -147,7 +172,7 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
["wmajority"]=>
bool(false)
["wtimeout"]=>
int(3000)
int(9000)
["fsync"]=>
bool(true)
["journal"]=>
Expand Down