MongoDB修复命令失败 [英] MongoDB repair command failed

查看:68
本文介绍了MongoDB修复命令失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,我的磁盘空间不足,并且mongodb停止工作.然后我增加了磁盘大小,但是mongodb无法开始工作.

Previously i was running out of disk space, and mongodb stopped working. Then I have increased disk size but mongodb does not start working.

尽管我已启用日记功能,但我已执行以下命令
sudo -u mongodb mongod --dbpath/var/lib/mongodb/-修复

Though i have journaling enabled, i have execute following command
sudo -u mongodb mongod --dbpath /var/lib/mongodb/ --repair

但是此修复命令出现异常,停止修复,然后退出.

But this repair command got an exception and stop repairing and then exit.

    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'未成功修复.

news collection is repaired successfully but the 'change_set' does not repair successfully.

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

How can i repair that particular collection (change_set) or database ?

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

UPDATE: When I run mongodump with --repair for that change_set collection i got following error message:

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...

推荐答案

如果 mongod 不能修复,则表明它已损坏到无法修复或无法使用的程度在启动一组有效且正确的数据库文件方面.

If mongod with repair is not doing it, then it is running into a level of corruption that it can't fix or work around in terms of having a valid and correct set of database files to start up.

您可以运行 mongodump 修复,它在尝试解决损坏方面更具攻击性,并且不会启动 mongod 实例(因此,不需要正确的文件即可继续操作).

You can run mongodump with repair, which is more aggressive in terms of trying to get around the corruption, and is not starting a mongod instance (hence does not require the files to be correct in order to proceed).

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

但是请注意,由于它尝试绕过损坏的路径,因此最终可能会获得一个文档的多个副本.关于 mongorestore 的工作方式,这不是问题,但是根据损坏的程度,您最终可能得到的转储文件比您预期的要大得多.在一个极端的情况下,我曾经看到产生了10倍的数据,尽管那是例外,而不是规则.

Be aware though, that because of the way it attempts to route around the corruption, you may end up with multiple copies of a document. With how mongorestore works this is not an issue, but depending on the level of corruption you can end up with dump files far larger than you would expect. In a very extreme case, I once saw 10x data produced, though that was the exception rather than the rule.

一旦您满意地丢弃了所有东西,就开始 mongod 清理并重新导入以恢复到良好状态.

Once you have dumped everything out to your satisfaction, start mongod clean and re-import to get back to a good state.

这篇关于MongoDB修复命令失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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