c#-主要故障,现在是辅助故障主要-如何写入新的主要故障?

如果我在一个MongoDB副本集上设置了3个节点(Primary,Secondary,Arbiter),Primary节点出现故障,现在Secondary假设是Primary,那么如何动态处理客户端中的更改,以便它们现在可以写入Primary?

我在开发环境中经历了这一点,并开始思考处理此问题的最佳方法.这不是分片群集,只是一个独立的副本集.

您是否在连接中检查了诸如“ IsPrimary”之类的内容,以便您不更改书写位置?

任何建议,将不胜感激.

谢谢,

小号

解决方法:

设置连接后,驱动程序应足够聪明,以理清应将数据发送到哪个节点.

For the C# driver

To connect to a replica set specify the seed list by providing
multiple hostnames (and port numbers if required) separated by commas.
For example:

mongodb://server1,server2:27017,server2:27018

For the Python driver

A connection to a replica set can be made using the normal
Connection() constructor, specifying one or more members of the set.
For example, any of the following will create a connection to the set
we just created:

Connection("morton.local", replicaset='foo')
Connection([u'morton.local:27019', 'morton.local:27017', u'morton.local:27018'])
Connection("morton.local:27018", replicaset='foo')
Connection([u'morton.local:27019', u'morton.local:27017', 'morton.local:27018'])
Connection("morton.local", 27019, replicaset='foo')
Connection(['morton.local:27019', u'morton.local:27017', u'morton.local:27018'])
Connection(["morton.local:27018", "morton.local:27019"])
Connection(['morton.local:27019', u'morton.local:27017', 'morton.local:27018'])
Connection("mongodb://morton.local:27017,morton.local:27018,morton.local:27019")
Connection(['morton.local:27019', 'morton.local:27017', 'morton.local:27018'])

The nodes passed to Connection() are called the seeds. If only one
host is specified the replicaset parameter must be used to indicate
this isn’t a connection to a single node. As long as at least one of
the seeds is online, the driver will be able to “discover” all of the
nodes in the set and make a connection to the current primary.

上一篇:pymongo排序


下一篇:python – 以可测试的方式连接到mongodb