MongoDB修复命令失败

时间:2012-12-03 09:11:15

标签: mongodb ruby-on-rails-3 database

以前我的磁盘空间不足,mongodb停止工作。然后我增加了磁盘大小,但是mongodb没有开始工作。

虽然我启用了日记功能,但我执行了以下命令 sudo -u mongodb mongod --dbpath / var / lib / mongodb / --repair

但是这个修复命令出现了异常并停止修复然后退出。

    Fri Nov 30 13:29:36 [initandlisten] build index bd_production.news { _id: 1 }

    Fri Nov 30 13:29:36 [initandlisten]      fastBuildIndex dupsToDrop:0

    Fri Nov 30 13:29:36 [initandlisten] build index done.  scanned 2549 total
    records. 0.008 secs

    Fri Nov 30 13:29:36 [initandlisten]  bd_production.change_sets
    Assertion failure isOk() src/mongo/db/pdfile.h 360

  0x879d86a 0x85a9835 0x85e441e 0x84caa02 0x84c7d19 0x8229b5a 0x822bfd8
 0x875bd51 0x875f0c7 0x8760df4 0x83e6523 0x83b6c3b 0x8753b07 0x83b92bf
 0x8827ab7 0x882a53b 0x882d4bf 0x882d691 0x85ed280 0x81719dc

 mongod(_ZN5mongo15printStackTraceERSo+0x2a) [0x879d86a]

 mongod(_ZN5mongo10logContextEPKc+0xa5) [0x85a9835]
 ...
 ...
 ...
    ... some error msg 

    Fri Nov 30 13:29:36 [initandlisten] assertion 0 assertion
     src/mongo/db/pdfile.h:360 ns:bd_production.change_sets
    query:{}

     Fri Nov 30 13:29:36 [initandlisten] problem detected during query over
     bd_production.change_sets : { $err: "assertion
     src/mongo/db/pdfile.h:360" }

    Fri Nov 30 13:29:36 [initandlisten] query
    bd_production.change_sets ntoreturn:0 keyUpdates:0 exception:
    assertion src/mongo/db/pdfile.h:360  reslen:71 197ms

     Fri Nov 30 13:29:36 [initandlisten] exception in initAndListen: 13106
     nextSafe(): { $err: "assertion src/mongo/db/pdfile.h:360" }, terminating

     Fri Nov 30 13:29:36 dbexit:
    ...
    ...

新闻集合已成功修复,但'change_set'无法成功修复。

如何修复特定的集合(change_set)或数据库?

更新 当我使用--repair为该change_set集合运行mongodump时,我收到以下错误消息:

Tue Dec  4 10:45:21 [tools]         backwards extent pass
Tue Dec  4 10:45:21 [tools]             extent loc: 5:1181e000
Tue Dec  4 10:45:21 [FileAllocator] allocating new datafile /home/suvankar/dd/bd_production.5, filling with zeroes...
Tue Dec  4 10:45:21 [FileAllocator] creating directory /home/suvankar/dd/_tmp
Tue Dec  4 10:45:21 [FileAllocator] done allocating datafile /home/suvankar/dd/bd_production.5, size: 511MB,  took 0.042 secs
Tue Dec  4 10:45:21 [tools]                 warning: Extent not ok magic: 0 going to try to continue
Tue Dec  4 10:45:21 [tools]                 length:0
Tue Dec  4 10:45:21 [tools]                     ERROR: offset is 0 for record which should be impossible
Tue Dec  4 10:45:21 [tools]                     wrote 1 documents
Tue Dec  4 10:45:21 [tools]             extent loc: 0:0
Tue Dec  4 10:45:21 [tools]                 ERROR: invalid extent ofs: 0
Tue Dec  4 10:45:21 [tools]                  5 objects
Tue Dec  4 10:45:21 dbexit: 
Tue Dec  4 10:45:21 [tools] shutdown: going to close listening sockets...
Tue Dec  4 10:45:21 [tools] shutdown: going to flush diaglog...
Tue Dec  4 10:45:21 [tools] shutdown: going to close sockets...
Tue Dec  4 10:45:21 [tools] shutdown: waiting for fs preallocator...
Tue Dec  4 10:45:21 [tools] shutdown: lock for final commit...

1 个答案:

答案 0 :(得分:4)

如果带有修复的mongod没有这样做,那么它就会遇到一个腐败级别,它无法修复或解决方案,无法启动有效且正确的数据库文件集。

您可以运行mongodump with repair,这在尝试绕过损坏方面更具攻击性,并且没有启动mongod实例(因此不要求文件正确以便继续进行)。

mongodump --repair --dbpath /var/lib/mongodb/ <other options here>

请注意,由于它试图绕过损坏的方式,您最终可能会得到文档的多个副本。有了mongorestore的工作方式,这不是问题,但根据损坏程度,最终可能会出现远大于预期的转储文件。在一个非常极端的情况下,我曾经看过产生10倍的数据,尽管这是例外而不是规则。

一旦您将所有内容全部转出,请开始mongod清理并重新导入以恢复良好状态。