Database Manual / Replication / Replica Set Members / Secondary

Hidden Replica Set Members隐藏副本集成员

A hidden member maintains a copy of the primary's data set but is invisible to client applications. Hidden members are good for workloads with different usage patterns from the other members in the replica set. 隐藏成员维护primary's数据集的副本,但对客户端应用程序不可见。隐藏成员适用于与副本集中的其他成员具有不同使用模式的工作负载。Hidden members must always be priority 0 members and so cannot become primary. 隐藏成员必须始终是优先级为0的成员,因此不能成为主要成员。The db.hello() method does not display hidden members. Hidden members, however, may vote in elections.db.hello()方法不显示隐藏成员。然而,隐藏的成员可以在选举中投票。

Behavior行为

Read Operations读取操作

You can only read from a hidden member if you directly connect to the node. If you connect to a cluster without directly connecting to the hidden node, you cannot run queries on the hidden node. As a result, these members receive no traffic other than basic replication. Use hidden members for dedicated tasks such as reporting and backups.如果直接连接到节点,则只能从隐藏成员读取。如果连接到集群而不直接连接到隐藏节点,则无法在隐藏节点上运行查询。因此,除了基本复制之外,这些成员不会收到任何流量。将隐藏成员用于报告和备份等专用任务。

Important

If your replica set contains delayed members ensure that the delayed members are hidden and non-voting.如果副本集包含延迟成员,请确保这些延迟成员是隐藏的,并且没有投票权。

Hiding delayed replica set members prevents applications from seeing and querying delayed data without a direct connection to that member. Making delayed replica set members non-voting means they will not count towards acknowledging write operations with write concern "majority".隐藏延迟的副本集成员可以防止应用程序在没有直接连接到该成员的情况下查看和查询延迟的数据。使延迟的副本集成员无投票权意味着他们将不计入以"majority"写入关注确认写入操作。

If you do not hide delayed members and one or more nodes become unavailable, the replica set has to wait for the delayed member and the commit point lags. A lagged commit point can lead to performance issues.如果不隐藏延迟成员,并且一个或多个节点不可用,则副本集必须等待延迟成员,提交点会延迟。延迟的提交点可能会导致性能问题。

For example, consider a Primary-Secondary-Delayed replica set configuration where the delayed secondary is voting with a 10 minute delay.例如,考虑一个主要次要延迟副本集配置,其中延迟的次要副本以10分钟的延迟进行投票。

With one non-delayed secondary unavailable, the degraded configuration of Primary-Delayed must wait at least 10 minutes to acknowledge a write operation with "majority". The majority commit point will take longer to advance, leading to cache pressure similar performance issues with a Primary with a Secondary and an Arbiter (PSA) replica set.

For more information on the majority commit point, see Causal Consistency and Read and Write Concerns. For additional details on resolving performance issues see the replica set maintenance tutorial.

In sharded clusters, you cannot access hidden nodes through mongos. Directly connecting to these nodes to read data can result in data inconsistency or loss. Instead, to achieve workload isolation, use tag-based read preferences.在分片集群中,您无法通过mongos访问隐藏节点。直接连接到这些节点读取数据可能会导致数据不一致或丢失。相反,为了实现工作负载隔离,请使用 基于标签的读取首选项

Note

Starting in MongoDB 8.0, you can only run certain commands on shards. If you attempt to connect directly to a shard and run an unsupported command, MongoDB returns an error:从MongoDB 8.0开始,您只能在分片上运行某些命令。如果您尝试直接连接到分片并运行不受支持的命令,MongoDB将返回错误:

"You are connecting to a sharded cluster improperly by connecting directly
to a shard. Please connect to the cluster via a router (mongos)."

Voting投票

Hidden members may vote in replica set elections. If you stop a voting hidden member, ensure that the set has an active majority or the primary will step down.隐藏成员可以在复制集选举中投票。如果你阻止了一个投票隐藏成员,请确保该组成员拥有有效多数,否则初选将下台。

For the purposes of backups,为了备份的目的,

  • db.fsyncLock() ensures that the data files are safe to copy using low-level backup utilities such as cp, scp, or tar. A mongod started using the copied files contains user-written data that is indistinguishable from the user-written data on the locked mongod.

    The data files of a locked mongod may change due to operations such as journaling syncs or WiredTiger snapshots. While this has no effect on the logical data (e.g. data accessed by clients), some backup utilities may detect these changes and emit warnings or fail with errors. For more information on MongoDB- recommended backup utilities and procedures, see Backup Methods for a Self-Managed Deployment.

Write Concern写关注

Hidden replica set members can acknowledge write operations issued with w: <number>. For write operations issued with w : "majority", however, hidden members must also be voting members (i.e. members[n].votes greater than 0) to acknowledge the "majority" write operation. Non-voting replica set members (i.e. members[n].votes is 0) cannot contribute to acknowledging write operations with majority write concern.

Further Reading进一步阅读

For more information about backing up MongoDB databases, see Backup Methods for a Self-Managed Deployment. To configure a hidden member, see Configure a Hidden Self-Managed Replica Set Member.有关备份MongoDB数据库的更多信息,请参阅自我管理部署的备份方法。要配置隐藏成员,请参阅配置隐藏的自我管理副本集成员