Introdução
Há algum tempo, recebi a tarefa de desenvolver um cluster de failover para PostgreSQL que opera em vários data centers, unidos por fibra dentro da mesma cidade, e pode resistir a uma falha (por exemplo, falta de energia) de um data center. Escolhi o Pacemaker como o software responsável pela tolerância a falhas, pois esta Ă© a solução oficial da RedHat para a criação de clusters de failover. A boa notĂcia Ă© que a RedHat fornece suporte para isso, e essa solução Ă© universal (modular). Com sua ajuda, será possĂvel fornecer tolerância a falhas nĂŁo sĂł para o PostgreSQL, mas tambĂ©m para outros serviços, seja usando mĂłdulos padrĂŁo, seja criando-os para necessidades especĂficas.
Uma questão razoável surgiu para esta decisão: quão resiliente será um cluster de failover? Para investigar isso, desenvolvi uma bancada de teste que simula várias falhas nos nós do cluster, aguarda uma recuperação, recupera o nó com falha e continua o teste em um loop. Inicialmente, esse projeto se chamava hapgsql, mas com o tempo fiquei entediado com o nome, que tem apenas uma vogal. Portanto, comecei a chamar bancos de dados tolerantes a falhas (e IPs flutuantes apontando para eles) krogan (um personagem de um jogo de computador, em que todos os órgãos importantes são duplicados) e nós, clusters e o próprio projeto - tuchanka (o planeta onde vivem os krogan).
open source- MIT. README ( , Pacemaker PostgreSQL), README () .
VirtualBox. 12 ( 36GiB), 4 ( ). PostgreSQL, -, witness c quorum device ( -), 50%/50%, . -: , , quorum device. PostgreSQL, -: , , witness c quorum device. -. , , .
ntpd , ntpd
(orphan mode). witness NTP-, , . witness , ( ). HTTP proxy witness, Yum-. , , , witness .
v0. CentOS 7 PostgreSQL 11 VirtualBox 6.1.
-, -. split-brain Pacemaker, STONITH (Shoot The Other Node In The Head) fencing. : , - , , «» , , IPMI UPS. , IPMI UPS . , ( ) -. stonith- (IPMI, UPS ..) .
. , , . «+1» . , , , .. split-brain. , , , watchdog, , IPMI.
( -), 50%/50% (-), . quorum device — , -. ( ), 50%/50%. , quorum device, witness ( repmgr, ).
, , , . , ( ?), IP (float IP). IP, Pacemaker ( ). () , , ( ).
Tuchanka1 ( )
, , slave- hot standby read only- ( ).
- . PostgreSQL ( PostgreSQL , ( ), Pacemaker). , ( float IP). -, . Ě’ ( ) (), ( shared_buffers ..), , ( ) -. ( read only-) , .
, .
witness
witness (quorum device) Tuchanka1, . witness , , . 2 3, . .
Tuchanka1
- Tuchanka1. witness -. , float IP.
Tuchanka2 ()
. , . ( read only), float IP: krogan2 — , krogan2s1 — . , .
, .
Tuchanka2
- witness . - , float IP: . , , ( connection ..) float IP. .
Tuchanka4 ( )
. , read-only ( ). Tuchanka4 — , , . . ( ) - , PostgreSQL.
, . , , , -, -, . float IP. , - sql proxy, , . sql proxy, , . , (connection pool), .. ( SQL proxy , ).
Tuchanka4
- (.. ) witness . - : , float IP ( read-write ); , float IP ( read only-).
, : float IP , . , sql proxy float IP; sql proxy , float IP URL . libpq IP, . , , , JDBC, sql proxy. , float IP , , .
: - . , - , , , ( ).
Tuchanka3 (3 -)
, -, . quorum device . - , — . , ANY (slave1, slave2), , , . float IP . Tuchanka4 float IP . read-only SQL- sql proxy ( ), float IP, — .
Tuchanka3
- . float IP , — float IP ( , float IP). . ( ) - ( ).
. , README. .
. test/failure
. , . , :
test/failure 2 3
. , . , tmux. Tmux tmux , - default tmux, tmux. . setup
.
, ( ) . Tuchanka2. :
- . :
- failure — ( ), .
- reaction — , . , , , . , , ( (Tuchanka3 Tuchanka4)), , , .
- deviation — () reaction « ».
- count — .
- , . (), Ě’ . (> 5 ) - .
- heart () — . float IP . .
- beat () — « », heart , float IP. . Tuchanka1 float IP ( , ), (), beat, heart .
-
pcs mon
. , . - . — . CPU Load ( ), , System Load ( Load Average, 5, 10 15 ), .
- , . — — .
. , , . , . ( ) - (> 5 , ) , - .
:
- , .
- Ready? — ( ).
- (reaction).
- Fix — «». .
, :
- ForkBomb: "Out of memory" -.
- OutOfSpace: . , , , , , PostgreSQL .
- Postgres-KILL: PostgreSQL
killall -KILL postgres
. - Postgres-STOP: PostgreSQL
killall -STOP postgres
. - PowerOff: «»
VBoxManage controlvm "" poweroff
. - Reset:
VBoxManage controlvm "" reset
. - SBD-STOP: SBD
killall -STOP sbd
. - ShutDown: SSH
systemctl poweroff
, . - UnLink: ,
VBoxManage controlvm "" setlinkstate1 off
.
tmux "kill-window" Ctrl-b &, "detach-client" Ctrl-b d: , tmux , .
watchdog sbd , . , , , Corosync Pacemaker, sbd. Corosync PR#83 ( GitHub sbd), master. ( PR#83), Pacemaker - , , RedHat 8 . «» , , ,
killall -STOP corosync
, .
Pacemaker CentOS 7 sync_timeout quorum device, , . sync_timeout quorum device (
setup/setup1
). Pacemaker, ( ), .
,
LC_MESSAGES
( ) , ,ru_RU.UTF-8
, postgres , locale UTF-8, , ( pacemaker+pgsqlms(paf) postgres), UTF-8 . PostgreSQL , . ,LC_MESSAGES=en_US.UTF-8
() .
wal_receiver_timeout ( 60s), PostgreSQL-STOP tuchanka3 tuchanka4 . , , . wal_receiver_timeout=0 PostgreSQL.
PostgreSQL ForkBomb ( ). ForkBomb . tuchanka3 tuchanka4, - , , . , - ( ). , . , , .
Deviant Art c :