Skip to content
This repository was archived by the owner on Feb 1, 2022. It is now read-only.

Commit df48166

Browse files
committed
Merge pull request #877
2 parents ca02282 + 16c9a1e commit df48166

File tree

5 files changed

+56
-110
lines changed

5 files changed

+56
-110
lines changed

collection.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ ZEND_EXTERN_MODULE_GLOBALS(mongo)
4848

4949
zend_class_entry *mongo_ce_Collection = NULL;
5050

51-
static int is_gle_op(zval *coll, zval *options, mongo_server_options *server_options TSRMLS_DC);
51+
static int is_gle_op(zval *coll, zval *options, mongo_server_options *server_options, int silent TSRMLS_DC);
5252
static void do_gle_op(mongo_con_manager *manager, mongo_connection *connection, zval *cursor_z, mongo_buffer *buf, zval *return_value TSRMLS_DC);
5353
static zval* append_getlasterror(zval *coll, mongo_buffer *buf, zval *options, mongo_connection *connection TSRMLS_DC);
5454
static char *to_index_string(zval *zkeys, int *key_len TSRMLS_DC);
@@ -378,11 +378,13 @@ static zval* append_getlasterror(zval *coll, mongo_buffer *buf, zval *options, m
378378
php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "The 'MongoCursor::$timeout' static property is deprecated, please call MongoCursor->timeout() instead");
379379
}
380380

381-
/* Get the default value for journalling */
382-
fsync = link->servers->options.default_fsync;
383-
journal = link->servers->options.default_journal;
384-
385381
/* Read the default_* properties from the link */
382+
if (link->servers->options.default_fsync != -1) {
383+
fsync = link->servers->options.default_fsync;
384+
}
385+
if (link->servers->options.default_journal != -1) {
386+
journal = link->servers->options.default_journal;
387+
}
386388
if (link->servers->options.default_w != -1) {
387389
w = link->servers->options.default_w;
388390
}
@@ -609,7 +611,7 @@ static int send_message(zval *this_ptr, mongo_connection *connection, mongo_buff
609611
return 0;
610612
}
611613

612-
if (is_gle_op(this_ptr, options, &link->servers->options TSRMLS_CC)) {
614+
if (is_gle_op(this_ptr, options, &link->servers->options, NOISY TSRMLS_CC)) {
613615
zval *cursor = append_getlasterror(this_ptr, buf, options, connection TSRMLS_CC);
614616
if (cursor) {
615617
do_gle_op(link->manager, connection, cursor, buf, return_value TSRMLS_CC);
@@ -632,7 +634,7 @@ static int send_message(zval *this_ptr, mongo_connection *connection, mongo_buff
632634
* on whether a write concern ("w" or "safe") or fsync/journal options are
633635
* specified.
634636
*/
635-
static int is_gle_op(zval *coll, zval *options, mongo_server_options *server_options TSRMLS_DC)
637+
static int is_gle_op(zval *coll, zval *options, mongo_server_options *server_options, int silent TSRMLS_DC)
636638
{
637639
int gle_op = 0, default_fsync, default_journal, coll_w = 0;
638640
zval *z_coll_w;
@@ -674,10 +676,14 @@ static int is_gle_op(zval *coll, zval *options, mongo_server_options *server_opt
674676
}
675677
break;
676678
default:
677-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The value of the 'w' option either needs to be a integer or string");
679+
if (silent == NOISY) {
680+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The value of the 'w' option either needs to be a integer or string");
681+
}
678682
}
679683
} else if (zend_hash_find(HASH_P(options), "safe", strlen("safe") + 1, (void**) &gle_pp) == SUCCESS) {
680-
php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "The 'safe' option is deprecated, please use 'w' instead");
684+
if (silent == NOISY) {
685+
php_error_docref(NULL TSRMLS_CC, E_DEPRECATED, "The 'safe' option is deprecated, please use 'w' instead");
686+
}
681687

682688
switch (Z_TYPE_PP(gle_pp)) {
683689
case IS_STRING:
@@ -691,7 +697,9 @@ static int is_gle_op(zval *coll, zval *options, mongo_server_options *server_opt
691697
}
692698
break;
693699
default:
694-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The value of the 'safe' option either needs to be a boolean or a string");
700+
if (silent == NOISY) {
701+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The value of the 'safe' option either needs to be a boolean or a string");
702+
}
695703
}
696704
} else if (coll_w >= 1) {
697705
gle_op = 1;
@@ -722,7 +730,9 @@ static int is_gle_op(zval *coll, zval *options, mongo_server_options *server_opt
722730
gle_op = (coll_w >= 1 || default_fsync == 1 || default_journal == 1);
723731
}
724732

725-
mongo_manager_log(MonGlo(manager), MLOG_IO, MLOG_FINE, "is_gle_op: %s", gle_op ? "yes" : "no");
733+
if (silent == NOISY) {
734+
mongo_manager_log(MonGlo(manager), MLOG_IO, MLOG_FINE, "is_gle_op: %s", gle_op ? "yes" : "no");
735+
}
726736
return gle_op;
727737
}
728738

@@ -1135,7 +1145,7 @@ static void php_mongo_collection_insert(zval *z_collection, zval *document, zval
11351145
RETURN_FALSE;
11361146
}
11371147

1138-
is_acknowledged = is_gle_op(z_collection, z_write_options, &link->servers->options TSRMLS_CC);
1148+
is_acknowledged = is_gle_op(z_collection, z_write_options, &link->servers->options, QUIET TSRMLS_CC);
11391149
supports_command = php_mongo_api_connection_supports_feature(connection, PHP_MONGO_API_WRITE_API);
11401150
supports_opcode = php_mongo_api_connection_supports_feature(connection, PHP_MONGO_API_RELEASE_2_4_AND_BEFORE);
11411151

@@ -1518,7 +1528,7 @@ static void php_mongocollection_update(zval *this_ptr, mongo_collection *c, zval
15181528
RETURN_FALSE;
15191529
}
15201530

1521-
is_acknowledged = is_gle_op(this_ptr, z_write_options, &link->servers->options TSRMLS_CC);
1531+
is_acknowledged = is_gle_op(this_ptr, z_write_options, &link->servers->options, QUIET TSRMLS_CC);
15221532
supports_command = php_mongo_api_connection_supports_feature(connection, PHP_MONGO_API_WRITE_API);
15231533
supports_opcode = php_mongo_api_connection_supports_feature(connection, PHP_MONGO_API_RELEASE_2_4_AND_BEFORE);
15241534

@@ -1637,7 +1647,7 @@ static void php_mongocollection_remove(zval *this_ptr, mongo_collection *c, zval
16371647
RETURN_FALSE;
16381648
}
16391649

1640-
is_acknowledged = is_gle_op(this_ptr, z_write_options, &link->servers->options TSRMLS_CC);
1650+
is_acknowledged = is_gle_op(this_ptr, z_write_options, &link->servers->options, QUIET TSRMLS_CC);
16411651
supports_command = php_mongo_api_connection_supports_feature(connection, PHP_MONGO_API_WRITE_API);
16421652
supports_opcode = php_mongo_api_connection_supports_feature(connection, PHP_MONGO_API_RELEASE_2_4_AND_BEFORE);
16431653

tests/standalone/bug01085-001.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ Test for PHP-1085: w=0 returns unexpected exception on failure (socketTimeoutMS
88

99
require_once "tests/utils/server.inc";
1010

11-
function assertFalse($value) {
11+
function assertTrue($value) {
1212
if ( ! is_bool($value)) {
1313
printf("Expected boolean type but received %s\n", gettype($value));
1414
return;
1515
}
1616

17-
if ($value !== false) {
18-
echo "Expected boolean false but received boolean true\n";
17+
if ($value !== true) {
18+
echo "Expected boolean true but received boolean false\n";
1919
}
2020
}
2121

@@ -34,7 +34,7 @@ for ($i = 0; $i < 10; ++$i) {
3434
array('x' => $i, 'y' => str_repeat('a', 4*1024*1024)),
3535
array('w' => 0)
3636
);
37-
assertFalse($retval);
37+
assertTrue($retval);
3838
}
3939

4040
echo "Testing update() with w=0\n";
@@ -44,15 +44,15 @@ $retval = $collection->update(
4444
array('$set' => array('y' => 1)),
4545
array('w' => 0)
4646
);
47-
assertFalse($retval);
47+
assertTrue($retval);
4848

4949
echo "Testing remove() with w=0\n";
5050

5151
$retval = $collection->remove(
5252
array('$where' => 'sleep(1) && false'),
5353
array('w' => 0)
5454
);
55-
assertFalse($retval);
55+
assertTrue($retval);
5656

5757
echo "Testing update() with w=1\n";
5858

tests/standalone/bug01085-002.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ Test for PHP-1085: w=0 returns unexpected exception on failure (socketTimeoutMS
88

99
require_once "tests/utils/server.inc";
1010

11-
function assertFalse($value) {
11+
function assertTrue($value) {
1212
if ( ! is_bool($value)) {
1313
printf("Expected boolean type but received %s\n", gettype($value));
1414
return;
1515
}
1616

17-
if ($value !== false) {
18-
echo "Expected boolean false but received boolean true\n";
17+
if ($value !== true) {
18+
echo "Expected boolean true but received boolean false\n";
1919
}
2020
}
2121

@@ -32,7 +32,7 @@ for ($i = 0; $i < 10; ++$i) {
3232
array('x' => $i, 'y' => str_repeat('a', 4*1024*1024)),
3333
array('w' => 0, 'socketTimeoutMS' => 1)
3434
);
35-
assertFalse($retval);
35+
assertTrue($retval);
3636
}
3737

3838
echo "Testing update() with w=0\n";
@@ -42,15 +42,15 @@ $retval = $collection->update(
4242
array('$set' => array('y' => 1)),
4343
array('w' => 0, 'socketTimeoutMS' => 1)
4444
);
45-
assertFalse($retval);
45+
assertTrue($retval);
4646

4747
echo "Testing remove() with w=0\n";
4848

4949
$retval = $collection->remove(
5050
array('$where' => 'sleep(1) && false'),
5151
array('w' => 0, 'socketTimeoutMS' => 1)
5252
);
53-
assertFalse($retval);
53+
assertTrue($retval);
5454

5555
echo "Testing update() with w=1\n";
5656

tests/standalone/mongoclient-connection-options-fsync-2.6.phpt

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ dump_writeConcern($mn);
4747

4848
echo "Setting it to false, per-query, and w=0 to force no-gle\n";
4949
$doc = array("doc" => "ument");
50+
printLogs(MongoLog::IO, MongoLog::FINE, '/is_gle_op/');
5051
$mc->test->bug572->insert($doc, array("fsync" => false, "w" => 0));
51-
dump_writeConcern($mn);
5252
$mc->test->bug572->update(array("_id" => $doc["_id"]), array("updated" => "doc"), array("fsync" => false, "w" => 0));
53-
dump_writeConcern($mn);
5453
$mc->test->bug572->remove(array("_id" => $doc["_id"]), array("fsync" => false, "w" => 0));
55-
dump_writeConcern($mn);
54+
MongoLog::setLevel(MongoLog::NONE);
5655

5756
$mc = new MongoClient($host, array("fsync" => false), array("context" => $ctx));
5857

@@ -78,12 +77,11 @@ $mc = new MongoClient($host, array("fsync" => false, "w" => 0), array("context"
7877

7978
echo "Fsync disabled by default, and gle\n";
8079
$doc = array("doc" => "ument");
80+
printLogs(MongoLog::IO, MongoLog::FINE, '/is_gle_op/');
8181
$mc->test->bug572->insert($doc);
82-
dump_writeConcern($mn);
8382
$mc->test->bug572->update(array("_id" => $doc["_id"]), array("updated" => "doc"));
84-
dump_writeConcern($mn);
8583
$mc->test->bug572->remove(array("_id" => $doc["_id"]));
86-
dump_writeConcern($mn);
84+
MongoLog::setLevel(MongoLog::NONE);
8785

8886
echo "Setting it to true, per-query, with gle=0\n";
8987
$doc = array("doc" => "ument");
@@ -135,24 +133,9 @@ array(2) {
135133
int(1)
136134
}
137135
Setting it to false, per-query, and w=0 to force no-gle
138-
array(2) {
139-
["fsync"]=>
140-
bool(false)
141-
["w"]=>
142-
int(0)
143-
}
144-
array(2) {
145-
["fsync"]=>
146-
bool(false)
147-
["w"]=>
148-
int(0)
149-
}
150-
array(2) {
151-
["fsync"]=>
152-
bool(false)
153-
["w"]=>
154-
int(0)
155-
}
136+
is_gle_op: no
137+
is_gle_op: no
138+
is_gle_op: no
156139
Fsync disabled by default
157140
array(2) {
158141
["fsync"]=>
@@ -192,24 +175,9 @@ array(2) {
192175
int(1)
193176
}
194177
Fsync disabled by default, and gle
195-
array(2) {
196-
["fsync"]=>
197-
bool(false)
198-
["w"]=>
199-
int(0)
200-
}
201-
array(2) {
202-
["fsync"]=>
203-
bool(false)
204-
["w"]=>
205-
int(0)
206-
}
207-
array(2) {
208-
["fsync"]=>
209-
bool(false)
210-
["w"]=>
211-
int(0)
212-
}
178+
is_gle_op: no
179+
is_gle_op: no
180+
is_gle_op: no
213181
Setting it to true, per-query, with gle=0
214182
array(2) {
215183
["fsync"]=>

tests/standalone/mongoclient-connection-options-journal-2.6.phpt

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,11 @@ dump_writeConcern($mn);
4848

4949
echo "Setting it to false, per-query, and w=0 to force no-gle\n";
5050
$doc = array("doc" => "ument");
51+
printLogs(MongoLog::IO, MongoLog::FINE, '/is_gle_op/');
5152
$mc->test->bug572->insert($doc, array("j" => false, "w" => 0));
52-
dump_writeConcern($mn);
5353
$mc->test->bug572->update(array("_id" => $doc["_id"]), array("updated" => "doc"), array("j" => false, "w" => 0));
54-
dump_writeConcern($mn);
5554
$mc->test->bug572->remove(array("_id" => $doc["_id"]), array("j" => false, "w" => 0));
56-
dump_writeConcern($mn);
55+
MongoLog::setLevel(MongoLog::NONE);
5756

5857
$mc = new MongoClient($host, array("journal" => false), array("context" => $ctx));
5958

@@ -79,12 +78,11 @@ $mc = new MongoClient($host, array("journal" => false, "w" => 0), array("context
7978

8079
echo "journal disabled by default, and gle\n";
8180
$doc = array("doc" => "ument");
81+
printLogs(MongoLog::IO, MongoLog::FINE, '/is_gle_op/');
8282
$mc->test->bug572->insert($doc);
83-
dump_writeConcern($mn);
8483
$mc->test->bug572->update(array("_id" => $doc["_id"]), array("updated" => "doc"));
85-
dump_writeConcern($mn);
8684
$mc->test->bug572->remove(array("_id" => $doc["_id"]));
87-
dump_writeConcern($mn);
85+
MongoLog::setLevel(MongoLog::NONE);
8886

8987
echo "Setting it to true, per-query, with gle=0\n";
9088
$doc = array("doc" => "ument");
@@ -136,24 +134,9 @@ array(2) {
136134
int(1)
137135
}
138136
Setting it to false, per-query, and w=0 to force no-gle
139-
array(2) {
140-
["j"]=>
141-
bool(false)
142-
["w"]=>
143-
int(0)
144-
}
145-
array(2) {
146-
["j"]=>
147-
bool(false)
148-
["w"]=>
149-
int(0)
150-
}
151-
array(2) {
152-
["j"]=>
153-
bool(false)
154-
["w"]=>
155-
int(0)
156-
}
137+
is_gle_op: no
138+
is_gle_op: no
139+
is_gle_op: no
157140
journal disabled by default
158141
array(2) {
159142
["j"]=>
@@ -193,24 +176,9 @@ array(2) {
193176
int(1)
194177
}
195178
journal disabled by default, and gle
196-
array(2) {
197-
["j"]=>
198-
bool(false)
199-
["w"]=>
200-
int(0)
201-
}
202-
array(2) {
203-
["j"]=>
204-
bool(false)
205-
["w"]=>
206-
int(0)
207-
}
208-
array(2) {
209-
["j"]=>
210-
bool(false)
211-
["w"]=>
212-
int(0)
213-
}
179+
is_gle_op: no
180+
is_gle_op: no
181+
is_gle_op: no
214182
Setting it to true, per-query, with gle=0
215183
array(2) {
216184
["j"]=>

0 commit comments

Comments
 (0)