如何在 mongodb 中的分片副本集上执行只读查询 [英] how to execute read only query on sharded replica set in mongodb

查看:75
本文介绍了如何在 mongodb 中的分片副本集上执行只读查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下配置 -

  1. 2 个 Shard 服务器,每个服务器有 1 个副本集(比如 rs0 和 rs1).
  2. 3 个配置服务器和 1 个查询路由器(mongos)

上述分片配置工作正常.但是,我想从分片副本集(从 rs0 和 rs1 的辅助节点)执行只读查询.因为,mongodb 数据同时存在于副本集 rs0 和 rs1 中.那么,如何配置它,从 rs0 和 rs1 的辅助节点获取数据?.

The above sharding configuration is working fine. But, i want to execute read-only query from sharded replica set (from secondary of rs0 and rs1). Since, the mongodb data are exists in both replica set rs0 and rs1. So, how to configure this, to fetch the data from both secondary of rs0 and rs1?.

推荐答案

您的分片设置不应影响读取首选项的使用,因此您可以继续使用 Secondary 或 SecondaryPreferred 来访问每个分片中副本集的辅助节点:

Your sharding setup should not impact the use of read preferences, so you can continue to use Secondary or SecondaryPreferred to access the secondaries of your replica sets within each shard:

分片集群中的读取偏好

2.2 版变更:2.2 版之前,mongos 不支持读取偏好模式语义.

Changed in version 2.2: Before version 2.2, mongos did not support the read preference mode semantics.

在大多数分片集群中,每个分片由一个副本集组成.作为这样,阅读首选项也适用.关于阅读偏好,分片集群中的读取操作与未分片的副本集.

In most sharded clusters, each shard consists of a replica set. As such, read preferences are also applicable. With regard to read preference, read operations in a sharded cluster are identical to unsharded replica sets.

与简单的副本集不同,在分片集群中,所有与分片从客户端传递到 mongos 实例实际上连接到集合成员.mongos 然后负责阅读偏好的应用,这对透明应用程序.

Unlike simple replica sets, in sharded clusters, all interactions with the shards pass from the clients to the mongos instances that are actually connected to the set members. mongos is then responsible for the application of read preferences, which is transparent to applications.

完全支持读取无需更改配置分片环境中的偏好模式,只要 mongos 处于最低版本 2.2.所有 mongos 都维护自己的连接池副本集成员.结果:

There are no configuration changes required for full support of read preference modes in sharded environments, as long as the mongos is at least version 2.2. All mongos maintain their own connection pool to the replica set members. As a result:

  • 没有指定首选项的请求具有主要的默认值,除非 mongos 重用具有不同的现有连接模式设置.为防止混淆,请始终明确设置您的阅读偏好模式.

  • A request without a specified preference has primary, the default, unless, the mongos reuses an existing connection that has a different mode set. To prevent confusion, always explicitly set your read preference mode.

所有最近的和延迟的计算都反映了 mongos 和 mongod 实例之间的连接,而不是客户端和 mongod 之间的连接
实例.这会产生所需的结果,因为所有结果都必须在返回客户端之前通过 mongos.

All nearest and latency calculations reflect the connection between the mongos and the mongod instances, not the client and the mongod
instances. This produces the desired result, because all results must pass through the mongos before returning to the client.

http://docs.mongodb.org/manual/core/read-preference-mechanics/

这篇关于如何在 mongodb 中的分片副本集上执行只读查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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