Database/RDS

InnoDB - Replication

류큐큐 2024. 8. 13. 12:26

MYSQL 에 대한 Replication의 일반적인 사용 예시

1. 데이터 분산 

2. 읽기 트래픽 확장

3. 분석 및 보고

 - 보고/분석(온라인 분석 처리 , OLAP) 쿼리를 위해 전용 레플리카를 사용

4. 고가용성 및 장애 조치

 - 복제는 MYSQL이 애플리케이션에서 단일 장애 지점이 되는 것을 방지할 수 있다.

5. MYSQL 버전 업그레이드 테스트 

 

-참고 

https://dev.mysql.com/doc/refman/8.4/en/replication-solutions.html

 

MySQL :: MySQL 8.4 Reference Manual :: 19.4 Replication Solutions

MySQL 8.4 Reference Manual  /  Replication  /  Replication Solutions 19.4 Replication Solutions Replication can be used in many different environments for a range of purposes. This section provides general notes and advice on using replication for spe

dev.mysql.com

 

 

 

복제 작동 방식

 

- 소스는 데이터 변경 사항을 바이너리 로그에 기록

- 레플리카는 소스의 바이너리 로그 이벤트를 자체 로컬 릴레이 로그에 기록

- 레플리카는 릴레이 로그의 이벤트를 재생하여 자체 데이터에 변경 사항을 적용

 

Binary Log Dump Thread (바이너리 로그 덤프 스레드)

소스 서버에서 동작. 이 스레드는 소스 서버의 바이너리 로그에서 데이터를 읽어 레플리카 서버로 전송.

mysql> SHOW PROCESSLIST\G
*************************** 1. row ***************************
     Id: 2
   User: root
   Host: localhost:32931
     db: NULL
Command: Binlog Dump
   Time: 94
  State: Has sent all binlog to slave; waiting for binlog to
         be updated
   Info: NULL
   
   
   이 상태는 소스 서버가 레플리카에 모든 로그를 전송한 후, 새로운 로그가 생성되기를 기다리고 있음을 의미.

 

 

Replication I/O (Receiver) Thread (복제 I/O 스레드)

레플리카 서버에서 동작.

소스 서버에서 전송된 바이너리 로그를 받아서 자신의 릴레이 로그에 기록.

 

이후에 릴레이 로그에 기록된 이벤트를 실제로 데이터베이스에 적용하는 스레드는 레플리카 서버에서 실행되는 Replication SQL (Applier) Thread. 이 스레드는 릴레이 로그에 기록된 이벤트를 재생하여 레플리카의 데이터베이스에 변경 사항을 적용.

mysql> SHOW PROCESSLIST\G

     Id: 10
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 11
  State: Waiting for master to send event
   Info: NULL

 

 

 

Replication SQL (Applier) Thread (복제 SQL 스레드)

레플리카 서버에서 동작.

릴레이 로그에 기록된 이벤트를 읽어들여 레플리카 서버의 데이터베이스에 적용.

 

mysql> SHOW PROCESSLIST\G

     Id: 11
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 11
  State: Has read all relay log; waiting for the slave I/O
         thread to update it
   Info: NULL

 

-참고

https://dev.mysql.com/doc/refman/8.4/en/replication-threads.html

 

MySQL :: MySQL 8.4 Reference Manual :: 19.2.3 Replication Threads

19.2.3 Replication Threads MySQL replication capabilities are implemented using the following types of threads: Binary log dump thread.  The source creates a thread to send the binary log contents to a replica when the replica connects. This thread can b

dev.mysql.com