返回顶部
首页 > 资讯 > 数据库 >Replication
  • 169
分享到

Replication

Replication 2018-01-15 17:01:15 169人浏览 绘本
摘要

Replication On this page Redundancy and Data A

Replication

Replication

On this page

  • Redundancy and Data Availability
  • Replication in mongoDB
  • Asynchronous Replication
  • Automatic Failover
  • Read Operations
  • Additional Features

A replica set in MonGoDB is a group of mongod processes that maintain the same data set. Replica sets provide redundancy and high availability, and are the basis for all production deployments. This section introduces replication in MongoDB as well as the components and architecture of replica sets. The section also provides tutorials for common tasks related to replica sets.

Redundancy and Data Availability

Replication provides redundancy and increases data availability. With multiple copies of data on different database servers, replication provides a level of fault tolerance against the loss of a single database server.

In some cases, replication can provide increased read capacity as clients can send read operations to different servers. Maintaining copies of data in different data centers can increase data locality and availability for distributed applications. You can also maintain additional copies for dedicated purposes, such as disaster recovery, reporting, or backup.

Replication in MongoDB

A replica set is a group of mongod instances that maintain the same data set. A replica set contains several data bearing nodes and optionally one arbiter node. Of the data bearing nodes, one and only one member is deemed the primary node, while the other nodes are deemed secondary nodes.

The primary node receives all write operations. A replica set can have only one primary capable of confirming writes with { w: "majority" } write concern; although in some circumstances, another mongod instance may transiently believe itself to also be primary. [1] The primary records all changes to its data sets in its operation log, i.e. oplog. For more infORMation on primary node operation, see Replica Set Primary.

Diagram of default routing of reads and writes to the primary. click to enlarge

The secondaries replicate the primary’s oplog and apply the operations to their data sets such that the secondaries’ data sets reflect the primary’s data set. If the primary is unavailable, an eligible secondary will hold an election to elect itself the new primary. For more information on secondary members, see Replica Set Secondary Members.

Diagram of a 3 member replica set that consists of a primary and two secondaries. click to enlarge

In some circumstances (such as you have a primary and a secondary but cost constraints prohibit adding another secondary), you may choose to add a mongod instance to a replica set as an arbiter. An arbiter participates in elections but does not hold data (i.e. does not provide data redundancy). For more information on arbiters, see Replica Set Arbiter.

Diagram of a replica set that consists of a primary, a secondary, and an arbiter. click to enlarge

An arbiter will always be an arbiter whereas a primary may step down and become a secondary and a secondary may become the primary during an election.

Asynchronous Replication

Secondaries apply operations from the primary asynchronously. By applying operations after the primary, sets can continue to function despite the failure of one or more members. For more information on replication mechanics, see Replica Set Oplog and Replica Set Data Synchronization.

For MongoDB 3.6 deployments, starting in version 3.6.11, secondary members of a replica set now log oplog entries that take longer than the slow operation threshold to apply. These slow oplog messages are logged for the secondaries in the diagnostic log under the REPL component with the text applied op: entry> took ms. These slow oplog entries depend only on the slow operation threshold. They do not depend on the log levels (either at the system or component level), or the profiling level, or the slow operation sample rate. The profiler does not capture slow oplog entries.

Automatic Failover

When a primary does not communicate with the other members of the set for more than the configured electionTimeoutMillis period (10 seconds by default), an eligible secondary calls for an election to nominate itself as the new primary. The cluster attempts to complete the election of a new primary and resume normal operations.

Diagram of an election of a new primary. In a three member replica set with two secondaries, the primary becomes unreachable. The loss of a primary triggers an election where one of the secondaries becomes the new primary click to enlarge

The replica set cannot process write operations until the election completes successfully. The replica set can continue to serve read queries if such queries are configured to run on secondaries while the primary is offline.

The median time before a cluster elects a new primary should not typically exceed 12 seconds, assuming default replica configuration settings. This includes time required to mark the primary as unavailable and call and complete an election. You can tune this time period by modifying the settings.electionTimeoutMillis replication configuration option. Factors such as network latency may extend the time required for replica set elections to complete, which in turn affects the amount of time your cluster may operate without a primary. These factors are dependent on your particular cluster architecture.

Lowering the electionTimeoutMillis replication configuration option from the default 10000 (10 seconds) can result in faster detection of primary failure. However, the cluster may call elections more frequently due to factors such as temporary network latency even if the primary is otherwise healthy. This can result in increased rollbacks for w : 1 write operations.

Your application connection logic should include tolerance for automatic failovers and the subsequent elections.

New in version 3.6: MongoDB 3.6+ drivers can detect the loss of the primary and automatically retry certain write operations a single time, providing additional built-in handling of automatic failovers and elections.

See Replica Set Elections for complete documentation on replica set elections.

To learn more about MongoDB’s failover process, see:

  • Replica Set Elections
  • Retryable Writes
  • Rollbacks During Replica Set Failover

Read Operations

By default, clients read from the primary [1]; however, clients can specify a read preference to send read operations to secondaries. Asynchronous replication to secondaries means that reads from secondaries may return data that does not reflect the state of the data on the primary. For information on reading from replica sets, see Read Preference.

In MongoDB, clients can see the results of writes before the writes are durable:

  • Regardless of write concern, other clients using "local" or "available" readConcern can see the result of a write operation before the write operation is acknowledged to the issuing client.
  • Clients using "local" or "available" readConcern can read data which may be subsequently rolled back.

For more information on read isolations, consistency and recency for MongoDB, see Read Isolation, Consistency, and Recency.

Additional Features

Replica sets provide a number of options to support application needs. For example, you may deploy a replica set with members in multiple data centers, or control the outcome of elections by adjusting the members[n].priority of some members. Replica sets also support dedicated members for reporting, disaster recovery, or backup functions.

See Priority 0 Replica Set Members, Hidden Replica Set Members and Delayed Replica Set Members for more information.

[1] (1, 2) In some circumstances, two nodes in a replica set may transiently believe that they are the primary, but at most, one of them will be able to complete writes with { w: "majority" } write concern. The node that can complete { w: "majority" } writes is the current primary, and the other node is a former primary that has not yet recognized its demotion, typically due to a network partition. When this occurs, clients that connect to the former primary may observe stale data despite having requested read preference primary, and new writes to the former primary will eventually roll back.
←   Change Events Replica Set Members  →

© MongoDB, Inc 2008-present. MongoDB, Mongo, and the leaf logo are reGIStered trademarks of MongoDB, Inc.

 
您可能感兴趣的文档:

--结束END--

本文标题: Replication

本文链接: https://lsjlt.com/news/7739.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • Replication
    Replication On this page Redundancy and Data A...
    99+
    2018-01-15
    Replication
  • REPLICATION SLAVE 与 REPLICATION CLIENT 权限
    测试的版本为5.6.30 REPLICATION SLAVE 常用于建立复制时所需要用到的用户权限,也就是slave server必须被master server授权具有该权限的用户,才能通过该用户复制...
    99+
    2024-04-02
  • mysql replication
    mysql replicaton环境:主:192.168.48.150           从:192.168.48.152简单的说,就...
    99+
    2024-04-02
  • Redis的replication
    环境: master:192.168.11.31slave : 192.168.11.20:6379 与 6380模拟两台slave同时对一台master进行复制。mater 配置:daemonize ye...
    99+
    2024-04-02
  • replication crash safe
    什么是主从复制的replication crash safe?参数master_info_repository有两个值:FILE (对应的文件master.info),  or TABLE (对应...
    99+
    2024-04-02
  • 3.MySQL Replication(
    3.1 MySQL Replication 概述MySQL Replication俗称MySQL AB复制,主要是通过把主服务器上的二进制日志通过网络传到从服务器上,MYSQL会自己把二进制日志转换成相关的DDL,DML,DCL等语句!但这...
    99+
    2023-01-31
    MySQL Replication
  • MySQL 5.7.17 Group Replication
    基于组复制的强大功能在MySQL 5.7.17之后以插件的形式实现,本文讲述在单机多实例基础上搭建组复制测试环境环境说明:操作系统:    CentOS Linux ...
    99+
    2024-04-02
  • replication set复制集
    replication set复制集replicattion set 多台服务器维护相同的数据副本,提高服务器的可用性. Replication set 设置全过程0:创建目录 mkdir -p /dat...
    99+
    2024-04-02
  • 延时复制 delayed replication
    mysql5.6开始支持延时复制,默认master_delay为0秒,CHANGE MASTER TO MASTER_DELAY = N;表示延时N秒原理:延时复制的本质是sql_thread需要等待延时时...
    99+
    2024-04-02
  • 如何理解Mysql Replication
    如何理解Mysql Replication,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。Mysql Replication类似...
    99+
    2024-04-02
  • 实战MongoDB-Replication之Replica Set
    实战MongoDB Master-Slave   MongoDB支持不同服务之间的异步的数据复制,来实现failover(故障转移,故障切换,故障恢复) and redundancy(数据冗余)。...
    99+
    2024-04-02
  • DB2 SQL Replication 配置方法
    Replication Server 产品包括 SQL 复制和 Q 复制两种技术。相比于 SQL 复制,Q 复制的数据传输技术借助于 IBM 队列机制,从而提高了数据的传输效率和可靠性,可以达到每秒复制几千...
    99+
    2024-04-02
  • Semi_Sync Replication方式的复制
          基于传统的复制,可能存在从库复制延迟的问题,那么master宕机后,如果此时master不能恢复,只能用slave代替master,slave处于落后的状...
    99+
    2024-04-02
  • 如何分析MySQL Group Replication
    如何分析MySQL Group Replication,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。最近看了下MySQL Gr...
    99+
    2024-04-02
  • 怎么部署MySQL Group Replication
    这篇文章主要介绍“怎么部署MySQL Group Replication”,在日常操作中,相信很多人在怎么部署MySQL Group Replication问题上存在疑惑,小编查阅了各式资料,整理出简单好用...
    99+
    2024-04-02
  • 配置mysql replication出错记录
    以下内容应用于[mysqld]段内server-id= 1  此行必须,1可以为其他数字,一般推荐的是IP最后段位。log-bin=mysql-bin 必须有此,开启binlog二进制所需。bin...
    99+
    2024-04-02
  • 半同步复制(Semi-synchronous Replication)
    MySQL5.5之前,MySQL的复制是异步操作,主库和从库的数据之间存在一定的延迟。这样存在一定的隐患:当主库上写入一个事务并        交成功,而从库尚未得到...
    99+
    2024-04-02
  • 【MySQL】5.7版本 Semisync Replication 增强
    一 前言 ...
    99+
    2024-04-02
  • MYSQL Group Replication的搭建过程
    这篇文章主要介绍“MYSQL Group Replication的搭建过程”,在日常操作中,相信很多人在MYSQL Group Replication的搭建过程问题上存在疑惑,小编查阅了各式资料,整理出简单...
    99+
    2024-04-02
  • 如何理解MySQL Replication线程
    这篇文章将为大家详细讲解有关如何理解MySQL Replication线程,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。Replication 线程Mysq...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作