MongoDB的+天青+安卓:错误:com.mongodb.MongoException:不是说要掌握和重试用完 [英] MongoDB+Azure+Android: Error: com.mongodb.MongoException: not talking to master and retries used up

查看:242
本文介绍了MongoDB的+天青+安卓:错误:com.mongodb.MongoException:不是说要掌握和重试用完的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

我在Azure云服务人员+ Web角色运行,使用蒙戈 - 蔚蓝库。我第一次安装我的Andr​​oid项目连接到MongoDB中/ Azure中,IO(读写)工作。然后,我坠毁因为在我的硬盘codeD试验JSONString一个错字的应用程序,所以蒙戈实例无法正确关闭。修复那些JSONString问题后,我收到以下错误(在堆栈跟踪)和无法访问的MongoDB / Azure上。也许并不关闭连接正确造成的错误?

I have MongoDB replica sets running in Azure cloud service worker + web roles, using mongo-azure library. The first time I setup my Android project to connect to MongoDB/Azure, IO (reads and writes) worked. Then, I crashed the app because of a typo in my hardcoded test JSONString, so the Mongo instance wasn't able to properly close. After fixing that JSONString problem, I received the following error (in stack trace) and wasn't able to access MongoDB/Azure. Perhaps not closing the connection properly caused the error?

问题

这到底是什么这个错误是什么意思?为什么不主实例可用?

What exactly does this error mean? Why wouldn't the master instance be available?

E/AndroidRuntime: com.mongodb.MongoException: not talking to master and retries used up

完整的堆栈跟踪

E/AndroidRuntime(6274): FATAL EXCEPTION: Thread-7108
E/AndroidRuntime(6274): Process: com.myproject.examplemongodb, PID: 6274
E/AndroidRuntime(6274): com.mongodb.MongoException: not talking to master and retries used up
E/AndroidRuntime(6274):     at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:271)
E/AndroidRuntime(6274):     at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:273)
E/AndroidRuntime(6274):     at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:273)
E/AndroidRuntime(6274):     at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:216)
E/AndroidRuntime(6274):     at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:288)
E/AndroidRuntime(6274):     at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:273)
E/AndroidRuntime(6274):     at com.mongodb.DB.getCollectionNames(DB.java:400)
E/AndroidRuntime(6274):     at com.myproject.examplemongodb.ActivityMain$1.run(ActivityMain.java:89)
E/AndroidRuntime(6274):     at java.lang.Thread.run(Thread.java:841)

备注

  • 在我使用的是最新的蒙戈-j​​ava的驱动程序(目前2.11.3)。
  • 在我远程连接到数据库(非本地)。
  • 另一个<一href="http://stackoverflow.com/questions/11308750/com-mongodb-mongoexception-not-talking-to-master-and-retries-used-up">question提到这个错误,但OP采用不同的驱动程序和他的解决方案并不针对Android / Java的工作。
  • I am using the newest mongo-java-driver (currently 2.11.3).
  • I am connecting remotely to database (non-localhost).
  • Another question mentions this error, but OP is using different drivers and his solution does not work for Android/Java.

可能的解决方法

  • 在它看来,关闭从应用程序的连接允许下一次运行正常工作。不过,我还是担心能允许并发连接,这我肯定会喜欢做的事。
    • 更新:我在一个包裹MongoDB的日志和周围我的每个查询将服务器注销,但错误似乎仍然间歇性出现。到目前为止,似乎每一次写操作的工作,但读取只工作一半时间。时间的另一半是发布错误。
    • It appears that closing the connection from the app allowed the next run to work properly. But, I'm still worried about being able allow concurrent connections, which I would definitely like to do.
      • Update: I have wrapped a mongodb log in and log out around each of my queries going to the server, but the error still seems to show up intermittently. So far, it seems that write work every time, but reads only work half the time. The other half of the time is the posted error.

      推荐答案

      的原因间歇性错误是因为默认的阅读preferences驱动程序,主要是关于副本集。默认读取preference是主要的。对于每个下面提到的模式,PRIMARY指的是主数据库(总是最先进的最新)和二级是指从机,它们基本上主人的副本,并非始终保持最新状态。

      The reason for the intermittent errors is because of the default read preferences for the driver, mainly in regards to replica sets. The default read preference is primary. For each of the modes mentioned below, PRIMARY refers to the master database (always the most up-to-date) and SECONDARY refers to slave(s), which are basically the copies of master and are not always up-to-date.

      PRIMARY: The default read mode. Read from primary only. Throw an error if
               primary is unavailable. Cannot be combined with tags.
      

      解决方案更改读取preference下列之一:

      The solution to change the read preference to one of the following:

      PRIMARY PREFERRED: Read from primary if available, otherwise a secondary.
      SECONDARY PREFERRED: Read from a secondary if available, otherwise read from the primary.
      NEAREST: Read from any member node from the set of nodes which respond the fastest.
      

      例如code:

      Example code:

      // Use this when doing a read if you don't care if the data is always consistent.
      // Change the following with secondaryPreferred() if you have high writes, so
      // that you don't interfere with them.
      ReadPreference preference = ReadPreference.primaryPreferred();
      DBCursor cur = new DBCursor(collection, query, null, preference);
      

      有关更多信息,请参见来源

      For more info, see the source.

      这篇关于MongoDB的+天青+安卓:错误:com.mongodb.MongoException:不是说要掌握和重试用完的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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