MongoDB gives us the fsync+lock mechanism to put data violence on the hard drive

Source: Internet
Author: User
Tags file copy

Can the data violence to the hard disk, of course, is possible, MongoDB provides us with a fsync+lock mechanism to meet our needs.

Fsync+lock first will buffer data violence into the hard disk, and then a write lock to the database, the other instances of the write operations are all blocked until Fsync

+lock Release the lock.

It's not going to be tested here.

Locking: Db.runcommand ({"Fsync": 1, "Lock": 1})

Release Lock: Db. $cmd. Unlock.findone ()

Fsync

Forces the mongod process to flush all pending writes from the storage layer to disk. Optionally, you can use to fsync lock the mongod instance and block write operations for the purpose of capturing backups.

As applications write data, MongoDB records the data in the storage layer and then writes the data to disk within the interval, which is a seconds by default. Run when you fsync want to flush writes to disk ahead of the that interval.

The fsync command has the following syntax:

Fsync1Async<boolean>lock<boolean}   

The fsync command has the following fields:

Field Type Description
fsync Integer Enter "1" to apply fsync .
async Boolean Optional. Runs fsync asynchronously. By default, the fsync operation is synchronous.
lock Boolean Optional. Locks mongod instance and blocks all write operations.
Examplesrun asynchronously

The fsync operation is synchronous by default. To run fsync asynchronously with the async field set to true :

Fsync1Async}  

The operation returns immediately. fsyncto view the status of the operation, check the output of db.currentOp() .

Lock mongodInstance

NOTE

Changed in version 3.2: fsync command with the lock option can ensure that the data files does not change for MongoDB Insta NCEs using either the MMAPV1 or the Wiredtiger storage engines, thus providing consistency for the purposes of creating BA Ckups.

In previous MongoDB versions, fsync command with the lock option cannot guarantee a consistent set of files for Low-level backups (e.g. via file copy cp , scp , tar ) for Wiredtiger.

The primary use of was to lock the instance in order-to-back up the fsync mongod files within mongod ' s dbPath . The operation flushes all data to the storage layer and blocks all write operations until you unlock the mongod instance.

To lock the database, with the lock field set to true :

Fsync1lock}  

You could continue to perform read operations on a mongod instance it has a fsync lock. However, after the first write operation all subsequent read operations wait until you unlock the mongod instance.

Unlock mongodInstance

mongodto unlock the, use db.fsyncUnlock() :

DB.  Fsyncunlock();  
See: https://docs.mongodb.com/manual/reference/command/fsync/

MongoDB gives us the fsync+lock mechanism to put data violence on the hard drive

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.