教条ODM / MongoDB不重试查询? [英] Doctrine ODM / MongoDB not retrying queries?

查看:128
本文介绍了教条ODM / MongoDB不重试查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Doctrine ODM连接到MongoDB。我有一个三节点复制集:两个满一个仲裁器。复制只是为了更高的可用性,我不寻求跨节点分发读取。我的应用程序经常记录 MongoCursorException ,消息不是master和slaveok = false 。我没有看到mongodb日志中发生故障转移事件的任何证据,主要事件没有发生变化。修正:故障切换确实发生,但是 c> c> not master和slaveok = false 的例外情况经常出现,即使在新的初级成功当选。

I'm using Doctrine ODM to connect to MongoDB. I have a three node replica set: two fulls and one arbiter. Replication is solely for higher availability, I don't seek to distribute reads across nodes. My application is logging MongoCursorExceptions every so often with the message not master and slaveok=false. I don't see any evidence that a failover event occurred in the mongodb logs and the primary didn't change. CORRECTION: failover had indeed occurred, but the exception with not master and slaveok=false was appearing often, even showing up 6 hours after a new primary was successfully elected.

该怎么办?我看到我们的 doctrine-mongodb 版本包含(实验?)重试功能,但我没有看到一个简单的方法来实现。

What to do? I see our version of doctrine-mongodb includes (experimental?) retry functionality, but I don't see an easy way to enable that.

不知道是否重要,但这是一个Symfony2(v2.0)应用程序。

Not sure if it matters, but this is a Symfony2 (v2.0) app.

https://groups.google.com/d/topic/mongodb-user/6p710Rdycpg/discussion 意味着我们需要重试(强调我的):

https://groups.google.com/d/topic/mongodb-user/6p710Rdycpg/discussion implies that we need retries (emphasis mine):


您的应用程序必须写入重新连接/重试,因为
任何数字短期(网络)错误可能会像
一样,在正常运行期间的滚动升级过程。

Your application must be written to reconnect/retry since there are any number of transient (network) errors which could come up much like the rolling upgrade process during normal operation.

Mongo PHP扩展程序文档似乎属于accoun这样做:

The Mongo PHP extension docs seem to account for this:


如果第一次尝试失败,驱动程序会自动重试简单查询(而不是命令)几次原因。这是在副本集故障转移期间引起较少的异常(尽管您可能仍然需要处理这些异常),并掩盖瞬时网络问题。

The driver will automatically retry "plain" queries (not commands) a couple of times if the first attempt failed for certain reasons. This is to cause fewer exceptions during replica set failover (although you will probably still have to deal with some) and gloss over transient network issues.

而且我认为 doctrine-mongodb 刚刚使用PHP扩展来与mongod进行交谈。所以我有点困惑,无论我是否应该必须担心重试配置。

And I thought doctrine-mongodb just used the PHP extension to actually talk to mongod. So I'm left a bit confused whether or not I should have to worry about retry configuration.

我想我解决了部分问题:我中删除仲裁器来自Kristina Chodorow的这个建议。我不再看到任何 MongoCursorException ,其中消息 not master和slaveok = false 。我可能已经击中了 https://jira.mongodb.org/browse/PHP-392

I think I solved part of the problem: I removed the arbiter from the connection string following this advice from Kristina Chodorow. I'm no longer seeing any MongoCursorExceptions with the message not master and slaveok=false. I might have been hitting https://jira.mongodb.org/browse/PHP-392.

但是,我仍然收到一些 MongoCursorException ,其中包含消息在故障切换期间无法确定主站。例如,我刚刚做了故障转移;基于mongod日志,几秒钟之后选出了一个新的小组,但网络应用程序甚至在5分钟后就抛出了这个异常。

However, I'm still getting a few MongoCursorExceptions with the message couldn't determine master during failover. For example, I just did a failover; based on the mongod logs, a new primary was elected after a few seconds, but the web application was throwing that exception even 5 minutes later.

推荐答案

我假设您正在使用与DoctrineMongoDBBundle上的2.0分支相对应的标签之一(目前为2.2.1)。 Symfony 2.1+兼容性在标签版本3+以上。

I assume you're using one of the tags (up to 2.2.1 at this time) corresponding to the 2.0 branch on DoctrineMongoDBBundle. Symfony 2.1+ compatibility is in tag versions 3+ of the bundle.

配置类公开了 retry_query 和<$在文档管理器级别的c $ c> retry_connect 选项,默认为零。在YML中,配置将如下所示:

The configuration class exposes retry_query and retry_connect options, which default to zero, at the document manager level. In YML, the configuration would look like:

doctrine_mongodb:
    # Other proxy, hydrator and connection configuration options

    default_document_manager: dm1

    document_managers:
        dm1:
            retry_query: 1
            retry_connect: 1
            # Other mapping, metadata and DM options follow

我意识到这在软件包文档,所以我刚刚在此提交

I realize this wasn't mentioned in the bundle documentation, so I just added a section on it in this commit.

这篇关于教条ODM / MongoDB不重试查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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