更新时 MongoDB 游标超时 [英] MongoDB Cursor Timeout on Update

查看:59
本文介绍了更新时 MongoDB 游标超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm currently writing a PHP script to compile data from a number of different CSVs and import the combined document into Mongo. During this process, I'm running into an error with my cursor timing out during an update. Seen here (with included var_dump() for $line and $voterId):

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 分别是有效的字符串和数组:

The "Id" field in the search criteria of the update is indexed and finds executed through the Mongo console or PHP are sub-second. Also if I run the update manually through the Mongo console there are no problems and it runs sub-second. Here's my PHP code, $voterId, and $line are both a valid string and array respectively:

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

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

Currently during development I've got the whole process running locally on my machine. Interestingly enough, when I exit out of the mongod process, I see the query in the log dumped during the exit process which indicates to me that there's a problem with the update. You can see a single server session log from startup to exit with only that single update query running below:

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 行看到转储的查询.

You can see the query dumped in line 19 of that dump.

非常感谢您抽出宝贵时间,如果需要更多信息,请告诉我.

Thanks a lot for your time and let me know if there's any more info required.

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

As requested, here's a var_dump() for $voterId and $line:

$voterId

string(18) "a0Qd0000001kMRwEAM"

$line

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 字段确实已编入索引:

And here's the system.indexes collection showing that the Id field is indeed indexed:

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

推荐答案

我相信答案是围绕查询的简单的一对多数组:

I believe the answer is a simple one-too-many arrays around your query:

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

实际上应该是:

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

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

If I wrap the query in an additional set of brackets, as is the case in this problem, the mongo shell raises an error.

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

In the mongo shell your query would look like:

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

哪个不正确

这篇关于更新时 MongoDB 游标超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆