dongza6247 2012-06-20 17:58
浏览 46
已采纳

Doctrine ODM / MongoDB没有重试查询?

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.

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.

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

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.

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.

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.

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.

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.

  • 写回答

2条回答 默认 最新

  • dongzhang6021 2012-11-06 21:16
    关注

    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.

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化