定义
db.fsyncUnlock()减少服务器上用于重新启用写入操作的锁计数。
从 MongoDB 7.0.2 开始(从 6.0.11 和 5.0.22 开始也可用),
db.fsyncLock()和db.fsyncUnlock()方法可以在mongos上运行以锁定和解锁分片集群。重要
mongosh 方法
This page documents a
mongoshmethod. This is not the documentation for database commands or language-specific drivers, such as Node.js.有关数据库命令,请参阅
fsyncUnlock命令。如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。
Servers maintain an fsync lock count. The
fsyncLock()method increments the lock count while thefsyncUnlock()method decrements it. To unlock writes on a server or cluster, call thefsyncUnlock()method until the lock count reaches zero.db.fsyncUnlock()is an administrative operation. Use this method to unlock a server or cluster after a backup operationdb.fsyncUnlock()语法为:db.fsyncUnlock() 该操作返回一个包含以下字段的文档:
info有关操作状态的信息。
lockCount操作后实例上剩余的锁数量。
ok状态代码。
The
db.fsyncUnlock()method wraps thefsyncUnlockcommand.
兼容性
此方法可用于以下环境中托管的部署:
重要
MongoDB Atlas 集群不支持此命令。有关 Atlas 对所有命令的支持的信息,请参阅不支持的命令。
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
与 WiredTiger 的兼容性
db.fsyncLock() 确保数据文件可以安全地使用 cp、scp 或 tar 等低级备份实用工具进行复制。开始使用复制文件的 mongod 包含用户写入的数据,这些数据与锁定的 mongod 上的用户写入的数据无法区分。
锁定mongod的数据文件可能会因日志同步或WiredTiger快照等操作而发生变化。虽然这对逻辑数据(例如客户端访问的数据),但某些备份实用程序可能会检测到这些更改并发出警告,或者失败并显示错误。有关MongoDB的更多信息 - 推荐的备份实用程序和过程,请参阅自管理部署的备份方法。
例子
db.fsyncLock()考虑已发出两次 的情况。以下 操作将db.fsyncUnlock() 占用的锁减少db.fsyncLock() 1:
db.fsyncUnlock()
该操作将返回以下文档:
{ "info" : "fsyncUnlock completed", "lockCount" : Long(1), "ok" : 1 }
由于lockCount大于 0,因此mongod实例被锁定以防止写入。 要解锁实例以进行写入,请再次运行db.fsyncLock() :
db.fsyncUnlock()
该操作将返回以下文档:
{ "info" : "fsyncUnlock completed", "lockCount" : Long(0), "ok" : 1 }
mongod实例已解锁,无法写入。