1. When a carrier crashes and a hardware or file system error occurs, especially when the hard disk is damaged, data security cannot be guaranteed. In addition, hardware and software of different brands have different persistent guarantees. All in all, if the hardware or file system destroys the data, MongoDB cannot protect the data, which is already part of the underlying storage. Copy can be used to avoid
1. When a carrier crashes and a hardware or file system error occurs, especially when the hard disk is damaged, data security cannot be guaranteed. In addition, hardware and software of different brands have different persistent guarantees. All in all, if the hardware or file system destroys the data, MongoDB cannot protect the data, which is already part of the underlying storage. Copy can be used to avoid
1. When a carrier crashes and a hardware or file system error occurs, especially when the hard disk is damaged, data security cannot be guaranteed. In addition, hardware and software of different brands have different persistent guarantees. All in all, if the hardware or file system destroys the data, MongoDB cannot protect the data, which is already part of the underlying storage. Replication can be used to avoid this problem, which is actually a single point of failure. 2 .? The check corruption validate command is used to detect corruption of a set, such:
> db.posts.validate({full:true}){ "ns" : "ttlsa_com.posts", "firstExtent" : "1:1036000 ns:ttlsa_com.posts", "lastExtent" : "4:2000 ns:ttlsa_com.posts", "extentCount" : 14, "extents" : [ { "loc" : "1:1036000", "xnext" : "1:104e000", "xprev" : "null", "nsdiag" : "ttlsa_com.posts", "size" : 61440, "firstRecord" : "1:1037c30", "lastRecord" : "1:103e4f0" }, { "loc" : "1:104e000", "xnext" : "1:108a000", "xprev" : "1:1036000", "nsdiag" : "ttlsa_com.posts", "size" : 245760, "firstRecord" : "1:104e0b0", "lastRecord" : "1:10556b0" }, { "loc" : "1:108a000", "xnext" : "1:117a000", "xprev" : "1:104e000", "nsdiag" : "ttlsa_com.posts", "size" : 983040, "firstRecord" : "1:108a0b0", "lastRecord" : "1:109a9b0" }, { "loc" : "1:117a000", "xnext" : "1:155e000", "xprev" : "1:108a000", "nsdiag" : "ttlsa_com.posts", "size" : 3932160, "firstRecord" : "1:117a0b0", "lastRecord" : "1:13739f0" }, { "loc" : "1:155e000", "xnext" : "1:24ee000", "xprev" : "1:117a000", "nsdiag" : "ttlsa_com.posts", "size" : 15728640, "firstRecord" : "1:155e0b0", "lastRecord" : "1:1bbe4f0" }, { "loc" : "1:24ee000", "xnext" : "1:392e000", "xprev" : "1:155e000", "nsdiag" : "ttlsa_com.posts", "size" : 21233664, "firstRecord" : "1:24ee8b0", "lastRecord" : "1:2b485b0" }, { "loc" : "1:392e000", "xnext" : "1:56c5000", "xprev" : "1:24ee000", "nsdiag" : "ttlsa_com.posts", "size" : 28667904, "firstRecord" : "1:392e0b0", "lastRecord" : "1:450dd30" }, { "loc" : "1:56c5000", "xnext" : "2:2000", "xprev" : "1:392e000", "nsdiag" : "ttlsa_com.posts", "size" : 38703104, "firstRecord" : "1:56c50b0", "lastRecord" : "1:617c0b0" }, { "loc" : "2:2000", "xnext" : "2:3ad7000", "xprev" : "1:56c5000", "nsdiag" : "ttlsa_com.posts", "size" : 52252672, "firstRecord" : "2:20b0", "lastRecord" : "2:188ac30" }, { "loc" : "2:3ad7000", "xnext" : "2:7e1d000", "xprev" : "2:2000", "nsdiag" : "ttlsa_com.posts", "size" : 70541312, "firstRecord" : "2:3ad7470", "lastRecord" : "2:66b8af0" }, { "loc" : "2:7e1d000", "xnext" : "3:2000", "xprev" : "2:3ad7000", "nsdiag" : "ttlsa_com.posts", "size" : 95232000, "firstRecord" : "2:7e1d0b0", "lastRecord" : "2:be8a2b0" }, { "loc" : "3:2000", "xnext" : "3:dd21000", "xprev" : "2:7e1d000", "nsdiag" : "ttlsa_com.posts", "size" : 128565248, "firstRecord" : "3:20b0", "lastRecord" : "3:63eb670" }, { "loc" : "3:dd21000", "xnext" : "4:2000", "xprev" : "3:2000", "nsdiag" : "ttlsa_com.posts", "size" : 173563904, "firstRecord" : "3:dd210b0", "lastRecord" : "3:12fccc30" }, { "loc" : "4:2000", "xnext" : "null", "xprev" : "3:dd21000", "nsdiag" : "ttlsa_com.posts", "size" : 234311680, "firstRecord" : "4:20b0", "lastRecord" : "4:7bec3b0" } ], "datasize" : 614217440, "nrecords" : 305603, "lastExtentSize" : 234311680, "padding" : 1.0000000000221079, "firstExtentDetails" : { "loc" : "1:1036000", "xnext" : "1:104e000", "xprev" : "null", "nsdiag" : "ttlsa_com.posts", "size" : 61440, "firstRecord" : "1:1037c30", "lastRecord" : "1:103e4f0" }, "lastExtentDetails" : { "loc" : "4:2000", "xnext" : "null", "xprev" : "3:dd21000", "nsdiag" : "ttlsa_com.posts", "size" : 234311680, "firstRecord" : "4:20b0", "lastRecord" : "4:7bec3b0" }, "objectsFound" : 305603, "invalidObjects" : 0, "bytesWithHeaders" : 619107088, "bytesWithoutHeaders" : 614217440, "deletedCount" : 125358, "deletedSize" : 244912976, "nIndexes" : 9, "keysPerIndex" : { "ttlsa_com.posts.$_id_" : 305603, "ttlsa_com.posts.$index_doctorSn" : 305603, "ttlsa_com.posts.$index_doctorUid" : 305603, "ttlsa_com.posts.$index_hosDeptId" : 305603, "ttlsa_com.posts.$index_hospitalId" : 305603, "ttlsa_com.posts.$doctorNumberList_1_doctorOrderId_-1" : 305924, "ttlsa_com.posts.$cityId_1_displayStatus_1" : 305603, "ttlsa_com.posts.$standardDeptId_1_displayStatus_1" : 305603, "ttlsa_com.posts.$doctorCode_1" : 305603 }, "valid" : true, "errors" : [ ], "ok" : 1}
At the bottom of the above output, there is a "valid": true, which indicates no damage. If not, some corrupt details will be found. Most outputs describe the internal structure of the set and are not particularly useful for debugging. Only sets can be detected, but indexes cannot be detected. If an invalid BSONbj occurs, it is usually damaged. The worst is the emergence of pdfile, which is basically the core of mongodb's data storage. It can be judged that the data file is damaged. If any corruption occurs, the following log information is displayed: Tue Dec 20 01:12:09 [initandlisten] Assertion: 10334: Invalid BSONObj size: 285213831 (0x87040011) first element: _ id: objectId ('4e5efa454b4ae20fa6000013 ') if the first element displays garbage, you do not need to do anything. If the first element is visible, you can remove the damaged document. For example,> db. remove ({_ id: ObjectId ('4e5efa454b4ae20fa6000013 ')}) if the file is damaged and not limited to this document, this technology may not work and you still need to fix it. 3. a copy of a persistent replica set can be rolled back until it is written to a majority of sets.> Db. runCommand ({"getLastError": 1, "j": true, "w": "majority"}) can only ensure that the write of primary has been persistent, and secondary may not be persistent.
Original article address: mongodb persistence (3), thanks to the original author for sharing.