定义
fsyncUnlock减少服务器或集群上的锁计数。 要启用写入操作,锁计数必须为零。
从MongoDB 7.0.2开始 (从6.0.11和5.0.22开始也可用)
fsync和fsyncUnlock命令可以在mongos上运行以锁和解锁分片集群。完成备份操作后,使用此命令取消阻止写入。
重要
Servers maintain an fsync lock count. The
fsynccommand with thelockfield set totrueincrements the lock count while thefsyncUnlockcommand decrements it. To enable writes on a locked server or cluster, call thefsyncUnlockcommand until the lock count reaches zero.fsyncUnlockis an administrative operation. Typically you will usefsyncUnlockfollowing a database backup operation.提示
In
mongosh, this command can also be run through thedb.fsyncUnlock()helper method.Helper methods are convenient for
mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
该命令具有以下语法:
db.adminCommand( { fsyncUnlock: 1, comment: <any> } )
comment字段是可选的,可以包含任何数据类型的注释。
结果
该操作返回一个包含以下字段的文档:
字段 | 说明 |
|---|---|
| 有关操作状态的信息 |
| 操作后实例上剩余的锁数量。 |
| 状态代码。 |
示例
db.fsyncLock()考虑已发出两次 的情况。以下 操作将fsyncUnlock 占用的锁减少db.fsyncLock() 1:
db.adminCommand( { fsyncUnlock: 1 } )
该操作将返回以下文档:
{ "info" : "fsyncUnlock completed", "lockCount" : Long(1), "ok" : 1 }
由于lockCount大于 0,因此mongod实例被锁定以防止写入。 要解锁实例以进行写入,请再次运行解锁操作:
db.adminCommand( { fsyncUnlock: 1 } )
该操作将返回以下文档:
{ "info" : "fsyncUnlock completed", "lockCount" : Long(0), "ok" : 1 }
mongod实例已解锁,无法写入。