MongoDB的+天青+安卓com.mongodb.WriteConcernException错误:"没有掌握" code:" 10058" [英] MongoDB+Azure+Android: com.mongodb.WriteConcernException err: "not master" code: "10058"

查看:1709
本文介绍了MongoDB的+天青+安卓com.mongodb.WriteConcernException错误:"没有掌握" code:" 10058"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景

我正在运行的MongoDB副本在Azure上设置并已连接到它在一个Android应用程序远程。我已经得到读取工作,极大的所有实例(更新时间:因为他们被允许读小学和中学节点上)。但是,写入数据库仍然有以下错误间歇性错误,因为写操作只能在主节点上完成。

Hi, I am running a MongoDB replica set on Azure and have connected to it remotely from within an Android app. I've gotten reads to work great from all instances (Updated: Because they are allowed to read on primary and secondary nodes). But, writes to the database still have intermittent errors with the following error, because writes must be done on the primary node only.

另外,如果你能处理这个问题提供任何更具体的资源,那么这将是非常有帮助了。我已经通过大部分的文档已经消失了,搜索了不少此错误。

Also, if you could provide any more specific resources for dealing with this issue, then that would be very helpful too. I've already gone through most of the docs and searched quite a bit for this error.

问题

如何prevent这个错误,并允许写的100%的时间?

How to prevent this error and allow writes 100% of the time?

E/AndroidRuntime(): com.mongodb.WriteConcernException: {
        "serverUsed" : "/<my-remote-ip>:27017" , "err" : "not master" , 
        "code" : 10058 , "n" : 0 , "lastOp" : { "$ts" : 0 , "$inc" : 0} , 
        "connectionId" : 1918 , "ok" : 1.0}

堆栈跟踪

E/AndroidRuntime(13731): FATAL EXCEPTION: Thread-7629
E/AndroidRuntime(13731): Process: com.myapplication.examplemongodb, PID: 13731
E/AndroidRuntime(13731): com.mongodb.WriteConcernException: { "serverUsed" : "/<my-remote-ip>:27017" , "err" : "not master" , "code" : 10058 , "n" : 0 , "lastOp" : { "$ts" : 0 , "$inc" : 0} , "connectionId" : 1918 , "ok" : 1.0}
E/AndroidRuntime(13731):    at com.mongodb.CommandResult.getException(CommandResult.java:77)
E/AndroidRuntime(13731):    at com.mongodb.CommandResult.throwOnError(CommandResult.java:110)
E/AndroidRuntime(13731):    at com.mongodb.DBTCPConnector._checkWriteError(DBTCPConnector.java:102)
E/AndroidRuntime(13731):    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:142)
E/AndroidRuntime(13731):    at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:115)
E/AndroidRuntime(13731):    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:248)
E/AndroidRuntime(13731):    at com.mongodb.DBApiLayer$MyCollection.insert(DBApiLayer.java:204)
E/AndroidRuntime(13731):    at com.mongodb.DBCollection.insert(DBCollection.java:76)
E/AndroidRuntime(13731):    at com.mongodb.DBCollection.insert(DBCollection.java:60)
E/AndroidRuntime(13731):    at com.mongodb.DBCollection.insert(DBCollection.java:105)
E/AndroidRuntime(13731):    at com.myapplication.examplemongodb.ActivityMain$1.run(ActivityMain.java:83)
E/AndroidRuntime(13731):    at java.lang.Thread.run(Thread.java:841)

备注

  • 在我使用蒙戈-j​​ava的驱动程序v2.11.3
  • 我用蒙戈 - 蔚蓝库,以帮助创建的MongoDB副本集的两个辅助角色。
    • (如果您有这更多的资源,那么我很愿意读它。我已经阅读过了GitHub的自述,的这个,的这个,并没有涉及到的MongoDB / Azure中的一些其他的事情。但是,这些资源不更新,也没有详细说明。)
    • I am using mongo-java-driver v2.11.3.
    • I used the mongo-azure library to help create the MongoDB replica set with two worker roles.
      • (If you have any more resources for this, then I'd love to read it. I've already read the GitHub readme, this, this, and a few other things not related to MongoDB/Azure. But, those resources are not updated, nor detailed.)

      可能的解决方案

      • 有事情做与具有副本集,我认为。
      • 在我没有确定是否发生这种情况,因为我只有两个实例副本集(一个小学和一个辅助),他们战斗(读:投票)超过谁愿意成为主要的。也许,一个仲裁器是必需的?但是,我不知道该怎么做,目前。

      更新

      • 感谢@大卫Makogon的帮助下,我是pretty的肯定与我如何设置连接到Azure的问题在于,如何我访问辅助角色。所以,这里是对系统的配置我的更新注意事项:
        • 在两个工作角色(MongoDB.WindowsAzure.MongoDBRole),我直接通过 TCP输入终结端口27017的Andr​​oid应用程序连接到。正如@大卫说,我目前还没有控制哪些该实例连接。
        • 在一个Web角色(MongoDB.WindowsAzure.Manager),我没有做任何事情,有一个 HTTP输入终结 80端口上。这只是所作默认与蒙戈 - 蔚蓝库我上面提到的。我不知道如果有什么我应该做的与此有关。
        • Thanks to the help of @David Makogon, I'm pretty sure the issue lies with how I have set up the connection to Azure, and how I access the worker roles. So, here's my updated notes on how the system is configured:
          • Two worker roles (MongoDB.WindowsAzure.MongoDBRole), which I connect directly to via TCP Input Endpoint port 27017 from the Android app. As @David said, I currently have no control over which which instance is connected to.
          • One web role (MongoDB.WindowsAzure.Manager), which I don't do anything with, has one HTTP Input Endpoint on port 80. This was just made by default with the mongo-azure library I mentioned above. I'm not sure if there is anything I should be doing with this.

          推荐答案

          如果实例都坐在后面一个负载平衡输入终点(如27017),然后您的每一个客户机连接到终点的时候,它会被连接到在replicaset集群潜在的不同节点(和你不得不在这种情况下您就到无法控制)。这或许可以解释为什么你有时试图写入非主,并得到一个错误,但是你所有的读取工作(因为你可能建立的MongoDB集群允许读取辅助节点上)。

          If the instances are all sitting behind a single load-balanced Input endpoint (e.g. 27017), then each time your client machine connects to the endpoint, it will be connected to potentially different nodes in the replicaset cluster (and you'd have no control over which instance you went to). This might explain why you sometimes attempt to write to the non-master and get an error, yet all your reads work (since you probably set up the MongoDB cluster to allow reads on secondary nodes).

          辅助角色还支持 InstanceInput 端点,它允许您在工人设置面向外部的端口范围(例如,27017-27019),映射到一个端口实例本身(如27017)。如果你这样做,你的客户端应用程序现在可以直接连接到所有的三个实例(27017,27018,27019)。许多驱动程序支持replicaset连接,所以它能够计算出哪个节点是主,指挥所有写入它。 我不知道,如果你使用的是Android上的驱动程序支持replicasets。的如果驱动程序不支持replicasets,那么你可能要考虑搭建一个API层,然后做所有通信数据库(一个很好的做法,按照一般情况下,无论如何,你可以看看Azure的移动服务来实现这样的快捷方式)。

          Worker roles also support InstanceInput endpoints, which allow you to set an externally-facing port range (say, 27017-27019), mapping to a single port on the worker instances themselves (e.g. 27017). If you do this, your client app can now connect to all three instances directly (27017, 27018, 27019). Many drivers support replicaset connections, so it would be able to figure out which node is the master, directing all writes to it. I don't know if the driver you're using on Android supports replicasets. If the driver doesn't support replicasets, then you'll probably want to consider putting up an API tier which then does all communication to the database (a good practice to follow in general, anyway, and you can look at Azure's Mobile Services for a quick way to implement this).

          所以...如果你replicaset群集的端点配置为输入,这可能说明你所看到的问题,这应该是解析切换端点类型 InstanceInput

          So... if your replicaset cluster's endpoint is configured as Input, this likely explains the issue you're seeing, which should be resolvable by switching the endpoint type to InstanceInput.

          这篇关于MongoDB的+天青+安卓com.mongodb.WriteConcernException错误:&QUOT;没有掌握&QUOT; code:&QUOT; 10058&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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