【问题标题】:MongoDB: How to remove an index on a replicaset?MongoDB:如何删除副本集上的索引?
【发布时间】:2013-11-01 07:29:20
【问题描述】:

我看到MongoDB documentation 说删除索引是通过调用db.accounts.dropIndex( { "tax-id": 1 } )。但它并没有说明该节点是否需要从副本集中移除。

我尝试使副本集中的辅助节点脱机并作为独立节点重新启动(在不同的端口中)并尝试删除索引。

但是在使用常规进程sudo service mongod start 带回副本集中的节点后,mongod 进程正在死亡,说索引已损坏。

 Thu Oct 31 19:52:38.098 [repl writer worker 1] Assertion: 15898:error in index possibly corruption consider repairing 382
0xdddd81 0xd9f55b 0xd9fa9c 0x7edb83 0x7fb332 0x7fdc08 0x9d3b50 0x9c796e 0x9deb64 0xac45dd 0xac58df 0xa903fa 0xa924c7 0xa71f6c 0xc273d3 0xc26b18 0xdab721 0xe26609 0x7ff4d05f0c6b 0x7ff4cf9965ed
 /usr/bin/mongod(_ZN5mongo15printStackTraceERSo+0x21) [0xdddd81]
 /usr/bin/mongod(_ZN5mongo11msgassertedEiPKc+0x9b) [0xd9f55b]
 /usr/bin/mongod() [0xd9fa9c]
 /usr/bin/mongod(_ZN5mongo11checkFailedEj+0x143) [0x7edb83]
 /usr/bin/mongod(_ZNK5mongo12BucketBasicsINS_12BtreeData_V1EE11basicInsertENS_7DiskLocERiS3_RKNS_5KeyV1ERKNS_8OrderingE+0x222) [0x7fb332]
 /usr/bin/mongod(_ZNK5mongo11BtreeBucketINS_12BtreeData_V1EE10insertHereENS_7DiskLocEiS3_RKNS_5KeyV1ERKNS_8OrderingES3_S3_RNS_12IndexDetailsE+0x68) [0x7fdc08]
 /usr/bin/mongod(_ZNK5mongo30IndexInsertionContinuationImplINS_12BtreeData_V1EE22doIndexInsertionWritesEv+0xa0) [0x9d3b50]
 /usr/bin/mongod(_ZN5mongo14IndexInterface13IndexInserter19finishAllInsertionsEv+0x1e) [0x9c796e]
 /usr/bin/mongod(_ZN5mongo24indexRecordUsingTwoStepsEPKcPNS_16NamespaceDetailsENS_7BSONObjENS_7DiskLocEb+0x754) [0x9deb64]
 /usr/bin/mongod(_ZN5mongo11DataFileMgr6insertEPKcPKvibbbPb+0x123d) [0xac45dd]
 /usr/bin/mongod(_ZN5mongo11DataFileMgr16insertWithObjModEPKcRNS_7BSONObjEbb+0x4f) [0xac58df]
 /usr/bin/mongod(_ZN5mongo14_updateObjectsEbPKcRKNS_7BSONObjES4_bbbRNS_7OpDebugEPNS_11RemoveSaverEbRKNS_24QueryPlanSelectionPolicyEb+0x2eda) [0xa903fa]
 /usr/bin/mongod(_ZN5mongo27updateObjectsForReplicationEPKcRKNS_7BSONObjES4_bbbRNS_7OpDebugEbRKNS_24QueryPlanSelectionPolicyE+0xb7) [0xa924c7]
 /usr/bin/mongod(_ZN5mongo21applyOperation_inlockERKNS_7BSONObjEbb+0x65c) [0xa71f6c]
 /usr/bin/mongod(_ZN5mongo7replset8SyncTail9syncApplyERKNS_7BSONObjEb+0x713) [0xc273d3]
 /usr/bin/mongod(_ZN5mongo7replset14multiSyncApplyERKSt6vectorINS_7BSONObjESaIS2_EEPNS0_8SyncTailE+0x48) [0xc26b18]
 /usr/bin/mongod(_ZN5mongo10threadpool6Worker4loopEv+0x281) [0xdab721]
 /usr/bin/mongod() [0xe26609]
 /lib64/libpthread.so.0(+0x7c6b) [0x7ff4d05f0c6b]
 /lib64/libc.so.6(clone+0x6d) [0x7ff4cf9965ed]
Thu Oct 31 19:52:38.106 [repl writer worker 1] ERROR: writer worker caught exception: error in index possibly corruption consider repairing 382 on: 

xxxxxxxx--删除了与数据相关的内容...xxxxxxxxxxxxx

Thu Oct 31 19:52:38.106 [repl writer worker 1]   Fatal Assertion 16360
0xdddd81 0xd9dc13 0xc26bfc 0xdab721 0xe26609 0x7ff4d05f0c6b 0x7ff4cf9965ed
 /usr/bin/mongod(_ZN5mongo15printStackTraceERSo+0x21) [0xdddd81]
 /usr/bin/mongod(_ZN5mongo13fassertFailedEi+0xa3) [0xd9dc13]
 /usr/bin/mongod(_ZN5mongo7replset14multiSyncApplyERKSt6vectorINS_7BSONObjESaIS2_EEPNS0_8SyncTailE+0x12c) [0xc26bfc]
 /usr/bin/mongod(_ZN5mongo10threadpool6Worker4loopEv+0x281) [0xdab721]
 /usr/bin/mongod() [0xe26609]
 /lib64/libpthread.so.0(+0x7c6b) [0x7ff4d05f0c6b]
 /lib64/libc.so.6(clone+0x6d) [0x7ff4cf9965ed]
Thu Oct 31 19:52:38.108 [repl writer worker 1]

***aborting after fassert() failure


Thu Oct 31 19:52:38.108 Got signal: 6 (Aborted).

这是由于在辅助节点上以离线模式删除索引吗?任何有关删除索引的正确方法的建议都非常感谢。

【问题讨论】:

    标签: mongodb


    【解决方案1】:

    从副本集中删除索引的正确方法是将其放到主节点上。副本的想法是拥有相同的数据副本(时间滞后小)。因此,每当您在主节点上执行某些操作时,都会将其复制到辅助节点。因此,如果您开始在主节点上执行任何操作,则在它完成此过程后,该过程会立即传播到辅助节点。

    如果您要从主数据库中删除索引 - 该索引也将在辅助数据库中删除。

    【讨论】:

    • 然而那不是向副本集添加索引的推荐方法。 docs.mongodb.org/manual/tutorial/build-indexes-on-replica-sets
    • @SalvadorDali 感谢您的建议。将尝试将其作为最后一个选项,因为涉及大量数据,并且担心在此期间副本集上的写锁定会使整个副本集阻塞,直到删除索引完成。
    • @AsyaKamsky 我们在副本集中删除索引的工作方式(除了从主节点发出删除索引,如上所述)是停止写入流量,停止主节点并执行删除所有节点上的索引,并将每个节点带回副本集中。不过,这涉及到我们的写入流量中断。
    • @oliTwist 虽然是不必要的 - dropIndex() 不是像 ensureIndex 这样的密集命令,但即使是这样,您也可以使用 docs.mongodb 方法对副本集的每个成员执行此操作。 org/manual/tutorial/build-indexes-on-replica-sets 所以停机时间不需要
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-17
    • 2013-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    相关资源
    最近更新 更多