Skip to content

Commit b8b41a5

Browse files
committed
Merge pull request #42 from jmikola/phpc-179
PHPC-179 and PHPC-280: WriteConcern journal/fsync handling
2 parents ca8ce77 + fa3618e commit b8b41a5

9 files changed

+77
-47
lines changed

php_phongo.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "mongoc-cursor-cursorid-private.h"
3131
#include "mongoc-read-prefs-private.h"
3232
#include "mongoc-bulk-operation-private.h"
33+
#include "mongoc-write-concern-private.h"
3334
#include "mongoc-trace.h"
3435

3536

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

12541255
add_assoc_bool_ex(retval, ZEND_STRS("wmajority"), mongoc_write_concern_get_wmajority(write_concern));
12551256
add_assoc_long_ex(retval, ZEND_STRS("wtimeout"), mongoc_write_concern_get_wtimeout(write_concern));
1256-
add_assoc_bool_ex(retval, ZEND_STRS("fsync"), mongoc_write_concern_get_fsync(write_concern));
1257-
add_assoc_bool_ex(retval, ZEND_STRS("journal"), mongoc_write_concern_get_journal(write_concern));
1257+
if (write_concern->fsync_ != MONGOC_WRITE_CONCERN_FSYNC_DEFAULT) {
1258+
add_assoc_bool_ex(retval, ZEND_STRS("fsync"), mongoc_write_concern_get_fsync(write_concern));
1259+
} else {
1260+
add_assoc_null_ex(retval, ZEND_STRS("fsync"));
1261+
}
1262+
if (write_concern->journal != MONGOC_WRITE_CONCERN_JOURNAL_DEFAULT) {
1263+
add_assoc_bool_ex(retval, ZEND_STRS("journal"), mongoc_write_concern_get_journal(write_concern));
1264+
} else {
1265+
add_assoc_null_ex(retval, ZEND_STRS("journal"));
1266+
}
12581267
} /* }}} */
12591268

12601269
void php_phongo_cursor_to_zval(zval *retval, php_phongo_cursor_t *cursor) /* {{{ */

src/MongoDB/WriteConcern.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ zend_object_handlers php_phongo_handler_writeconcern;
4848

4949
#define PHONGO_WRITE_CONCERN_W_MAJORITY "majority"
5050

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

8888
switch(ZEND_NUM_ARGS()) {
8989
case 4:
90-
if (fsync) {
91-
mongoc_write_concern_set_fsync(intern->write_concern, true);
92-
}
90+
mongoc_write_concern_set_fsync(intern->write_concern, fsync);
9391
/* fallthrough */
9492
case 3:
95-
if (journal) {
96-
mongoc_write_concern_set_journal(intern->write_concern, true);
97-
}
93+
mongoc_write_concern_set_journal(intern->write_concern, journal);
9894
/* fallthrough */
9995
case 2:
10096
if (wtimeout > 0) {

tests/bulk/write-0002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ object(MongoDB\Driver\BulkWrite)#%d (%d) {
6969
["wtimeout"]=>
7070
int(1000)
7171
["fsync"]=>
72-
bool(false)
72+
NULL
7373
["journal"]=>
74-
bool(false)
74+
NULL
7575
}
7676
}
7777
Inserted 2 documents to %s

tests/replicaset/writeresult-getserver-002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
8686
["wtimeout"]=>
8787
int(0)
8888
["fsync"]=>
89-
bool(false)
89+
NULL
9090
["journal"]=>
91-
bool(false)
91+
NULL
9292
}
9393
}
9494
string(14) "192.168.112.10"

tests/standalone/server-executeBulkWrite-001.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
7676
["wtimeout"]=>
7777
int(0)
7878
["fsync"]=>
79-
bool(false)
79+
NULL
8080
["journal"]=>
81-
bool(false)
81+
NULL
8282
}
8383
}
8484

tests/standalone/writeresult-isacknowledged-001.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
4545
["wtimeout"]=>
4646
int(0)
4747
["fsync"]=>
48-
bool(false)
48+
NULL
4949
["journal"]=>
50-
bool(false)
50+
NULL
5151
}
5252
}
5353
===DONE===

tests/standalone/writeresult-isacknowledged-002.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
4949
["wtimeout"]=>
5050
int(0)
5151
["fsync"]=>
52-
bool(false)
52+
NULL
5353
["journal"]=>
54-
bool(false)
54+
NULL
5555
}
5656
}
5757
===DONE===

tests/standalone/writeresult-isacknowledged-003.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ object(MongoDB\Driver\WriteResult)#%d (%d) {
4747
["wtimeout"]=>
4848
int(0)
4949
["fsync"]=>
50-
bool(false)
50+
NULL
5151
["journal"]=>
52-
bool(false)
52+
NULL
5353
}
5454
}
5555
===DONE===

tests/writeConcern/writeconcern-001.phpt

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,26 @@ MongoDB\Driver\WriteConcern construction
66
<?php
77
require_once __DIR__ . "/../utils/basic.inc";
88

9-
$w = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY);
10-
$w2 = new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000);
9+
var_dump(new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY));
10+
var_dump(new MongoDB\Driver\WriteConcern(MongoDB\Driver\WriteConcern::MAJORITY, 1000));
1111

12-
$w3 = new MongoDB\Driver\WriteConcern(2);
13-
$w4 = new MongoDB\Driver\WriteConcern(2, 2000);
12+
var_dump(new MongoDB\Driver\WriteConcern(2));
13+
var_dump(new MongoDB\Driver\WriteConcern(2, 2000));
1414

15-
$w5 = new MongoDB\Driver\WriteConcern("tagname");
16-
$w6 = new MongoDB\Driver\WriteConcern("string", 3000);
15+
var_dump(new MongoDB\Driver\WriteConcern("tagname"));
16+
var_dump(new MongoDB\Driver\WriteConcern("string", 3000));
1717

18-
$w7 = new MongoDB\Driver\WriteConcern("string", 3000, false, false);
19-
$w8 = new MongoDB\Driver\WriteConcern("string", 3000, true, true);
18+
var_dump(new MongoDB\Driver\WriteConcern("string", 4000, true));
19+
var_dump(new MongoDB\Driver\WriteConcern("string", 5000, false));
2020

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

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

2627
try {
27-
new MongoDB\Driver\WriteConcern("string", 3000, false, true, 1);
28+
new MongoDB\Driver\WriteConcern("string", 10000, false, true, 1);
2829
} catch(InvalidArgumentException $e) {
2930
echo $e->getMessage(), "\n";
3031
}
@@ -41,9 +42,9 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
4142
["wtimeout"]=>
4243
int(0)
4344
["fsync"]=>
44-
bool(false)
45+
NULL
4546
["journal"]=>
46-
bool(false)
47+
NULL
4748
}
4849
object(MongoDB\Driver\WriteConcern)#%d (%d) {
4950
["w"]=>
@@ -53,9 +54,9 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
5354
["wtimeout"]=>
5455
int(1000)
5556
["fsync"]=>
56-
bool(false)
57+
NULL
5758
["journal"]=>
58-
bool(false)
59+
NULL
5960
}
6061
object(MongoDB\Driver\WriteConcern)#%d (%d) {
6162
["w"]=>
@@ -65,9 +66,9 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
6566
["wtimeout"]=>
6667
int(0)
6768
["fsync"]=>
68-
bool(false)
69+
NULL
6970
["journal"]=>
70-
bool(false)
71+
NULL
7172
}
7273
object(MongoDB\Driver\WriteConcern)#%d (%d) {
7374
["w"]=>
@@ -77,9 +78,9 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
7778
["wtimeout"]=>
7879
int(2000)
7980
["fsync"]=>
80-
bool(false)
81+
NULL
8182
["journal"]=>
82-
bool(false)
83+
NULL
8384
}
8485
object(MongoDB\Driver\WriteConcern)#%d (%d) {
8586
["w"]=>
@@ -89,9 +90,9 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
8990
["wtimeout"]=>
9091
int(0)
9192
["fsync"]=>
92-
bool(false)
93+
NULL
9394
["journal"]=>
94-
bool(false)
95+
NULL
9596
}
9697
object(MongoDB\Driver\WriteConcern)#%d (%d) {
9798
["w"]=>
@@ -101,7 +102,31 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
101102
["wtimeout"]=>
102103
int(3000)
103104
["fsync"]=>
105+
NULL
106+
["journal"]=>
107+
NULL
108+
}
109+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
110+
["w"]=>
111+
string(6) "string"
112+
["wmajority"]=>
113+
bool(false)
114+
["wtimeout"]=>
115+
int(4000)
116+
["fsync"]=>
117+
NULL
118+
["journal"]=>
119+
bool(true)
120+
}
121+
object(MongoDB\Driver\WriteConcern)#%d (%d) {
122+
["w"]=>
123+
string(6) "string"
124+
["wmajority"]=>
104125
bool(false)
126+
["wtimeout"]=>
127+
int(5000)
128+
["fsync"]=>
129+
NULL
105130
["journal"]=>
106131
bool(false)
107132
}
@@ -111,7 +136,7 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
111136
["wmajority"]=>
112137
bool(false)
113138
["wtimeout"]=>
114-
int(3000)
139+
int(6000)
115140
["fsync"]=>
116141
bool(false)
117142
["journal"]=>
@@ -123,7 +148,7 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
123148
["wmajority"]=>
124149
bool(false)
125150
["wtimeout"]=>
126-
int(3000)
151+
int(7000)
127152
["fsync"]=>
128153
bool(true)
129154
["journal"]=>
@@ -135,7 +160,7 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
135160
["wmajority"]=>
136161
bool(false)
137162
["wtimeout"]=>
138-
int(3000)
163+
int(8000)
139164
["fsync"]=>
140165
bool(false)
141166
["journal"]=>
@@ -147,7 +172,7 @@ object(MongoDB\Driver\WriteConcern)#%d (%d) {
147172
["wmajority"]=>
148173
bool(false)
149174
["wtimeout"]=>
150-
int(3000)
175+
int(9000)
151176
["fsync"]=>
152177
bool(true)
153178
["journal"]=>

0 commit comments

Comments
 (0)