Definition定义
db.fsyncUnlock()Reduces the lock count on the server to renable write operations.将服务器上的锁计数减少到可重命名的写入操作。Starting in MongoDB 7.1 (also available starting in 7.0.2, 6.0.11, and 5.0.22) the从MongoDB 7.1开始(从7.0.2、6.0.11和5.0.22开始也可用),db.fsyncLock()anddb.fsyncUnlock()methods can run onmongosto lock and unlock a sharded cluster.db.fsyncLock()和db.fsyncUnlock()方法可以在mongos上运行,以锁定和解锁分片集群。Important
mongosh
Method方法This page documents a本页记录了一种mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.mongosh方法。这不是数据库命令或特定语言驱动程序(如Node.js)的文档。For the database command, see the有关数据库命令,请参阅fsyncUnlockcommand.fsyncUnlock命令。For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.有关MongoDB API驱动程序,请参阅特定语言的MongoDB驱动程序文档。Servers maintain an fsync lock count. The服务器维护fsync锁计数。fsyncLock()method increments the lock count while thefsyncUnlock()method decrements it.fsyncLock()方法递增锁计数,而fsyncUnlock()方法递减锁计数。To unlock writes on a server or cluster, call the要解锁服务器或集群上的写入,请调用fsyncUnlock()method until the lock count reaches zero.fsyncUnlock()方法,直到锁定计数达到零。db.fsyncUnlock()is an administrative operation. Use this method to unlock a server or cluster after a backup operation这是一种行政操作。使用此方法在备份操作后解锁服务器或群集db.fsyncUnlock()has the syntax:具有以下语法:db.fsyncUnlock()The operation returns a document with the following fields:该操作返回一个包含以下字段的文档:infoInformation on the status of the operation.有关操作状态的信息。lockCountThe number of locks remaining on the instance after the operation.操作后实例上剩余的锁数。okThe status code.状态代码。Thedb.fsyncUnlock()method wraps thefsyncUnlockcommand.db.fsyncUnlock()方法封装fsyncUnlock命令。
Compatibility兼容性
This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:
Important
This command is not supported in MongoDB Atlas clusters. MongoDB Atlas集群不支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令。
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
Compatibility with WiredTiger与WiredTiger的兼容性
db.fsyncLock() ensures that the data files are safe to copy using low-level backup utilities such as 确保使用cp, scp, or tar. cp、scp或tar等低级备份实用程序可以安全地复制数据文件。A 一个mongod started using the copied files contains user-written data that is indistinguishable from the user-written data on the locked mongod.mongod开始使用复制的文件,其中包含用户写入的数据,这些数据与锁定的mongod上的用户写入数据无法区分。
The data files of a locked 锁定的mongod may change due to operations such as journaling syncs or WiredTiger snapshots. While this has no effect on the logical data (e.g. data accessed by clients), some backup utilities may detect these changes and emit warnings or fail with errors. mongod的数据文件可能会因日志同步或WiredTiger快照等操作而更改。虽然这对逻辑数据(例如客户端访问的数据)没有影响,但一些备份实用程序可能会检测到这些更改并发出警告或出现错误。For more information on MongoDB-recommended backup utilities and procedures, see Backup Methods for a Self-Managed Deployment.有关MongoDB推荐的备份实用程序和过程的更多信息,请参阅自我管理部署的备份方法。
Example示例
Consider a situation where 考虑db.fsyncLock() has been issued two times. The following db.fsyncUnlock() operation reduces the locks taken by db.fsyncLock() by 1:db.fsyncLock()已被发出两次的情况。以下db.fsyncUnlock()操作将db.fsyncLock()占用的锁减少1:
db.fsyncUnlock()
The operation returns the following document:该操作返回以下文档:
{ "info" : "fsyncUnlock completed", "lockCount" : Long(1), "ok" : 1 }
As the 由于lockCount is greater than 0, the mongod instance is locked against writes. lockCount大于0,mongod实例被锁定以防止写入。To unlock the instance for writes, run 要解锁实例进行写入,请再次运行db.fsyncLock() again:db.fsyncLock():
db.fsyncUnlock()
The operation returns the following document:该操作返回以下文档:
{ "info" : "fsyncUnlock completed", "lockCount" : Long(0), "ok" : 1 }
The mongod instance is unlocked for writes.mongod实例已解锁以进行写入。