237 Commits

Author SHA1 Message Date
Oleksii Kliukin
87a5646ad0 Merge branch 'restore/movebasebackup' of https://github.com/pgexperts/patroni into pgexperts-restore/movebasebackup 2015-11-16 12:04:32 +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
Josh Berkus
30aa83c5b2 Fixed failing tests, pep8 issues. 2015-11-02 17:51:01 -08:00
Alexander Kukushkin
2d709a48e6 fix test_create_replica unit test 2015-10-26 11:30:04 +01:00
Oleksii Kliukin
c426b8c246 Merge branch 'master' of https://github.com/zalando/patroni into feature/configurable_pgpass 2015-10-21 13:07:42 +02:00
Oleksii Kliukin
3c3694dc7c Merge pull request #73 from zalando/bugfix/update-machines-cache
Bugfix/update machines cache
2015-10-21 12:11:11 +02:00
Oleksii Kliukin
0b69ef93cf Merge branch 'master' of https://github.com/zalando/patroni into feature/clusterid 2015-10-21 12:02:55 +02:00
Alexander Kukushkin
8bd28507a9 format tests according to the latest pep8 standards 2015-10-21 11:08:06 +02:00
Oleksii Kliukin
92fe6a1de9 Make pgpass location configurable.
One can use pgpass configuration parameter in the postgres
subsection of Patroni. By default pgpass is written in ~/.
Mock actual writes to pgpass in the tests.
2015-10-20 11:28:26 +02:00
Oleksii Kliukin
90c738d83a Address the code review by Alex. 2015-10-19 16:03:21 +02:00
Oleksii Kliukin
8f606e4ff9 Add a missing call to restore_configuration_files.
I accidentially removed the call when moving the backup functions
to the external script. It is intended to save the configuration,
so that at the restore phase one can just copy backup files.
Its primary intention was to save configuration files in the WAL-E
case (WAL-E just omits everything with .conf), but it is also
useful in the pg_basebackup case, which omits all symlinks, leaving
the cluster with .conf files symlinked in the broken state.
2015-10-19 15:13:24 +02:00
Oleksii Kliukin
4e448015f3 Increase the test coverage. 2015-10-19 10:13:14 +02:00
Alexander Kukushkin
16a0a3481d fix pep8 formatting 2015-10-15 09:08:33 +02:00
Oleksii Kliukin
c7246e48d9 Work around the differences in pg_controldata names. 2015-10-14 09:46:20 +02:00
Oleksii Kliukin
101082fa3b more tests. 2015-10-13 09:08:27 +02:00
Oleksii Kliukin
94aa6873f4 Add more tests for the new postgresql methods. 2015-10-13 08:19:44 +02:00
Oleksii Kliukin
46f4788c28 Do not try to run postgres -D during unit tests. 2015-10-12 17:06:13 +02:00
Oleksii Kliukin
d7988384d3 Address the code review by Alex Kukushkin:
- check the link before checking the file when deciding to remove it,
  as isfile follows symlinks and, therefore, may return True on them.
- Remove append mode from write_pgpass, as it is always written anew
  before it is used.
- make pg_controldata return an empty hash in case of an error, and
  check for the empty value return by this function before using it.
 some other minior fixed and test updates.
2015-10-12 16:24:02 +02:00
Oleksii Kliukin
ce7169f61d Add new tests ha and postgresql. 2015-10-12 15:29:47 +02:00
Oleksii Kliukin
42137e689b Merge remote-tracking branch 'origin/master' into feature/pg_rewind_unclean_shutdown
Modify HA tests to reflect the changes in HA::recover.
2015-10-12 09:22:38 +02:00
Oleksii Kliukin
b629e0852f Call pg_rewind in case of the master's unclean shutdown.
If patroni detects the former master was killed, it runs
it first in a single-user mode and then shuts down normally,
to make sure pg_rewind will see a normal shut down status
in pg_controldata.

Add a flag need_rewind, since the point where it is detected
that rewind might be necessary is moved out the code that
runs rewind.
2015-10-12 08:34:08 +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
Oleksii Kliukin
a500781b6d Mock remove_data_directory in the pg_rewind test. 2015-09-30 16:32:56 +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
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
Oleksii Kliukin
b62d72a130 Merge branch 'master' into feature/pg_rewind 2015-09-25 13:08:42 +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
Oleksii Kliukin
027bcd39ce Move pg_rewind call into a separate sub.
Add a Postgresql method to call pg_rewind.
Improve the test coverage.
2015-09-24 12:46:36 +02:00
Alexander Kukushkin
e83651b57b Run initial cluster bootstrap from the main loop 2015-09-23 10:55:38 +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
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
Oleksii Kliukin
51eacc5042 Handle the case when initialize flag is not set and leader is present. 2015-09-14 12:36:28 +02:00
Alexander Kukushkin
1774d6e31a Merge branches watch-leader-key and package-refactoring 2015-09-05 16:09:28 +02:00
Alexander Kukushkin
3a4a2dbb94 Merge branch 'master' of github.com:zalando/patroni into feature/watch-leader-key 2015-09-05 15:31:37 +02:00
Alexander Kukushkin
ac2740eeb9 Drop unused variable server_version 2015-09-05 15:22:38 +02:00
Alexander Kukushkin
7cce02ae95 Always use pg_xlog_location_diff to calculate bytes written to xlog
Drop unused functionality (lsn_to_bytes, bytes_to_lsn)
Revert some changes.
2015-09-05 15:19:17 +02:00
Alexander Kukushkin
650e244904 Refactor directory structure in preparation for building pypi-package 2015-09-04 16:06: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
df06860bde Merge pull request #23 from pgexperts/93compat
93compat
2015-09-04 08:14:13 +02:00
Josh Berkus
f5627a498e Fixed test_postgresql.py to include use_slots. 2015-09-03 18:41:30 -07:00
Alexander Kukushkin
3b1efff53e Refactor Cluster object
`Cluster.leader` is not reference to `Member` anymore, but to `Leader`
`Leader` class contains field `index` (update index). This field is very
useful for watching for events which changing leader key. Also `Leader`
contains `member` field, which should reference real member.
2015-08-27 10:53:22 +02:00
Alexander Kukushkin
420176aa75 Merge branch 'master' of github.com:zalando/patroni into feature/python-etcd 2015-08-25 10:11:29 +02:00
Alexander Kukushkin
befd33555d Refactor helpers/etcd.py
Work with etcd cluster via high-level python-etcd module.
Plus change all unit tests accordingly.
2015-08-24 16:58:08 +02:00
Oleksii Kliukin
29434e24ea Allow relative paths to external scripts. 2015-08-24 16:53:57 +02:00