故障現象
mongodb重啟後,等了幾十分鐘還一直沒啟動完成,單節點複本集,狀態一直處於startup 原因分析
查看mongod的錯誤記錄檔,發現一直處於building index,但根據之前的經驗,只有在重做secondary節點的時候才會經常處於building index狀態,而這個db是primary節點,於是詳細查看了關於這個building index的全部資訊
2017-01-05T17:24:59.473+0800 [IndexRebuilder] found 1 index(es) that wasn't finished before shutdown
2017-01-05T17:24:59.473+0800 [IndexRebuilder] found 1 interrupted index build(s) on aso.app_version_info_chn1
2017-01-05T17:24:59.473+0800 [IndexRebuilder] note: restart the server with --noIndexBuildRetry to skip index rebuilds
2017-01-05T17:24:59.473+0800 [IndexRebuilder] going to rebuild: { v: 1, unique: true, key: { _fts: "text", _ftsx: 1 }, name: "$**_text", ns: "aso.app_version_info_chn1", weights: { $**: 1 }, default_language: "english", language_override: "language", textIndexVersion: 2 }
2017-01-05T17:24:59.474+0800 [IndexRebuilder] build index on: aso.app_version_info_chn1 properties: { v: 1, unique: true, key: { _fts: "text", _ftsx: 1 }, name: "$**_text", ns: "aso.app_version_info_chn1", weights: { $**: 1 }, default_language: "english", language_override: "language", textIndexVersion: 2 }
2017-01-05T17:24:59.474+0800 [IndexRebuilder] building index using bulk method
根據錯誤記錄檔的提示資訊,看樣子原因是這樣的:在db關閉之前,有一二較大的索引建立的操作沒有完成,db就直接shutdown了,等db再次啟動的時候,mongo預設會將這個index重建好,重建期間處於startup狀態 處理方法
由於不清楚building index到底要持續多久,根據錯誤記錄檔提示,重啟mongod時加上--noIndexBuildRetry參數來跳過索引重建。等啟動完成後,再評估是否需要建立這個index。