Ctrip open source Redis multi-data center replication management system

Ctrip open source Redis multi-data center replication management system

2022-10-12 0 808
Resource Number 45197 Last Updated 2025-02-24
¥ 0USD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

This issue recommends a Redis multi-data center replication management system developed by Ctrip’s framework department — X-Pipe.

Ctrip open source Redis multi-data center replication management system插图

Redis has been widely used inside Ctrip. According to client data statistics, the read and write requests of all Redis in Ctrip are 2000W per second, of which the write requests are about 100W. Many businesses even use Redis as a persistent memory database. In this way, Redis multi-data centers are in great demand. One is to improve availability and solve the Disaster Recovery (DR) problem of data centers; the other is to improve access performance. Each data center can read the data of the current data center without cross-room reading. XPipe was born.

For ease of description, DC is used to represent the Data Center.

Overall structure

Ctrip open source Redis multi-data center replication management system插图1

  • Console The console is used to manage the metadata data of multiple equipment rooms and provides a user interface for configuration and DR Switching.
  • Keeper caches Redis operation logs and compresses and encrypts cross-room transmission.
  • Meta Server manages all keeper status in a single room and corrects abnormal status.

Redis data replication problem

The first thing to solve in a multi-data center is the data replication problem, that is, how data is transferred from one DC to another DC. We decided to adopt the pseudo-slave scheme, that is, to implement the Redis protocol, pretend to be a Redis slave, and let the Redis master push data to the pseudo-slave. This pseudo-slave, which we call keeper, is shown below:

Ctrip open source Redis multi-data center replication management system插图2

Advantages of using keeper :

  • Reduce master full synchronization

If the slave in the remote equipment room is directly connected to the master, multiple slaves will cause the master to fully synchronize multiple times, and the keeper can cache rdb and replication log. The slave in the remote equipment room directly obtains data from the keeper to enhance the stability of the master.

  • Reduce multi-data center network traffic

Between two data centers, data needs to be transmitted only once through keeper, and the transmission protocol between keeper can be customized to facilitate compression (currently not supported).

  • Reduce full synchronization when network exception

keeper caches Redis log data to disk, so that a large amount of log data can be cached (Redis caches data to the memory ring buffer, the capacity is limited). If the network between data centers is abnormal for a long time, log data can still be transmitted.

  • Security improvement

data transmission between multiple computer rooms often needs to be carried out through the public network, so the security of data becomes extremely important. Data transmission between keeper can also be encrypted (not yet realized) to improve security.

Equipment Room Switching process

  • Check if you can switch DR

Similar to the 2PC protocol, prepare first to ensure that the process can proceed smoothly.

  • The original master cannot write

This step ensures that there is only one master during the migration process to resolve possible data loss during the migration process.

  • Upgrade new master
  • Synchronize other equipment rooms to the new main equipment room

Both rollback and retry functions are provided. The rollback function can be rolled back to the original state. The retry function can repair abnormal conditions and continue the switchover when the DBA manually intervenes.

High availability

High availability of XPipe system

If keeper fails, data transmission between DCS may be interrupted. To solve this problem, keeper has two active and standby nodes, and the standby node copies data from the active node in real time. When the active node fails, the standby node will be promoted to the active node to replace the active node.

The promotion operation needs to be carried out through a third-party node, which we call MetaServer, which is mainly responsible for the transformation of keeper status and the storage of meta information in the equipment room. At the same time, MetaServer should also be highly available: each MetaServer is responsible for a specific Redis cluster. When a MetaServer node fails, its Redis cluster will be replaced by another node. If a new node is added to the entire cluster, load balancing is automatically performed and part of the cluster is transferred to the new node.

High availability of Redis itself

Redis may also fail, and Redis itself provides a Sentinel mechanism to ensure high availability of the cluster. However, before Redis4.0, after a new master is promoted, other nodes will perform full synchronization after connecting to the master. During full synchronization, the slave will be unavailable. The master will export the rdb, reducing the availability of the master. At the same time, a large amount of data (RDB) is transmitted in the cluster, which will lead to the instability of the whole system.

Up to the time of writing, 4.0 still has not been released, and the Redis version used by Ctrip internally is 2.8.19, if it is upgraded to 4.0, the version span is too large, based on this, We optimized the version of Redis3.0.7 to implement the psync2.0 protocol and achieve incremental synchronization.

Ctrip open source Redis multi-data center replication management system插图3

Test data

Test scheme

The test method is shown in the figure below. Data is sent from the client to the master and the slave notifies the client through keyspace notification. The test delay is t1+t2+t3.

Ctrip open source Redis multi-data center replication management system插图4

Test data

First, we test the delay of Redis master copying directly to slave, which is 0.2ms. Then add a layer of keeper between master and slave, and the overall delay increases by 0.1ms to 0.3ms.

The test was carried out in the production environment of Ctrip, and the ping RTT between the two machine rooms in the production environment was about 0.61ms. After the two-layer keeper across the data center, the average delay obtained by the test was about 0.8ms, and the delay of 99.9 lines was 2ms.

docker Quick start

1 Start preparation

    • Need to start docker process in advance, and Docker-compose

is supported

  • Create a path and start from it (recommended)

2 Start docker

  • Method 1: Start the image on dockerhub
/bin/bash -c "$(curl  -sSL  https://raw.githubusercontent.com/ctripcorp/x-pipe/master/redis/dockerPackage/start-xpipe-container.sh)"</ code>

Container distribution after startup

 Run the command: docker ps -a

CONTAINER ID   IMAGE                              COMMAND                  CREATED      STATUS      PORTS                                                                                                                          NAMES
1e77491414a9   ctripcorpxpipe/xpipe-console:1.0   "docker-entrypoint.sh"   3 days ago   Up 3 days   0.0.0.0:8079->8080/tcp, :::8079->8080/tcp                                                                                       consolejq
6694f9eff0ad   ctripcorpxpipe/xpipe-console:1.0   "docker-entrypoint.sh"   3 days ago   Up 3 days   0.0.0.0:8081->8080/tcp, :::8081->8080/tcp                                                                                       consoleoy

aa0d109c7aae   ctripcorpxpipe/xpipe-meta:1.0      "docker-entrypoint.sh"   3 days ago   Up 3 days   0.0.0.0:9747->8080/tcp, :::9747->8080/tcp                                                                                       metajq
0c6cb6dfe51f   ctripcorpxpipe/xpipe-meta:1.0      "docker-entrypoint.sh"   3 days ago   Up 3 days   0.0.0.0:9748->8080/tcp, :::9748->8080/tcp                                                                                       metaoy

0e0f78ae096d   ctripcorpxpipe/xpipe-keeper:1.0    "docker-entrypoint.sh"   3 days ago   Up 3 days   0.0.0.0:7080->8080/tcp, :::7080->8080/tcp                                                                                       keeperjq1
16c5fdd14a5e   ctripcorpxpipe/xpipe-keeper:1.0    "docker-entrypoint.sh"   3 days ago   Up 3 days   0.0.0.0:7081->8080/tcp, :::7081->8080/tcp                                                                                       keeperjq2
1915292f3a7f   ctripcorpxpipe/xpipe-keeper:1.0    "docker-entrypoint.sh"   3 days ago   Up 3 days   0.0.0.0:7180->8080/tcp, :::7180->8080/tcp                                                                                       keeperoy1
0c885945d8f3   ctripcorpxpipe/xpipe-keeper:1.0    "docker-entrypoint.sh"   3 days ago   Up 3 days   0.0.0.0:7181->8080/tcp, :::7181->8080/tcp                                                                                       keeperoy2

15062ab45feb   ctripcorpxpipe/xpipe-proxy:1.0     "docker-entrypoint.sh"   3 days ago   Up 3 days   0.0.0.0:19079->80/tcp, :::19079->80/tcp, 0.0.0.0:19442->443/tcp, :::19442->443/tcp, 0.0.0.0:8092->8080/tcp, :::8092->8080/tcp   proxyjq
ed38daf8e71e   ctripcorpxpipe/xpipe-proxy:1.0     "docker-entrypoint.sh"   3 days ago   Up 3 days   0.0.0.0:19081->80/tcp, :::19081->80/tcp, 0.0.0.0:19444->443/tcp, :::19444->443/tcp, 0.0.0.0:8091->8080/tcp, :::8091->8080/tcp   proxyoy

d0e811ea5d3d   zookeeper                          "/docker-entrypoint.…"   3 days ago   Up 3 days   2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp, 8080/tcp                                                         zoo1
41381b5bd3a9   zookeeper                          "/docker-entrypoint.…"   3 days ago   Up 3 days   2888/tcp, 3888/tcp, 8080/tcp, 0.0.0.0:2182->2181/tcp, :::2182->2181/tcp                                                         zoo2

d5f85ee0360e   ctripcorpxpipe/xpipe-mysql:2.0     "docker-entrypoint.s…"   3 days ago   Up 3 days   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp                                                                            mysql

ba2b64f10700   redis:4.0                          "docker-entrypoint.s…"   3 days ago   Up 3 days   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp                                                                                       redis-6379
4687df7ac486   redis:4.0                          "docker-entrypoint.s…"   3 days ago   Up 3 days   0.0.0.0:6479->6379/tcp, :::6479->6379/tcp                                                                                       redis-6479
58cfdf41284a   redis:4.0                          "docker-entrypoint.s…"   3 days ago   Up 3 days   0.0.0.0:6579->6379/tcp, :::6579->6379/tcp                                                                                       redis-6579
d180471bb010   redis:4.0                          "docker-entrypoint.s…"   3 days ago   Up 3 days   0.0.0.0:6679->6379/tcp, :::6679->6379/tcp                                                                                       redis-6679

4539be899dd3   redis:4.0                          "docker-entrypoint.s…"   3 days ago   Up 3 days   0.0.0.0:7379->6379/tcp, :::7379->6379/tcp                                                                                       redis-7379
dcf1b8079c1e   redis:4.0                          "docker-entrypoint.s…"   3 days ago   Up 3 days   0.0.0.0:7479->6379/tcp, :::7479->6379/tcp                                                                                       redis-7479	
180a2255d038   redis:4.0                          "docker-entrypoint.s…"   3 days ago   Up 3 days   0.0.0.0:7579->6379/tcp, :::7579->6379/tcp                                                                                       redis-7579
a877a83287b4   redis:4.0                          "docker-entrypoint.s…"   3 days ago   Up 3 days   0.0.0.0:7679->6379/tcp, :::7679->6379/tcp                                                                                       redis-7679
  • Method 2: Compile the local image according to the latest code and restart

3 Verification

  • data replication

Test whether data in the master can be synchronized to the standby equipment room redis:

1. If reids are not installed locally, enter a redis container at random

docker exec -ti redis-6379  bash

2. Connect to master redis, add data, and exit

`redis-cli -h 172.19.0.10

set test1 12345`

3. Connect to the slave redis and exit after obtaining data

`redis-cli -h 172.19.0.13

get test1`

4, example

song@ubuntu:~/yusong/code/test$ docker exec  -ti redis-6379 bash
root@c568933bae57:/data# redis-cli -h 172.19.0.10
172.19.0.10:6379>  set test1 12345
OK
172.19.0.10:6379>  exit
root@c568933bae57:/data# redis-cli-h 172.19.0.13
172.19.0.13:6379>  get test1
"12345"
172.19.0.13:6379>  exit
  • Delay monitoring

Launch your browser and go to localhost:8079/#
/cluster_dc_shards/cluster1 Check whether the status of each redis is green

Ctrip open source Redis multi-data center replication management system插图5

  • Migration function

1. Locate the cluster on the cluster_list page and click Migrate

.

Ctrip open source Redis multi-data center replication management system插图6

2. Select the cluster to be migrated and the target equipment room

Ctrip open source Redis multi-data center replication management system插图7 Ctrip open source Redis multi-data center replication management system插图8

3. Perform the migration

Ctrip open source Redis multi-data center replication management system插图9

4. Check whether the migration is successful

Ctrip open source Redis multi-data center replication management system插图10

4 Stop

docker-compose down

—END—

Open Source protocol: Apache 2.0

资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free source code Ctrip open source Redis multi-data center replication management system https://ictcoder.com/kyym/ctrip-open-source-redis-multi-data-center-replication-management-system.html

Share free open-source source code

Q&A
  • 1, automatic: after taking the photo, click the (download) link to download; 2. Manual: After taking the photo, contact the seller to issue it or contact the official to find the developer to ship.
View details
  • 1, the default transaction cycle of the source code: manual delivery of goods for 1-3 days, and the user payment amount will enter the platform guarantee until the completion of the transaction or 3-7 days can be issued, in case of disputes indefinitely extend the collection amount until the dispute is resolved or refunded!
View details
  • 1. Heptalon will permanently archive the process of trading between the two parties and the snapshots of the traded goods to ensure that the transaction is true, effective and safe! 2, Seven PAWS can not guarantee such as "permanent package update", "permanent technical support" and other similar transactions after the merchant commitment, please identify the buyer; 3, in the source code at the same time there is a website demonstration and picture demonstration, and the site is inconsistent with the diagram, the default according to the diagram as the dispute evaluation basis (except for special statements or agreement); 4, in the absence of "no legitimate basis for refund", the commodity written "once sold, no support for refund" and other similar statements, shall be deemed invalid; 5, before the shooting, the transaction content agreed by the two parties on QQ can also be the basis for dispute judgment (agreement and description of the conflict, the agreement shall prevail); 6, because the chat record can be used as the basis for dispute judgment, so when the two sides contact, only communicate with the other party on the QQ and mobile phone number left on the systemhere, in case the other party does not recognize self-commitment. 7, although the probability of disputes is very small, but be sure to retain such important information as chat records, mobile phone messages, etc., in case of disputes, it is convenient for seven PAWS to intervene in rapid processing.
View details
  • 1. As a third-party intermediary platform, Qichou protects the security of the transaction and the rights and interests of both buyers and sellers according to the transaction contract (commodity description, content agreed before the transaction); 2, non-platform online trading projects, any consequences have nothing to do with mutual site; No matter the seller for any reason to require offline transactions, please contact the management report.
View details

Related Article

make a comment
No comments available at the moment
Official customer service team

To solve your worries - 24 hours online professional service