db.stats() 是对 MongoDB 的阻塞调用吗? [英] Is db.stats() a blocking call for MongoDB?

查看:68
本文介绍了db.stats() 是对 MongoDB 的阻塞调用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在研究如何检查 MongoDB 的大小时,我发现 这条评论:

While researching how to check the size of a MongoDB, I found this comment:

请注意,dbstats 在运行时会阻塞您的数据库,因此它不适合在生产环境中使用.https://jira.mongodb.org/browse/SERVER-5714

Be warned that dbstats blocks your database while it runs, so it's not suitable in production. https://jira.mongodb.org/browse/SERVER-5714

查看链接的错误报告(仍处于打开状态),它引用了 Mongo 文档说:

Looking at the linked bug report (which is still open), it quotes the Mongo docs as saying:

命令运行需要一些时间,通常需要几秒钟,除非 .ns 文件非常大(通过使用 --nssize).同时运行其他操作可能会被阻塞.

Command takes some time to run, typically a few seconds unless the .ns file is very large (via use of --nssize). While running other operations may be blocked.

但是,当我查看当前的 Mongo 文档时,我没有找到该文本.相反,他们说:

However, when I check the current Mongo docs, I don't find that text. Instead, they say:

运行命令所需的时间取决于数据库的总大小.由于该命令必须涉及所有数据文件,因此该命令可能需要几秒钟才能运行.

The time required to run the command depends on the total size of the database. Because the command must touch all data files, the command may take several seconds to run.

对于使用 WiredTiger 存储引擎的 MongoDB 实例,在非正常关闭后,大小和计数的统计信息可能会减少多达 1000 个文档,如 collStats、dbStats、count 报告的那样.要恢复集合的正确统计信息,请对集合运行验证.

For MongoDB instances using the WiredTiger storage engine, after an unclean shutdown, statistics on size and count may off by up to 1000 documents as reported by collStats, dbStats, count. To restore the correct statistics for the collection, run validate on the collection.

这是否意味着 WiredTiger 存储引擎通过保持持续的统计数据将其更改为非阻塞调用?

Does this mean the WiredTiger storage engine changed this to a non-blocking call by keeping ongoing stats?

推荐答案

游戏有点晚,但我在寻找答案时发现了这个问题,答案是:是,直到 3.6.12/4.0.5 它正在获取一个共享"锁(R"),该锁在执行期间阻止所有写入请求.之后,它现在是一个意图共享"锁(r"),它不会阻止写入请求.读取请求未受影响.

a bit late to the game but I found this question while looking for the answer, and the answer is: Yes until 3.6.12 / 4.0.5 it was acquiring a "shared" lock ("R") which block all write requests during the execution. After that it's now an "intent shared" lock ("r") which doesn't block write requests. Read requests were not impacted.

来源:https://jira.mongodb.org/browse/SERVER-36437

这篇关于db.stats() 是对 MongoDB 的阻塞调用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆