Commit Graph
100 Commits
Author SHA1 Message Date
Alexander Kukushkin ab0ef91f24 Improve quality of code by resolving issues found by quantifiedcode and codacy 2016-02-12 14:52:23 +01:00
Alexander Kukushkin 36aef07738 Merge branch 'master' of github.com:zalando/patroni into codequality 2016-02-12 12:33:02 +01:00
Alexander Kukushkin df9b8fed2e Improve quality of code by resolving issues found by quantifiedcode and codacy 2016-02-12 12:23:49 +01:00
Alexander Kukushkin 7b524bc557 Create new session and set the process group ID for the postmaster
Otherwice it was receiving signal when you pressed Ctrl+C in the
terminal where patroni is running.
2016-02-10 14:51:20 +01:00
Alexander Kukushkin b4af126bc3 Apply superuser name and password when doing checkpoint 2016-02-10 13:50:05 +01:00
Alexander Kukushkin ad17b2070a Create superuser with the name specified in config file
And later use this name to connect to the cluster
2016-02-10 12:37:34 +01:00
Alexander Kukushkin b77908ce58 Execute tests against python 3.5 2015-12-24 09:59:01 +01:00
Alexander Kukushkin 1b032ab618 stick to the python-etcd=0.4.2 until issues=152 is not fixed 2015-12-24 09:56:24 +01:00
Alexander Kukushkin 41bf010cc1 stick to the python-etcd=0.4.2 until issues=152 is not fixed 2015-12-24 09:54:13 +01:00
Alexander Kukushkin 91a10bf122 Execute tests against python 3.5 2015-12-24 09:51:42 +01:00
Alexander Kukushkin 42a5cf70e6 mock socket.getaddrinfo for patroni-ctl unit tests 2015-12-24 09:49:58 +01:00
Alexander Kukushkin 092bf8defa Merge branch 'master' of github.com:zalando/patroni into feature/initdb 2015-11-12 12:22:14 +01:00
Alexander Kukushkin 13cb8e7402 set synchronous_commit to local when creating roles 2015-11-12 12:20:05 +01:00
Alexander Kukushkin d39d297d92 blacklist some options for initdb instead of having big whitelist 2015-11-12 12:07:36 +01:00
Alexander Kukushkin f0a6c86caa Make it possible to specify custom options for initdb
In the initial implementation we were using the only option
--encoding=UTF8. In order to have pg_rewind working with postgresql-9.3
we have to enable data-checksums. The naive approach was to enable it
globaly but taking into account some performance degradation it's better
not to do it but make it possible to configure it.

In addition to that fix all problems with setting up password of default
postgres user: execute CREATE ROLE | ALTER ROLE depending on content of
pg_authid
2015-11-11 15:59:34 +01:00
Alexander Kukushkin 9c16830fc0 Do not fail when there is no postgresql/parameters section in a config file 2015-11-11 10:46:37 +01:00
Alexander Kukushkin 8a70cc4d7b Call touch_member right after demote and promote.
This is necessary to propagate actual information about node into DCS.
2015-11-09 16:22:51 +01:00
Alexander Kukushkin 2d709a48e6 fix test_create_replica unit test 2015-10-26 11:30:04 +01:00
Alexander Kukushkin ab64ae7fe7 execute delete_trigger_file() after successfull call of create_replica() 2015-10-26 11:29:32 +01:00
Alexander Kukushkin 553129a981 Revert "Fix unit-test for Postgresql.controldata()"
This reverts commit deaaf8ad1a.
2015-10-23 15:59:20 +02:00
Alexander Kukushkin ad719297c2 Merge branch 'master' of github.com:zalando/patroni into feature/custom-namespace 2015-10-23 15:58:42 +02:00
Alexander Kukushkin 8e41d14283 Merge branch 'master' of github.com:zalando/patroni into feature/custom-namespace 2015-10-23 09:13:52 +02:00
Alexander Kukushkin deaaf8ad1a Fix unit-test for Postgresql.controldata() 2015-10-21 15:38:51 +02:00
Alexander Kukushkin 2c7e3f60cc Make possible to override default namespace (/service/) from a config file
If the namespace is not specified in a config file /service/ would be
used.
Also it's possible to use just '/' as a namespace. It means we would
have following structure:
  /scope1
  /scope2
  ...
2015-10-21 15:34:55 +02:00
Alexander Kukushkin c4a6dd48d3 remove debug print statement 2015-10-21 11:09:37 +02:00
Alexander Kukushkin 8bd28507a9 format tests according to the latest pep8 standards 2015-10-21 11:08:06 +02:00
Alexander Kukushkin 0096b6b06f Schedule update of machines cache when api_execute call has failed
Such situation could happen if we replaced all etcd nodes except one
which was used by patroni. After replacing the last node patroni will
try to execute request on all other nodes from machines_cache but non of
them are available. Michines cache would became empty and patroni will
stick to the latest node which was available in the machines_cache and
will never try to refresh machines_cache from dns for example.

Currently machines cache is refreshed only when one request to the etcd
cluster has failed, but probably it should be done periodically, for
example every minute...
2015-10-21 10:56:43 +02:00
Alexander Kukushkin f53c968d8b Improve tests 2015-10-20 14:36:49 +02:00
Alexander Kukushkin 18eebdadaa Watch for change of failover key.
If the value is empty and leader didn't changed, this probably means
that failover failed.

After 15 seconds timeout we will consider failover status = unknown
2015-10-19 15:00:06 +02:00
Alexander Kukushkin 2ebbebac7f Merge branch 'master' of github.com:zalando/patroni into feature/api 2015-10-19 09:37:11 +02:00
Alexander Kukushkin 921e4fc323 psycopg2 should be not older than 2.6.1 2015-10-16 10:28:15 +02:00
Alexander Kukushkin 3ed82ae22c Manual failover via rest api
curl -XPOST --data '{"leader": "leader_name", "member": "member_name"}' http://127.0.0.1:8008/failover

It will execute some preliminary checks and write failover key into DCS.
Afterward it will wait until new leader key will appear in a DCS.

It's better to execute this request on the master node. It will send a
signal to the main HA loop which makes possible to release leader key
immidiately even if you are working with etcd.
2015-10-15 16:18:28 +02:00
Alexander Kukushkin f35d109810 Bugfix: do not try to double encode data 2015-10-15 16:17:11 +02:00
Alexander Kukushkin 16a0a3481d fix pep8 formatting 2015-10-15 09:08:33 +02:00
Alexander Kukushkin 2f0cf1db06 Mock etcd client delete method 2015-10-15 09:08:16 +02:00
Alexander Kukushkin cf6be5f58e add missing tests for async_executor 2015-10-09 16:02:34 +02:00
Alexander Kukushkin a588ddc23c Merge branch 'master' of github.com:zalando/patroni into feature/manual-failover 2015-10-09 15:58:38 +02:00
Alexander Kukushkin a6603e8b48 bugfix in zookeeper module:
when master node was being attached to patroni/zookeeper (no cluster in
zookeeper yet) patroni has never tried to "refetch" cluster from DCS.
It was leeding to demote...
2015-10-08 13:07:38 +02:00
Alexander Kukushkin 8a844285ff Set fetch_cluster flag to False when _inner_load_cluster called
Set the same flag to True if the cluster does not yet exists in
ZooKeeper
2015-10-07 16:48:39 +02:00
Alexander Kukushkin d48f8384ed leader variable should be None if the leader.name == my name.
This check has to be performed even check_recovery_conf call
2015-10-06 10:07:40 +02:00
Alexander Kukushkin 601ba7db8d Make work with dcs.cluster thread-safe 2015-10-05 14:30:47 +02:00
Alexander Kukushkin 4c444c943e tests for Api.do_GET method 2015-10-02 13:17:58 +02:00
Alexander Kukushkin d8f4b09478 use Event.wait instead of sleep
it makes possible to break "sleep" for example from API

plus small bugfix: catch ValueError exception from json.loads
2015-10-02 10:26:48 +02:00
Alexander Kukushkin d09875a056 refactoring:
1. run touch_member from the main loop
2. move code which takes care about long tasks into separate class
3. change format of data stored in a DCS: use json instead of url
4. change Member class: from now it deserialize everything into data property
5. rework API: from now it takes into account state of the current node in a dcs
2015-10-01 17:06:42 +02:00
Alexander Kukushkin a6cb7563e5 catch all exceptions in change_replication_slots method 2015-10-01 08:06:00 +02:00
Alexander Kukushkin 1997f15a7a Run long time operations asynchronously
i.e. restart, reinitialize, demote
2015-09-30 17:08:15 +02:00
Alexander Kukushkin 0572fec6a3 remove leader lock after stop of postgres to speed up failover 2015-09-29 12:59:26 +02:00
Alexander Kukushkin a259764458 Suppress logging from API when postgres is being bootstrapped/initialized 2015-09-29 08:39:05 +02:00
Alexander Kukushkin c218054d05 Implement manual failover
Implementation is done on top of feature/is-healthiest-via-api and
feature/api branches.
In order to trigger manual failover one has to create 'failover' key in
a configuration store with the value in following format:
'leader_name:member_name'
leader_name can be empty or should match with the name of current leader
member_name can be empty or should match with the name one of cluster
nodes
Leader always checks that either desired member (if specified) or one of
the memners is accessible and healthy before demote.
After leader has deomted himself other nodes are performig checks that
desired node is healthy. If it is not they are participating in a leader
race. In some cases (when accidently there is no healthy nodes) former
leader can also participate in a leader race.

Current implementation does not provide REST API endpoint for a manual
failover.
2015-09-28 17:00:42 +02:00
Alexander Kukushkin 3b1b6ff448 revert log level to INFO 2015-09-24 16:54:16 +02:00
Alexander Kukushkin dffa1767f2 Merge branch 'master' of github.com:zalando/patroni into feature/api 2015-09-24 16:53:16 +02:00
Alexander Kukushkin 6e9cb60fd5 Restart and reinitialize via api
POST /restart -- will restart postgres
You you are restartung leader node, lock would be maintained during
restart.

POST /reinitialize -- will reinitialize node from the leader.
It's not possible to reinitialize current leader.
Command will fail when the leader is unknown.
2015-09-24 14:52:03 +02:00
Alexander Kukushkin a4266be3da remove unused function 2015-09-23 10:59:55 +02:00
Alexander Kukushkin e83651b57b Run initial cluster bootstrap from the main loop 2015-09-23 10:55:38 +02:00
Alexander Kukushkin d8e51f586f Merge branch 'feature/query-retry' of github.com:zalando/patroni into feature/query-retry 2015-09-20 13:58:12 +02:00
Alexander Kukushkin d8982e1e5a Refactor Postgresql.query method to use common retry mechanism
query method in an api.py also needs retry in some cases (for example
when we are running is_healthiest_node check).
In all cases we should retry only when connection is closed or broken.
BUT, the connection status must be checked via cursor.connection (old
implementation was using general connection object for that). For
multi-threaded applications this is not appropriate, because some other
thread might restore connection.

In addition to that I've changed most of the unit tests to use `Mock` and
`patch` where it is possible.
2015-09-20 13:54:30 +02:00
Alexander Kukushkin 9f9cb6005d Refactor Postgresql.query method to use commont retry mechanism
query method in an api.py also needs retry in some cases (for example
when we are running is_healthiest_node check).
In all cases We will retry only when connection is closed or broken, BUT
connection status must be checked via cursor.connection (old
implementation was using general connection object for that). For
multi-threaded applications this is not appropriate, because some other
thread might restore connection.

In appdition to that I've changed most of the unit tests to use `Mock` and
`patch` where it is possible.
2015-09-20 13:41:57 +02:00
Alexander Kukushkin 0a3a6d72cf Fix etcd unit tests 2015-09-18 15:33:58 +02:00
Alexander Kukushkin 9dfb562a4f wait for event on leader key a little bit longer than timeout 2015-09-18 15:29:50 +02:00
Alexander Kukushkin 3145e94797 check ignore_sigterm flag instead of setting new handler for SIGTERM 2015-09-18 15:27:09 +02:00
Alexander Kukushkin afe1a2c92c During shutdown sigterm is send to all processes every second
First time is triggers some shutdown mechanisms in a patroni, but the
second one just terminates patroni. Solution is pretty simple, we need
to ignore all other sigterms which are coming after the first one.
2015-09-18 12:41:36 +02:00
Alexander Kukushkin 6530e1f7aa Remove unused parameter in a is_leader method 2015-09-17 16:11:08 +02:00
Alexander Kukushkin 0b753d25e1 Get rid from is_promoted flag. use role == 'master' instead 2015-09-17 13:57:29 +02:00
Alexander Kukushkin dbcc5aff9b Track postgresql role in a Postgresql class 2015-09-16 16:22:10 +02:00
Alexander Kukushkin e204945b3d Merge branch 'master' of github.com:zalando/patroni into feature/faster_shutdown 2015-09-16 15:20:53 +02:00
Alexander Kukushkin 0435e36cad self.cluster = None if unexpected exception occured 2015-09-16 15:14:02 +02:00
Alexander Kukushkin 246f0dbbaf watch should return true if you are not leader 2015-09-16 14:23:47 +02:00
Alexander Kukushkin c240fd1ee8 More documentation for watch method 2015-09-16 11:09:53 +02:00
Alexander Kukushkin 7f8e95b334 Next run of ha cycle is rescheduled depending on return value of watch
Current etcd implementation does not yet support timeout option when
`wait=true`: https://github.com/coreos/etcd/issues/2468

Originaly I've implemented `watch` method for `Etcd` class in a
following manner: if the leader key was updated just because master
needs to update ttl and watch timeout is not yet expired, I was
recalculating timeout and starting `watch` call once again.
Usually after "restart" we were getting urllib3.exceptions.TimeoutError.
The only possible way to recover after such exception - close socket and
establish a new connection. With pure http it's relatively cheap, but
with https and some kind of authorization on etcd side it would became
rather expensive and should be avoided.
2015-09-16 10:38:34 +02:00
Alexander Kukushkin 01efcc8638 Merge branch 'master' of github.com:zalando/patroni into feature/basic-auth
Conflicts:
	tests/test_patroni.py
2015-09-15 09:33:18 +02:00
Alexander Kukushkin 90cfcf0c14 Make zookeeper module compatible with python3 2015-09-14 17:14:39 +02:00
Alexander Kukushkin 44a20f12a4 version field is znode is just version, not mzxid 2015-09-14 16:32:45 +02:00
Alexander Kukushkin 98488a00a2 Remove unused import of KazooException 2015-09-14 12:00:24 +02:00
Alexander Kukushkin 4a081bcb71 Run cancel_initialization with retry 2015-09-14 11:58:10 +02:00
Alexander Kukushkin 209c985420 get_node and get_children should catch only NoNodeError exception.
All other exceptions are needed to have retry functionality working
correctly.
2015-09-14 11:45:00 +02:00
Alexander Kukushkin f494d2ce64 Build Cluster object for ZooKeeper the same way as for Etcd
Previous implementation was always setting Cluster.initialize to True.
Also it was throwing ZooKeeperError when there were no members in a
cluster.

Plus BUGFIX of a bug introduced with
https://github.com/zalando/patroni/pull/34 in a `load_members` method.
- data = self.get_node(self.member_path)
+ data = self.get_node(self.members_path + member)
It was always fetching the same node for all cluster members.
Fortunately Etcd doesn't have such problem because we are fetching the
whole cluster directory with one recursive API call.
2015-09-14 11:19:46 +02:00
Alexander Kukushkin f292398e94 Merge branches with ssl and basic-auth support together 2015-09-10 16:49:55 +02:00
Alexander Kukushkin 3d7c6118de Add missing body to authenticate request 2015-09-10 16:29:17 +02:00
Alexander Kukushkin e6f069018c Merge branch 'feature/api-https' of github.com:zalando/patroni into feature/api-https 2015-09-10 15:36:43 +02:00
Alexander Kukushkin 5d304e95ed Merge branch 'master' of github.com:zalando/patroni into feature/api-https 2015-09-10 15:34:43 +02:00
Alexander Kukushkin d830e8de7c Merge branch 'master' of github.com:zalando/patroni into feature/basic-auth 2015-09-10 15:33:31 +02:00
Alexander Kukushkin abcaf2b94a Possibility to protect some endpoints with basic-auth
user:passwd pair should be configured in restapi section of main
configuration file in following format:
restapi:
  auth: 'username:password'

Plus implemented some simple routing mechanisms:
GET /foo => do_GET_foo()
POST /bar => do_POST_bar()
2015-09-10 15:25:08 +02:00
Alexander Kukushkin 36cbd34ffc Fix zookeeper test coverage 2015-09-09 15:59:02 +02:00
Alexander Kukushkin 5bdb18761b Define initialize, leader, optime and members string constansts in AbstractDCS
Also define following properties:
* initialize_path
* members_path
* member_path
* leader_path
* leader_optime_path

And replace any occurrences of these strings or client_path calls in a
etcd and zookeeper implementations with given constants and properties.
2015-09-09 15:10:45 +02:00
Alexander Kukushkin 1d9333dcdc Update documentation and configs with examples of usage of SSL. 2015-09-09 12:19:50 +02:00
Alexander Kukushkin b5a5ea2a75 Add SSL wrapper around restapi server socket
If config['restapi']['certfile'] is specified and not empty http server
would be wrapped into SSL and api connection string changed accordingly:
http:// => https://
2015-09-09 12:15:52 +02:00
Alexander Kukushkin 61d1d5a098 Set current version to 0.2 2015-09-08 12:42:12 +02:00
Alexander Kukushkin fa22d91e05 Move some basic methods implementation into parent exception class 2015-09-08 12:41:48 +02:00
Alexander Kukushkin 5ea0ab70f5 Add patroni.py executable file 2015-09-07 10:37:10 +02:00
Alexander Kukushkin 650e244904 Refactor directory structure in preparation for building pypi-package 2015-09-04 16:06:44 +02:00
Alexander Kukushkin a69565fc5f Set Postgresql._SERVER_VERSION only after real connect. 2015-09-04 13:22:44 +02:00
Alexander Kukushkin c913c8ad92 Calculate xlog bytes with using lsn_to_bytes method
This method behaves differently depending on server version and will
allow to use patroni with postgres older than 9.3
2015-09-04 12:11:55 +02:00
Alexander Kukushkin 8b9e99090f Move lsn_to_bytes and bytes_to_lsn into Postgresql class
and make their behavior version specific
2015-09-04 10:41:59 +02:00
Alexander Kukushkin 9361732722 Fix pep8 formatting and unit-tests 2015-09-04 08:29:16 +02:00
Alexander Kukushkin 50420771ce Retry when executing take_leader method. 2015-09-03 16:53:15 +02:00
Alexander Kukushkin 2f6399de27 More unit-tests for etcd 2015-09-03 16:35:58 +02:00
Alexander Kukushkin 66286733b2 Enable retry functionality for etcd with default deadline=10 seconds 2015-09-03 15:03:09 +02:00
Alexander Kukushkin 8d99fd17a0 Merge branch 'master' of github.com:zalando/patroni into feature/retry 2015-09-03 13:18:58 +02:00
Alexander Kukushkin e8b2fb112b It is better to reap childs before running relatively long sleep 2015-09-03 11:50:58 +02:00
Alexander Kukushkin 58410db9dd Implemented Retry class inspired by KazooRetry 2015-09-03 11:47:08 +02:00