为什么MongoDB在简单插入后崩溃了?

时间:2014-01-21 16:27:28

标签: php mongodb

在简单的文档插入中,我的MongoDB服务器有时会意外崩溃。 在我插入此文档的集合中,大约有1400万个文档。

  • MongoDB版本:Debian上的2.4.9
  • php_mongo version:1.4.5
  • PHP版本:5.4.14

我使用的代码:

$data = ["type"          => "Test"];
$res = $db->test->insert($data);

我得到的错误:

Fatal error: Uncaught exception 'MongoCursorException' with message 'Couldn't get connection: Failed to connect to: 192.168.2.23:27017: Remote server has closed the connection' in C:\xx\Data.php on line 160

MongoCursorException: Couldn't get connection: Failed to connect to: 192.168.2.23:27017: Remote server has closed the connection in C:\xx\Data.php on line 160

mongod日志:

    Tue Jan 21 16:55:07.433 [initandlisten] connection accepted from 192.168.10.80:43934 #1 (1 connection now open)
    Tue Jan 21 16:55:19.995 [conn1] insert xxx.activity ninserted:1 keyUpdates:0 locks(micros) w:124101 124ms
    Tue Jan 21 16:55:52.168 [conn1]  xxx.activity Deleted record list corrupted in bucket 18, link number 9, invalid link is 1788887572:6aa04074, throwing Fatal Assertion
    Tue Jan 21 16:55:52.168 [conn1]  xxx.activity Fatal Assertion 16469
    0xde46e1 0xda44d3 0xa633c8 0xa63c42 0xac91c3 0xaca5af 0x9f8a69 0x9f94d9 0x9ffd68 0x6e8518 0xdd0cae 0x7fdc1efbdb50 0x7fdc1e360a7d
     /usr/bin/mongod(_ZN5mongo15printStackTraceERSo+0x21) [0xde46e1]
     /usr/bin/mongod(_ZN5mongo13fassertFailedEi+0xa3) [0xda44d3]
     /usr/bin/mongod(_ZN5mongo16NamespaceDetails10__stdAllocEib+0x488) [0xa633c8]
     /usr/bin/mongod(_ZN5mongo16NamespaceDetails13allocWillBeAtEPKci+0x32) [0xa63c42]
     /usr/bin/mongod(_ZN5mongo11DataFileMgr6insertEPKcPKvibbbPb+0x1153) [0xac91c3]
     /usr/bin/mongod(_ZN5mongo11DataFileMgr16insertWithObjModEPKcRNS_7BSONObjEbb+0x4f) [0xaca5af]
     /usr/bin/mongod(_ZN5mongo14checkAndInsertEPKcRNS_7BSONObjE+0x119) [0x9f8a69]
     /usr/bin/mongod(_ZN5mongo14receivedInsertERNS_7MessageERNS_5CurOpE+0x929) [0x9f94d9]
     /usr/bin/mongod(_ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE+0xab8) [0x9ffd68]
     /usr/bin/mongod(_ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE+0x98) [0x6e8518]
     /usr/bin/mongod(_ZN5mongo17PortMessageServer17handleIncomingMsgEPv+0x42e) [0xdd0cae]
     /lib/x86_64-linux-gnu/libpthread.so.0(+0x6b50) [0x7fdc1efbdb50]
     /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7fdc1e360a7d]
    Tue Jan 21 16:55:52.227 [conn1]
    ***aborting after fassert() failure
    Tue Jan 21 16:55:52.228 Got signal: 6 (Aborted).
    Tue Jan 21 16:55:52.237 Backtrace:
    0xde46e1 0x6d06c9 0x7fdc1e2b84f0 0x7fdc1e2b8475 0x7fdc1e2bb6f0 0xda450e 0xa633c8 0xa63c42 0xac91c3 0xaca5af 0x9f8a69 0x9f94d9 0x9ffd68 0x6e8518 0xdd0cae 0x7fdc1efbdb50 0x7fdc1e360a7d
     /usr/bin/mongod(_ZN5mongo15printStackTraceERSo+0x21) [0xde46e1]
     /usr/bin/mongod(_ZN5mongo10abruptQuitEi+0x399) [0x6d06c9]
     /lib/x86_64-linux-gnu/libc.so.6(+0x324f0) [0x7fdc1e2b84f0]
     /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x35) [0x7fdc1e2b8475]
     /lib/x86_64-linux-gnu/libc.so.6(abort+0x180) [0x7fdc1e2bb6f0]
     /usr/bin/mongod(_ZN5mongo13fassertFailedEi+0xde) [0xda450e]
     /usr/bin/mongod(_ZN5mongo16NamespaceDetails10__stdAllocEib+0x488) [0xa633c8]
     /usr/bin/mongod(_ZN5mongo16NamespaceDetails13allocWillBeAtEPKci+0x32) [0xa63c42]
     /usr/bin/mongod(_ZN5mongo11DataFileMgr6insertEPKcPKvibbbPb+0x1153) [0xac91c3]
     /usr/bin/mongod(_ZN5mongo11DataFileMgr16insertWithObjModEPKcRNS_7BSONObjEbb+0x4f) [0xaca5af]
     /usr/bin/mongod(_ZN5mongo14checkAndInsertEPKcRNS_7BSONObjE+0x119) [0x9f8a69]
     /usr/bin/mongod(_ZN5mongo14receivedInsertERNS_7MessageERNS_5CurOpE+0x929) [0x9f94d9]
     /usr/bin/mongod(_ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE+0xab8) [0x9ffd68]
     /usr/bin/mongod(_ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE+0x98) [0x6e8518]
     /usr/bin/mongod(_ZN5mongo17PortMessageServer17handleIncomingMsgEPv+0x42e) [0xdd0cae]
     /lib/x86_64-linux-gnu/libpthread.so.0(+0x6b50) [0x7fdc1efbdb50]
     /lib/x86_64-linux-gnu/libc.so.6(clone+0x6d) [0x7fdc1e360a7d]

重启时,mongod说:

     Tue Jan 21 17:04:33.521 [initandlisten] journal dir=/var/lib/mongodb/journal
    Tue Jan 21 17:04:33.521 [initandlisten] recover begin
    Tue Jan 21 17:04:33.521 [initandlisten] recover lsn: 34950
    Tue Jan 21 17:04:33.521 [initandlisten] recover /var/lib/mongodb/journal/j._0
    Tue Jan 21 17:04:33.554 [initandlisten] recover skipping application of section seq:0 < lsn:34950
    Tue Jan 21 17:04:33.944 [initandlisten] recover cleaning up
    Tue Jan 21 17:04:33.944 [initandlisten] removeJournalFiles
    Tue Jan 21 17:04:34.175 [initandlisten] recover done
    Tue Jan 21 17:04:34.175 [initandlisten] preallocating a journal file /var/lib/mongodb/journal/prealloc.0
    Tue Jan 21 17:04:37.065 [initandlisten]                 File Preallocator Progress: 1059061760/1073741824       98%
    Tue Jan 21 17:04:37.933 [initandlisten] waiting for connections on port 27017
    Tue Jan 21 17:04:37.934 [websvr] admin web console waiting for connections on port 28017

当我使用控制台时:

> db.activity.insert({Type: "test"})
Tue Jan 21 17:40:10.161 Socket recv() errno:104 Connection reset by peer 127.0.0.1:27017
Tue Jan 21 17:40:10.178 SocketException: remote: 127.0.0.1:27017 error: 9001 socket exception [RECV_ERROR] server [127.0.0.1:27017]
Tue Jan 21 17:40:10.178 DBClientCursor::init call() failed
Tue Jan 21 17:40:10.178 Error: error doing query: failed at src/mongo/shell/query.js:78
Tue Jan 21 17:40:10.179 trying reconnect to 127.0.0.1:27017
Tue Jan 21 17:40:10.179 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
>

有什么建议吗?

2 个答案:

答案 0 :(得分:6)

看起来数据文件已损坏(已删除的记录列表已损坏)。其他人似乎have run into the same issue之前。

您可能必须使用--repair来修复数据文件。阅读documentation on repairDatabase,特别是说明--repair删除损坏的数据的部分,如果可以,请进行备份。

答案 1 :(得分:0)

看起来你的数据存在问题,删除mongo storage目录中的所有内容(如果可以的话),重新启动mongo并重试。

不要忘记在删除之前备份所有数据。