MongoDB 5.X中有一个非常方便的添加功能,它允许执行快照
在某些读取操作中读取关注,并指定通过 atclustertime
进行快照的时间戳。如果未提供时间戳,则 mongo
将自动选择它,并将其值返回给用户以备将来参考。请参阅:
以来 - 但是,只有具有写入问题的内部交易 - 我想知道是否也可以获取一些有关何时拍摄快照的信息,类似于5.x的操作。我了解我无法明确指定 atoperationTime
,但是 mongo
需要单独选择时间戳,因此似乎可以合理地期望此信息应在某个地方提供。
There's been a really handy addition in MongoDB 5.x that allows enforcing snapshot
read concern in some read operations outside transactions and specify the timestamp at which the snapshot is taken via atClusterTime
. If the timestamp is not provided, mongo
will select it automatically and kindly return its value to the user for future reference. See:
https://www.mongodb.com/docs/v6.0/reference/read-concern-snapshot/#read-concern-and-atclustertime
Since MongoDB 4.x also supports read concern snapshot
- but only inside transactions with write concern majority
- I am wondering if it is also possible to obtain some information about when exactly the snapshot was taken, similarly to what 5.x is doing. I understand that I cannot explicitly specify atOperationTime
but somehow mongo
needs to select the timestamp on its own, so it seems reasonable to expect that this information should be available somewhere.
发布评论
评论(1)
恐怕没有方便的方法可以为Mongo&lt提供集群时间; 5.0。您可以随时检查日志,但我不会认为它是可靠的解决方案。无论如何,这是您可以在mongo shell上运行的脚本:
首先,让我们说
getlog
命令global
过滤器仅返回最新日志,因此,如果您正在寻找旧交易物理日志文件。该脚本:readconcern
参数并打印到控制台,您应该看到输出类似对此:
我们找到了群集时间:
库集团时间
。在第一次交易中,我将文档添加到一个空集合中,这可能就是为什么它不显示群集时间(当然也没有使用)。我不知道每个参数的含义以及您无法获得群集时间的所有情况,但是有个好消息。要获取属于给定事务ID的日志,您需要应用此过滤器(而不是上面显示的一个过滤器):
I am afraid there is no convenient way to get the cluster time for Mongo < 5.0. You can always inspect the logs, but I would not consider it a reliable solution. Anyway, here is a possible script you could run on the mongo shell:
Let's start by saying that the
getLog
command with theglobal
filter returns only the most recent logs, so if you are looking for old transactions I guess you need to parse the physical log files. That script:readConcern
parameters and print them to consoleYou should see an output similar to this one:
We found the cluster time:
afterClusterTime
.In the first transaction, I added a document to an empty collection, which could be why it does not show the cluster time (and was not used, of course). I don't know the meaning of each parameter and all the cases in which you will not get the cluster time, but there is good news. To get the logs, if exist, belonging to a given transaction id, you need to apply this filter (instead of the one shown above):