Table of Contents
1. 载体崩溃" >1. 载体崩溃
2. ?检查损坏" >2. ?检查损坏
3. 复制的持久性" >3. 复制的持久性
Home Database Mysql Tutorial mongodb 持久化(3)

mongodb 持久化(3)

Jun 07, 2016 pm 04:36 PM
mongodb Appear collapse Endurance document hardware question

1. 载体崩溃 当出现硬件问题或文件系统出错,特别是硬盘损坏了,就没法保护数据安全了。另外,不同品牌的硬件和软件具有不同的持久保证的。总而言之,如果硬件或文件系统破坏了数据,MongoDB是无法保护数据的,这已经属于底层存储的事情了。可以使用复制来避

1. 载体崩溃

当出现硬件问题或文件系统出错,特别是硬盘损坏了,就没法保护数据安全了。另外,不同品牌的硬件和软件具有不同的持久保证的。 总而言之,如果硬件或文件系统破坏了数据,MongoDB是无法保护数据的,这已经属于底层存储的事情了。可以使用复制来避免这个问题,其实就是单点问题了。

2. ?检查损坏

validate命令用来检测一个集合的损坏,如:
> 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
}
Copy after login
在上面输出底部,有个"valid" : true 说明没有损坏,如果不是,会找到一些损坏的细节。大部分输出是描述集合内部的结构,对于调试不是特别有用的。 只能检测集合,不能检测索引。 如果出现无效的BSONbj,通常就是损坏了。最糟糕的是出现pdfile,pdfile基本上是mongodb的数据存储核心,几乎可以判断数据文件已经损坏了。 如果出现损坏,会看到下面的日志信息: Tue Dec 20 01:12:09 [initandlisten] Assertion: 10334: Invalid BSONObj size: 285213831 (0x87040011) first element: _id: ObjectId('4e5efa454b4ae20fa6000013') 如果第一个元素显示的是垃圾,不需要做什么。如果第一个元素是可见的,可以移除损坏的文档。如: > db.remove({_id: ObjectId('4e5efa454b4ae20fa6000013')}) 如果损坏并不局限于该文档,这种技术可能无法工作,你仍然需要进行修复。

3. 复制的持久性

复制集一个写可被回滚,直到它被写入到一个大多数的集合中。 > db.runCommand({"getLastError" : 1, "j" : true, "w" : "majority"}) 只能保证primary写入已经持久化,secondary未必持久化。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the use of net4.0 What is the use of net4.0 May 10, 2024 am 01:09 AM

.NET 4.0 is used to create a variety of applications and it provides application developers with rich features including: object-oriented programming, flexibility, powerful architecture, cloud computing integration, performance optimization, extensive libraries, security, Scalability, data access, and mobile development support.

How to configure MongoDB automatic expansion on Debian How to configure MongoDB automatic expansion on Debian Apr 02, 2025 am 07:36 AM

This article introduces how to configure MongoDB on Debian system to achieve automatic expansion. The main steps include setting up the MongoDB replica set and disk space monitoring. 1. MongoDB installation First, make sure that MongoDB is installed on the Debian system. Install using the following command: sudoaptupdatesudoaptinstall-ymongodb-org 2. Configuring MongoDB replica set MongoDB replica set ensures high availability and data redundancy, which is the basis for achieving automatic capacity expansion. Start MongoDB service: sudosystemctlstartmongodsudosys

How to ensure high availability of MongoDB on Debian How to ensure high availability of MongoDB on Debian Apr 02, 2025 am 07:21 AM

This article describes how to build a highly available MongoDB database on a Debian system. We will explore multiple ways to ensure data security and services continue to operate. Key strategy: ReplicaSet: ReplicaSet: Use replicasets to achieve data redundancy and automatic failover. When a master node fails, the replica set will automatically elect a new master node to ensure the continuous availability of the service. Data backup and recovery: Regularly use the mongodump command to backup the database and formulate effective recovery strategies to deal with the risk of data loss. Monitoring and Alarms: Deploy monitoring tools (such as Prometheus, Grafana) to monitor the running status of MongoDB in real time, and

How to read and write files concurrently in Golang? How to read and write files concurrently in Golang? Jun 05, 2024 pm 06:12 PM

Concurrent file reading: create a goroutine to read data blocks concurrently, and use pipeline communication coordination; concurrent file writing: use goroutine to write data, and use a mutex to protect the write operation.

Best practices for data modeling and persistence in PHP frameworks Best practices for data modeling and persistence in PHP frameworks Jun 04, 2024 pm 01:43 PM

In the PHP framework, best practices for data modeling include using appropriate data types, applying constraints, considering indexes, and using ER diagrams. Best practices for persistence include using ORM tools, DAOs, handling transactions, and enforcing data validation. Following these practices ensures maintainable, efficient, and scalable code and maintains data integrity and reliability.

Technical comparison of persistence middleware in java framework Technical comparison of persistence middleware in java framework Jun 03, 2024 pm 01:24 PM

Java persistence middleware technology comparison: JDBC: scalable and efficient, but verbose and error-prone. Hibernate: Easy to use, offers advanced features, but can be slow. JPA: Standardized and compatible with JavaEE, but has more configuration restrictions. Choosing the right technology depends on application needs: JDBC focuses on control and scalability, Hibernate/JPA focuses on development efficiency and functionality.

Major update of Pi Coin: Pi Bank is coming! Major update of Pi Coin: Pi Bank is coming! Mar 03, 2025 pm 06:18 PM

PiNetwork is about to launch PiBank, a revolutionary mobile banking platform! PiNetwork today released a major update on Elmahrosa (Face) PIMISRBank, referred to as PiBank, which perfectly integrates traditional banking services with PiNetwork cryptocurrency functions to realize the atomic exchange of fiat currencies and cryptocurrencies (supports the swap between fiat currencies such as the US dollar, euro, and Indonesian rupiah with cryptocurrencies such as PiCoin, USDT, and USDC). What is the charm of PiBank? Let's find out! PiBank's main functions: One-stop management of bank accounts and cryptocurrency assets. Support real-time transactions and adopt biospecies

What is a cryptocurrency crash? What are the strategies for beginners to deal with cryptocurrency crashes? What is a cryptocurrency crash? What are the strategies for beginners to deal with cryptocurrency crashes? Mar 03, 2025 pm 09:03 PM

Cryptocurrency market volatility and coping strategies Cryptocurrency markets are known for their drastic volatility, and investors often face the risk of a sharp decline in asset value. This article will explore the reasons for the collapse of the cryptocurrency market and provide coping strategies to help investors stay rational and reduce risks during market turmoil. What is the collapse of the cryptocurrency market? The sharp fluctuation of cryptocurrency prices in the short term is a market collapse. Such events may be triggered by a variety of factors, such as: changes in regulatory policies, changes in market sentiment, fluctuations in the macroeconomic environment, etc. When major events occur, panic selling often exacerbates market declines. The lack of regulation in the cryptocurrency market also makes it more susceptible to manipulation and speculation. Regulatory changes: New regulatory policies may lead to increased investor uncertainty and trigger a sell-off.

See all articles