Commit Graph
100 Commits
Author SHA1 Message Date
Oleksii Kliukin 70cbbb4ef4 Ignore only socket.error at finalization stage of StreamRequestHandler, not other errors. 2015-11-12 17:55:02 +01:00
Oleksii Kliukin 28934350ef Handle haproxy requests. Improve failover status code.
By default, haproxy sens an OPTION request, which we didn't
handle until now. In addition, all haproxy requests that doesn't
examine the request body close the connection as soon as the status
code is obtained. Such behavior breaks BaseHTTPRequestHandler,
namely handle_one_request, which doesn't check for connection reset
by peer and throw this error on a higher level, but since we don't
call this function directly, there is no place in the code to catch
it, therefore, we have to patch this function in the base class.
In addition, patch the StreamRequestHandler finish() function in
order to handle the connection reset error.

Re-read the cluster from DCS right after the failover to supply
the correct new values to the API thread. Fix a typo.
2015-11-12 17:38:22 +01:00
Oleksii Kliukin a8312dfefc Fixed a typo in the error message. 2015-11-10 18:14:18 +01:00
Oleksii Kliukin e52a34de1c Remove the useless codeline. 2015-11-03 16:04:01 +03:00
Oleksii Kliukin 87ead9ddaf Fix haproxy configuration to work by default with Patroni. 2015-11-01 15:29:45 +03:00
Oleksii Kliukin a1a7c9b4c5 Make sure nofailover tag is set to False by default. 2015-10-27 09:46:03 +01:00
Oleksii Kliukin 8d68130aac Fix the test to account for an extra parameter returned by fetch_node_statuses. 2015-10-27 09:32:09 +01:00
Oleksii Kliukin da74aee2cd Make sure that nofailover presents the node even from initializing the cluster. 2015-10-26 18:57:28 +01:00
Oleksii Kliukin 685363c5a8 Fix an invocation fo fetch_node_statuses in the API code to account for the tags 2015-10-26 18:57:05 +01:00
Oleksii Kliukin 1f9d8c039c Add tests for nofailover. 2015-10-26 17:19:35 +01:00
Oleksii Kliukin ed5e3e53e2 Use a shortcut to call patroni nofailover attribute. 2015-10-26 17:18:45 +01:00
Oleksii Kliukin 2044d4db96 Move nofailover checks on the upper level.
Instead of checking that nofailover node should not
be marked as healthiest in one of the _failover
functions, do make it unhealthy in the is_healthiest_node.
2015-10-26 14:52:34 +01:00
Oleksii Kliukin 84db64e0d5 Merge branch 'master' of https://github.com/zalando/patroni into feature/nofailover 2015-10-26 10:41:51 +01:00
Oleksii Kliukin a2736cd2b7 Add nofailover property to Patroni and Cluster.
Add checks for nofailover tag in is_failover_possible
in order to save on API calls for the nodes with this tag set.
2015-10-26 10:40:34 +01:00
Oleksii Kliukin 0c5a21e57d Fix removal of keys on failed initialization.
The initialize key was checked against the value
of the node name before removal, but it was changed
recently to contain either an empty string, or cluster
sysid. To fix this, the check for the previous value
was simply removed: we can guarantee that the code path
that removes the key is the one that created it.
2015-10-23 10:46:55 +02:00
Oleksii Kliukin b7b47ffd79 Add support for the nofailover tag. 2015-10-23 10:11:38 +02:00
Oleksii Kliukin 2200a4ce8c Add support for per-member tags.
Tags are labels assigned to individual members in order
to alter its default behavior, i.e. exclude from the
leader election or indicate a possibility to create base
backups from the member.

This commit only adds support for setting tags in the
configuration file, exposes the tags to DCS /member subkey
and returns the tags in a response of the API request. At
the moment the tag names are not validated, nor they are
interpreted in any way.

Support for setting tags via the API is also in the scope
of further work.
2015-10-21 15:51:21 +02: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 9130891029 Move calculation of pgpass to the class constructor: better to fail fast in case of issues. 2015-10-21 13:06:54 +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
Oleksii Kliukin 44a73982d4 Do not try to fetch the element from the get_node result if the node is not there. 2015-10-21 12:00:03 +02:00
Oleksii Kliukin 35641ac072 Use distinct paths for pgpass from test nodes. 2015-10-20 11:40:52 +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 40c5d5e351 Match default param in the abstract class definition with those from the implementation. 2015-10-19 16:08:52 +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
Oleksii Kliukin 11073ac644 Merge branch 'master' into feature/clusterid 2015-10-19 09:37:51 +02:00
Oleksii Kliukin a10b7248a6 Fix a flake8 warning 2015-10-19 09:19:25 +02:00
Oleksii Kliukin 83662f71cb Exit right away if the node sysid is different from the cluster's one 2015-10-16 16:38:05 +02:00
Oleksii Kliukin a844920489 Store the cluster sysid in the initialize flag.
Make sure that the new PostgreSQL node will only
join the cluster if its sysid matches the one
stored in DCS.
2015-10-16 16:14:45 +02:00
Oleksii Kliukin 5c86b60cd2 Fix an exception in the (rather unusual) case of attaching Patroni to an existing running replica. 2015-10-14 17:05:09 +02:00
Oleksii Kliukin c7246e48d9 Work around the differences in pg_controldata names. 2015-10-14 09:46:20 +02:00
Oleksii Kliukin 953ea749bf Make sure patroni is not using stale connections.
After the PostgreSQL crash (i.e. with kill -9), the backend
patroni connects to may still exist. In this case, patroni
will get stale postgres role from this backend, preventing
a restarted node with a leader lock from being promoted.

Easily reproducible and also observed in a staging environment
after the postgres crash due to out of disk space.
2015-10-13 15:00:16 +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
Oleksii Kliukin bad37a5a21 Always check that cluster is configured correctly right before running pg_rewind. 2015-10-02 10:57:49 +02:00
Oleksii Kliukin ea910a8987 Make sure pgpass file name is also passed in the PGPASSFILE environment variable. 2015-09-30 18:02:07 +02:00
Oleksii Kliukin b223319183 use the PATH to get the python interpreter path for the scripts. 2015-09-30 18:00:28 +02:00
Oleksii Kliukin d7403f999d Merge branch 'feature/pg_rewind' of https://github.com/zalando/patroni into feature/pg_rewind 2015-09-30 17:13:16 +02:00
Oleksii Kliukin 316e4f8d74 Merge branch 'master' into feature/pg_rewind 2015-09-30 17:12:03 +02:00
Oleksii Kliukin b4a2ed874f Merge branch 'master' of https://github.com/zalando/patroni 2015-09-30 16:47:07 +02:00
Oleksii Kliukin 182a90973d Make sure tests work with the new pytest. 2015-09-30 16:46:53 +02:00
Oleksii Kliukin a500781b6d Mock remove_data_directory in the pg_rewind test. 2015-09-30 16:32:56 +02:00
Oleksii Kliukin e39d318732 Eliminate os.system call. 2015-09-28 12:04:06 +02:00
Oleksii Kliukin d44a54628a remove the data directory on an unsuccessfull rewind attempt. 2015-09-25 16:00:24 +02:00
Oleksii Kliukin b62d72a130 Merge branch 'master' into feature/pg_rewind 2015-09-25 13:08:42 +02:00
Oleksii Kliukin d6c8df45e1 Write the pg_rewind password in pgpass instead of passing it in the command line. 2015-09-25 13:08:12 +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
Oleksii Kliukin c8108f221e Check the exit code of the postgres start when determining whether to run the on_role_change callback. 2015-09-24 11:34:28 +02:00
Oleksii Kliukin 793325cb60 add support for pg_rewind. 2015-09-23 18:38:17 +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
Oleksii Kliukin be110c4ba0 Do not try to stop postgres twice if initialization had failed. 2015-09-14 09:20:45 +02:00
Oleksii Kliukin 15cd10669d Change an outdated comment. 2015-09-10 18:04:47 +02:00
Oleksii Kliukin cd312de252 Fix a flake8 warning.
Improve some unit tests by expecting specific exceptions.
2015-09-10 17:15:43 +02:00
Oleksii Kliukin 2377c417e4 Fix etcd and zookeper interactions with initialize key.
Fix unittests as well.
2015-09-10 16:05:10 +02:00
Oleksii Kliukin 938b946e55 Merge branch 'master' into feature/cleanup_on_failed_initialization 2015-09-10 15:43:31 +02:00
Oleksii Kliukin 30a9e0f7f5 Move PostgreSQL data directory if init had failed.
Prevent treating the incompletely-initialized PostgreSQL cluster
as a valid on restart by forcefully moving the data directory.
I don't want to remove it altogether, since a DBA might decide
to analyze the failed PG cluster in order to resolve the init
issue.
2015-09-10 15:34:29 +02:00
Oleksii Kliukin 1c61280d70 Fix path to scripts subdirectory in configuration files. 2015-09-08 16:10:42 +02:00
Oleksii Kliukin ff499604f0 Act on removal of initialization flag.
If initializer node suddenly dies before the initialization is complete,
other nodes should try to take over.

Fix some unittests for etcd and zookeeper and add couple of new ones.
2015-09-08 16:04:54 +02:00
Oleksii Kliukin 92647b7aad Merge branch 'master' of https://github.com/zalando/patroni into feature/cleanup_on_failed_initialization 2015-09-08 14:54:52 +02:00
Oleksii Kliukin b842ed478b Make sure initialize flag is reset on failure.
Cleanup the initialize flag if the initializing node fails
to bootstrap its PostgreSQL database.

Rename dcs.race to initialize, since we only call it for the
initialize flag. Factored out PostgreSQL bootstrapping code
into a separate function.
2015-09-08 12:03:34 +02:00
Oleksii Kliukin da132ca1fc Do not rely on env vars for superuser role name.
Environment variables may not be set in Docker.
Instead, obtain the superuser role from the database.
2015-09-02 15:20:16 +02:00
Oleksii Kliukin b21bc89bd7 Merge branch 'master' into feature/faster_shutdown 2015-09-02 14:16:04 +02:00
Oleksii Kliukin 80f92b1dee Run CHECKPOINT before calling shutdown.
In addition, restart is now performed as stop/start,
which would allow it to benefit from the shutdown speedup.

The hooks in start/stop are modified in order not to run
when called as a part of restart.
2015-09-02 14:14:16 +02:00
Oleksii Kliukin a5f2ab6f88 Better SIGCHLD handling, use correct user name.
- Defer SIGCHLD processing until the later stage in order to allow
  subprocess to run its own reaping of children and return the correct
  exit code from the process called.

- When changing the password at startup, do not assume the user postgres.
2015-09-02 12:56:23 +02:00
Oleksii Kliukin 3e4d2df33b put a real restore/replication command inside the test postgres.yaml files 2015-09-02 12:04:39 +02:00
Oleksii Kliukin af10bb8ab8 make sure replica-creation scripts are also available to patroni docker image. 2015-08-25 18:22:47 +02:00
Oleksii Kliukin 6b60be09a1 include restore command in the entyrpoint 2015-08-25 16:19:22 +02:00
Oleksii Kliukin 824819bbff Make script compatible with boot2docker on OS X by exporting the correct LC_ variable and running docker with -P, exposing the ports to the underlying OS. 2015-08-25 16:18:59 +02:00
Oleksii Kliukin 29434e24ea Allow relative paths to external scripts. 2015-08-24 16:53:57 +02:00
Oleksii Kliukin 164b5760a4 remove line too long warnings where possible. 2015-08-07 16:35:00 +02:00
Oleksii Kliukin 5d1d59a42b Add mock-based unit tests for the restore module.
- add unit tests for the restore module
- additional dependencies in requirement
- harden the code that calls restore callbacks
- remove WAL-E related code from postgresql.py
2015-08-07 16:05:17 +02:00
Oleksii Kliukin 74a1daad09 fix a typo in the named tuple definition. 2015-08-04 17:13:36 +02:00
Oleksii Kliukin 8bed553d30 Use new-style classes. 2015-08-04 16:52:03 +02:00
Oleksii Kliukin e69f015369 switch to using WAL-E by default. 2015-08-04 16:22:46 +02:00
Oleksii Kliukin 67da1b3a78 Make parse_connstring staticmethod less 'selfish' 2015-08-04 15:26:12 +02:00
Oleksii Kliukin f17b651107 Adoprt WAL-E related code for a stand-alone script.
- make sure all parameters are taken from the env variables.
- make sure WAL-E code is not involved if the image is not configured for it
- pick up pg_basebackup as an alternative if WAL-E fails.

The WAL-E support will be switched on in subsequent commits.
2015-08-04 14:10:11 +02:00
Oleksii Kliukin fd884a53a9 Multiple small fixes:
- Do delete trigger file in the patroni itself.
- Fix the typo in the datadir member.
- Add #! at the top of the python script.
2015-08-03 15:51:40 +02:00
Oleksii Kliukin 2089a123c2 fix line too long warning. 2015-08-03 11:48:02 +02:00
Oleksii Kliukin 7f2dcc0a95 Move replica creation code into a separte file. So far, only the class that makes replicas with pg_basebackup is called. 2015-08-03 11:44:11 +02:00
Oleksii Kliukin a0fdd6398f Cosmetic changes: avoid magic strings in action names, name the parameter passed to the callback 'scope' for consistency. 2015-07-30 10:17:17 +02:00
Oleksii Kliukin 71a1200f64 Fix a mistake in checking for the number of parameters. 2015-07-29 12:09:17 +02:00
Oleksii Kliukin 5171964758 Merge branch 'master' into feature/callbacks 2015-07-27 16:19:03 +02:00
Oleksii Kliukin 5c5bae69ea make sure we can import from scripts. 2015-07-27 16:11:58 +02:00
Oleksii Kliukin 27bda5b4e4 document the new callbacks option. 2015-07-27 13:12:08 +02:00
Oleksii Kliukin 7d1bc32ad9 potentially run the doctests for the scripts. 2015-07-27 13:06:44 +02:00
Oleksii Kliukin d85451efae Increase test coverage for aws script. 2015-07-27 13:04:45 +02:00
Oleksii Kliukin b92bfb34a5 Futher test for postgresql module (includes callbacks) 2015-07-27 13:04:01 +02:00
Oleksii Kliukin 56983d867d Run coverage test for the data in scripts as well as helpers. 2015-07-27 13:03:12 +02:00
Oleksii Kliukin 115ba1d9ae Make sure postgresql.stop also return True if pg_ctl stop returned 0. 2015-07-27 11:23:08 +02:00
Oleksii Kliukin 201f9bf4b2 Make sure role check during callbacks does not accidentially modify the cluster state (is_promoted flag or trigger file). 2015-07-27 11:08:19 +02:00
Oleksii Kliukin 859da0db0a Make unit tets run again. 2015-07-27 10:10:29 +02:00
Oleksii Kliukin dac3d7997f Change a typo. 2015-07-24 10:47:26 +02:00
Oleksii Kliukin 35fe536e8b Set +x bit on aws.py 2015-07-23 17:09:39 +02:00