更新时的MongoDB游标超时

时间:2014-01-07 21:55:30

标签: php mongodb

我目前正在编写一个PHP脚本来编译来自多个不同CSV的数据,并将组合文档导入Mongo。在此过程中,我在更新期间因光标超时而遇到错误。在这里看到(包含$ line和$ voterId的var_dump()):

PHP Fatal error:  Uncaught exception 'MongoCursorTimeoutException' with message 'localhost:27017: Read timed out after reading 0 bytes, waited for 30.000000 seconds' in /Users/georgeyates/Projects/cerebro-jobs/cavers-parse-phone.php:40
Stack trace:
#0 cavers-parse-phone.php(40): MongoCollection->update(Array, Array)
#1 {main}
  thrown in cavers-parse-phone.php on line 40

Fatal error: Uncaught exception 'MongoCursorTimeoutException' with message 'localhost:27017: Read timed out after reading 0 bytes, waited for 30.000000 seconds' in /Users/georgeyates/Projects/cerebro-jobs/cavers-parse-phone.php:40
Stack trace:
#0 cavers-parse-phone.php(40): MongoCollection->update(Array, Array)
#1 {main}
  thrown in cavers-parse-phone.php on line 40

更新搜索条件中的“Id”字段已编制索引,并且通过Mongo控制台或PHP执行的查找是亚秒级。此外,如果我通过Mongo控制台手动运行更新,则没有问题,它会在亚秒内运行。这是我的PHP代码,$ voterId和$ line分别是一个有效的字符串和数组:

$db->Voters->update(array(
    array(
        "Id" => $voterId
    )
),
array(
    '$push' => array(
        "PhoneCalls" => $line
    )
));

目前在开发过程中,我已经在我的机器上本地运行了整个过程。有趣的是,当我退出mongod进程时,我看到在退出过程中转储的日志中的查询向我表明更新存在问题。您可以看到从启动到退出的单个服务器会话日志,只有下面运行的单个更新查询:

Tue Jan  7 16:44:53.266 [initandlisten] MongoDB starting : pid=4963 port=27017 dbpath=/usr/local/var/mongodb 64-bit host=Georges-MacBook-Pro.local
Tue Jan  7 16:44:53.266 [initandlisten] 
Tue Jan  7 16:44:53.266 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
Tue Jan  7 16:44:53.266 [initandlisten] db version v2.4.8
Tue Jan  7 16:44:53.266 [initandlisten] git version: nogitversion
Tue Jan  7 16:44:53.266 [initandlisten] build info: Darwin Georges-MacBook-Pro.local 13.0.2 Darwin Kernel Version 13.0.2: Sun Sep 29 19:38:57 PDT 2013; root:xnu-2422.75.4~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
Tue Jan  7 16:44:53.266 [initandlisten] allocator: tcmalloc
Tue Jan  7 16:44:53.266 [initandlisten] options: { bind_ip: "127.0.0.1", config: "/usr/local/etc/mongod.conf", dbpath: "/usr/local/var/mongodb", logappend: "true", logpath: "/usr/local/var/log/mongodb/mongo.log" }
Tue Jan  7 16:44:53.268 [initandlisten] journal dir=/usr/local/var/mongodb/journal
Tue Jan  7 16:44:53.268 [initandlisten] recover : no journal files present, no recovery needed
Tue Jan  7 16:44:53.474 [websvr] admin web console waiting for connections on port 28017
Tue Jan  7 16:44:53.474 [initandlisten] waiting for connections on port 27017
Tue Jan  7 16:45:23.839 [initandlisten] connection accepted from 127.0.0.1:63253 #1 (1 connection now open)
Tue Jan  7 16:45:57.638 [signalProcessingThread] got signal 2 (Interrupt: 2), will terminate after current cmd ends
Tue Jan  7 16:45:57.640 [signalProcessingThread] now exiting
Tue Jan  7 16:45:57.640 dbexit: 
Tue Jan  7 16:45:57.640 [signalProcessingThread] shutdown: going to close listening sockets...
Tue Jan  7 16:45:57.640 [signalProcessingThread] closing listening socket: 9
Tue Jan  7 16:45:57.640 [conn1] update cavers-import.Voters query: { 0: { Id: "a0Qd0000001kMRwEAM" } } update: { $push: { PhoneCalls: [ "a0ed0000000p75wAAA", "005d00000010pc9AAA", "0", "Phone- 000000000", "2012-09-21 19:16:30", "005d00000010pc9AAA", "2012-09-21 19:16:30", "005d00000010pc9AAA", "2013-01-05 17:18:54", "", "", "", "Sample Question Text appears here !", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "", "", "", "Undecided", "Undecided", "Undecided", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "0", "0", "0", "a0Qd0000001kMRwEAM", "Favorable", "House 55 > 65, VP3-7", "", "", "", "", "", "" ] } } nscanned:816378 keyUpdates:0 exception: interrupted at shutdown code:11600 numYields: 7907 locks(micros) w:62634071 33653ms
Tue Jan  7 16:45:57.640 [signalProcessingThread] closing listening socket: 10
Tue Jan  7 16:45:57.640 [signalProcessingThread] closing listening socket: 11
Tue Jan  7 16:45:57.640 [signalProcessingThread] removing socket file: /tmp/mongodb-27017.sock
Tue Jan  7 16:45:57.641 [signalProcessingThread] shutdown: going to flush diaglog...
Tue Jan  7 16:45:57.641 [signalProcessingThread] shutdown: going to close sockets...
Tue Jan  7 16:45:57.641 [signalProcessingThread] shutdown: waiting for fs preallocator...
Tue Jan  7 16:45:57.641 [signalProcessingThread] shutdown: lock for final commit...
Tue Jan  7 16:45:57.641 [signalProcessingThread] shutdown: final commit...
Tue Jan  7 16:45:57.953 [signalProcessingThread] shutdown: closing all files...
Tue Jan  7 16:45:58.024 [signalProcessingThread] closeAllFiles() finished
Tue Jan  7 16:45:58.024 [signalProcessingThread] journalCleanup...
Tue Jan  7 16:45:58.024 [signalProcessingThread] removeJournalFiles
Tue Jan  7 16:45:58.032 [signalProcessingThread] shutdown: removing fs lock...
Tue Jan  7 16:45:58.032 dbexit: really exiting now

您可以在该转储的第19行中看到转储的查询。

非常感谢您的时间,如果还有其他信息,请告诉我。


编辑:

根据要求,这是$voterId$line的var_dump():

$ voterId

string(18) "a0Qd0000001kMRwEAM"

$线

array(95) {
  [0]=>
  string(18) "a0ed0000000p75wAAA"
  [1]=>
  string(18) "005d00000010pc9AAA"
  [2]=>
  string(1) "0"
  [3]=>
  string(16) "Phone- 000000000"
  [4]=>
  string(19) "2012-09-21 19:16:30"
  [5]=>
  string(18) "005d00000010pc9AAA"
  [6]=>
  string(19) "2012-09-21 19:16:30"
  [7]=>
  string(18) "005d00000010pc9AAA"
  [8]=>
  string(19) "2013-01-05 17:18:54"
  [9]=>
  string(0) ""
  [10]=>
  string(0) ""
  [11]=>
  string(0) ""
  [12]=>
  string(35) "Sample Question Text appears here !"
  [13]=>
  string(0) ""
  [14]=>
  string(0) ""
  [15]=>
  string(0) ""
  [16]=>
  string(0) ""
  [17]=>
  string(0) ""
  [18]=>
  string(0) ""
  [19]=>
  string(0) ""
  [20]=>
  string(0) ""
  [21]=>
  string(0) ""
  [22]=>
  string(0) ""
  [23]=>
  string(0) ""
  [24]=>
  string(0) ""
  [25]=>
  string(0) ""
  [26]=>
  string(0) ""
  [27]=>
  string(0) ""
  [28]=>
  string(0) ""
  [29]=>
  string(0) ""
  [30]=>
  string(0) ""
  [31]=>
  string(0) ""
  [32]=>
  string(0) ""
  [33]=>
  string(0) ""
  [34]=>
  string(0) ""
  [35]=>
  string(0) ""
  [36]=>
  string(0) ""
  [37]=>
  string(0) ""
  [38]=>
  string(0) ""
  [39]=>
  string(0) ""
  [40]=>
  string(0) ""
  [41]=>
  string(0) ""
  [42]=>
  string(0) ""
  [43]=>
  string(1) "0"
  [44]=>
  string(1) "0"
  [45]=>
  string(1) "0"
  [46]=>
  string(1) "0"
  [47]=>
  string(1) "0"
  [48]=>
  string(1) "0"
  [49]=>
  string(1) "0"
  [50]=>
  string(1) "0"
  [51]=>
  string(1) "0"
  [52]=>
  string(1) "0"
  [53]=>
  string(0) ""
  [54]=>
  string(0) ""
  [55]=>
  string(0) ""
  [56]=>
  string(9) "Undecided"
  [57]=>
  string(9) "Undecided"
  [58]=>
  string(9) "Undecided"
  [59]=>
  string(0) ""
  [60]=>
  string(0) ""
  [61]=>
  string(0) ""
  [62]=>
  string(0) ""
  [63]=>
  string(0) ""
  [64]=>
  string(0) ""
  [65]=>
  string(0) ""
  [66]=>
  string(0) ""
  [67]=>
  string(0) ""
  [68]=>
  string(0) ""
  [69]=>
  string(0) ""
  [70]=>
  string(0) ""
  [71]=>
  string(0) ""
  [72]=>
  string(0) ""
  [73]=>
  string(0) ""
  [74]=>
  string(0) ""
  [75]=>
  string(0) ""
  [76]=>
  string(0) ""
  [77]=>
  string(0) ""
  [78]=>
  string(0) ""
  [79]=>
  string(0) ""
  [80]=>
  string(0) ""
  [81]=>
  string(0) ""
  [82]=>
  string(0) ""
  [83]=>
  string(1) "0"
  [84]=>
  string(1) "0"
  [85]=>
  string(1) "0"
  [86]=>
  string(18) "a0Qd0000001kMRwEAM"
  [87]=>
  string(9) "Favorable"
  [88]=>
  string(0) ""
  [89]=>
  string(0) ""
  [90]=>
  string(0) ""
  [91]=>
  string(0) ""
  [92]=>
  string(0) ""
  [93]=>
  string(0) ""
  [94]=>
  string(0) ""
}

这是system.indexes集合,显示Id字段确实已编入索引:

{ "v" : 1, "key" : { "_id" : 1 }, "ns" : "cavers-import.Voters", "name" : "_id_" }
{ "v" : 1, "key" : { "Id" : 1 }, "ns" : "cavers-import.Voters", "name" : "Id_1" }

1 个答案:

答案 0 :(得分:1)

我认为答案是围绕查询的一个简单的一个太多的数组:

   $db->Voters->update(array(
        array(
            "Id" => $voterId
        )
    ), ...

实际应该是:

 $db->Voters->update(
    array(
        "Id" => $voterId
    ), ...

如果我将查询包装在另一组括号中,就像这个问题中的情况一样,mongo shell会引发错误。

在mongo shell中,您的查询将如下所示:

db.Voters.update({{Id: voterId}}, {update info here ...}); 

哪个不正确