Einführung
Vor einiger Zeit wurde ich mit der Entwicklung eines Failover-Clusters für PostgreSQL beauftragt , das in mehreren Rechenzentren betrieben wird, die durch Glasfaser in derselben Stadt verbunden sind und einem Ausfall (z. B. einem Stromausfall) eines Rechenzentrums standhalten können. Ich habe Pacemaker als Software für die Fehlertoleranz ausgewählt, da dies die offizielle Lösung von RedHat zum Erstellen von Failover-Clustern ist. Die gute Nachricht ist, dass RedHat Unterstützung dafür bietet und dass diese Lösung universell (modular) ist. Mit seiner Hilfe wird es möglich sein, Fehlertoleranz nicht nur für PostgreSQL, sondern auch für andere Dienste bereitzustellen, indem entweder Standardmodule verwendet oder für bestimmte Anforderungen erstellt werden.
Zu dieser Entscheidung stellte sich eine vernünftige Frage: Wie fehlertolerant wird ein Failover-Cluster sein? Um dies zu untersuchen, habe ich einen Prüfstand entwickelt, der verschiedene Fehler auf den Clusterknoten simuliert, auf die Wiederherstellung des Zustands wartet, den ausgefallenen Knoten neu erstellt und das Testen in einer Schleife fortsetzt. Ursprünglich hieß dieses Projekt hapgsql, aber im Laufe der Zeit langweilte mich der Name, der nur einen Vokal hat. Daher begann ich, fehlertolerante Datenbanken (und Float-IPs, die auf sie verweisen) Krogan (eine Figur aus einem Computerspiel, in dem alle wichtigen Organe dupliziert sind) sowie Knoten, Cluster und das Projekt selbst - Tuchanka (der Planet, auf dem Krogan lebt) zu nennen.
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 :
