PoC: Patroni on pure RAFT (#375)

* new node can join the cluster dynamically and become a part of consensus
 * it is also possible to join only Patroni cluster (without adding the node to the raft), just comment or remove `raft.self_addr` for that
 * when the node joins the cluster it is using values from `raft.partner_addrs` only for initial discovery.
* It is possible to run Patroni and Postgres on two nodes plus one node with `patroni_raft_controller` (without Patroni and Postgres). In such setup one can temporarily lose one node without affecting the primary.
This commit is contained in:
Alexander Kukushkin
2020-07-29 15:34:44 +02:00
committed by GitHub
parent c42d507b82
commit bfbc4860d5
19 changed files with 884 additions and 89 deletions
+46
View File
@@ -0,0 +1,46 @@
import logging
import os
import unittest
from mock import Mock, patch
from pysyncobj import SyncObj
from patroni.config import Config
from patroni.raft_controller import RaftController, main as _main
from . import SleepException
class TestPatroniRaftController(unittest.TestCase):
SELF_ADDR = '127.0.0.1:5360'
def remove_files(self):
for f in ('journal', 'dump'):
f = self.SELF_ADDR + '.' + f
if os.path.exists(f):
os.unlink(f)
@patch('pysyncobj.tcp_server.TcpServer.bind', Mock())
def setUp(self):
self._handlers = logging.getLogger().handlers[:]
self.remove_files()
os.environ['PATRONI_RAFT_SELF_ADDR'] = self.SELF_ADDR
config = Config('postgres0.yml', validator=None)
self.rc = RaftController(config)
def tearDown(self):
logging.getLogger().handlers[:] = self._handlers
self.remove_files()
def test_reload_config(self):
self.rc.reload_config()
@patch('logging.Logger.error', Mock(side_effect=SleepException))
@patch.object(SyncObj, 'doTick', Mock(side_effect=Exception))
def test_run(self):
self.assertRaises(SleepException, self.rc.run)
self.rc.shutdown()
@patch('sys.argv', ['patroni'])
def test_patroni_raft_controller_main(self):
self.assertRaises(SystemExit, _main)