简体   繁体   English

教义ODM / MongoDB是否不重试查询?

[英]Doctrine ODM / MongoDB not retrying queries?

I'm using Doctrine ODM to connect to MongoDB. 我正在使用Doctrine ODM连接到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 MongoCursorException s every so often with the message not master and slaveok=false . 我的应用程序经常记录MongoCursorException ,消息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. 我没有看到任何证据表明mongodb日志中发生了故障转移事件,并且主事件没有发生变化。 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. 改正: 确实发生了故障转移 ,但是经常出现异常( not master and slaveok=false ),甚至在成功选出新的主not master and slaveok=false后的6小时内也出现了。

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. 我看到我们的doctrine-mongodb版本包含(实验性?)重试功能 ,但是我看不到启用它的简便方法。

Not sure if it matters, but this is a Symfony2 (v2.0) app. 不确定是否重要,但这是一个Symfony2(v2.0)应用程序。

https://groups.google.com/d/topic/mongodb-user/6p710Rdycpg/discussion implies that we need retries (emphasis mine): https://groups.google.com/d/topic/mongodb-user/6p710Rdycpg/discussion表示我们需要重试(强调我的意思):

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 . 必须编写您的应用程序才能重新连接/重试,因为可能会出现许多瞬时(网络)错误,就像在正常操作期间的滚动升级过程一样。

The Mongo PHP extension docs seem to account for this: Mongo PHP扩展文档似乎说明了这一点:

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. 这将在副本集故障转移期间引起较少的异常(尽管您可能仍将不得不处理一些异常),并避免出现瞬态网络问题。

And I thought doctrine-mongodb just used the PHP extension to actually talk to mongod. 而且我认为doctrine-mongodb只是使用PHP扩展与mongod进行了实际对话。 So I'm left a bit confused whether or not I should have to worry about retry configuration. 因此,我是否应该担心重试配置让我有些困惑。

I think I solved part of the problem: I removed the arbiter from the connection string following this advice from Kristina Chodorow . 我想我已经解决了部分问题:我按照Kristina Chodorow的建议从连接字符串中删除了仲裁程序 I'm no longer seeing any MongoCursorException s with the message not master and slaveok=false . 我再也看不到任何MongoCursorException消息, not master and slaveok=false消息。 I might have been hitting https://jira.mongodb.org/browse/PHP-392 . 我可能一直在点击https://jira.mongodb.org/browse/PHP-392

However, I'm still getting a few MongoCursorException s with the message couldn't determine master during failover. 但是,我仍然遇到一些MongoCursorException ,并且消息在故障转移期间couldn't determine master服务器。 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. 根据mongod日志,几秒钟后便选择了一个新的主数据库,但Web应用程序甚至在5分钟后仍抛出该异常。

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. 我假设您正在使用与DoctrineMongoDBBundle上的2.0分支相对应的标记之一(当前为2.2.1)。 Symfony 2.1+ compatibility is in tag versions 3+ of the bundle. Symfony 2.1+的兼容性在捆绑软件的3+版本中。

The configuration class exposes retry_query and retry_connect options, which default to zero, at the document manager level. 配置类在文档管理器级别公开retry_queryretry_connect选项,默认情况下为零。 In YML, the configuration would look like: 在YML中,配置如下所示:

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 . 我意识到捆绑包文档中没有提到这点,所以我在提交中添加了一段。

Have you configured the replicaSet option to point to your designated replica set configured within MongoDB? 您是否配置了copysetSet选项以指向在MongoDB中配置的指定副本集?

Symfony DoctrineMongoDBBundle Docs Symfony主义MongoDB捆绑文档

Look at the full configuration at the bottom. 查看底部的完整配置。 As far as I know you need to name all the servers in the server config line AND name the replicaSet in the options section. 据我知道你需要来命名服务器配置行中的所有服务器名称的选项部分的replicaSet。 The documentation on that page doesn't make that very clear. 该页面上的文档并不清楚。

Looking through the code. 查看代码。 It looks like the retry system should be configured by setting. 看起来重试系统应该通过设置进行配置。

retryConnect
retryQuery

At the same level as the database name. 与数据库名称处于同一级别。

This is an example of my Zend Framework config which essentially does the same thing. 这是我的Zend Framework配置的一个示例,该配置实际上执行相同的操作。

; Database details
resources.odm.configuration.defaultDB = "test"
resources.odm.connection.options.replicaSet = "test-replica-set"
resources.odm.connection.server = "mongodb://rs1a.testing.com:27017,rs1b.testing.com:27017,rs1c.testing.com:27017"
resources.odm.configuration.retryConnect = 3
resources.odm.configuration.retryQuery = 3

I was getting similar errors when I didn't have the replicaSet configured. 当我没有配置plicateSet时,我得到了类似的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM