Skip to content

Commit b470ade

Browse files
authored
Change master->primary, take two (patroni#3127)
This commit is a breaking change: 1. `role` in DCS is written as "primary" instead of "master". 2. `role` in REST API responses is also written as "primary". 3. REST API no longer accepts role=master in requests (for example switchover/failover/restart endpoints). 4. `/metrics` REST API endpoint will no longer report `patroni_master`. 5. `patronictl` no longer accepts `--master` argument. 6. `no_master` option in declarative configuration of custom replica creation methods is no longer treated as a special option, please use `no_leader` instead. 7. `patroni_wale_restore` doesn't accept `--no_master` anymore. 8. `patroni_barman` doesn't accept `--role=master` anymore. 9. callback scripts will be executed with role=primary instead of role=master 10. On Kubernetes Patroni by default will set role label to primary. In case if you want to keep old behavior and avoid downtime or lengthy complex migrations you can configure `kubernetes.leader_label_value` and `kubernetes.standby_leader_label_value` to `master`. However, a few exceptions regarding master are still in place: 1. `GET /master` REST API endpoint will continue to work. 2. `master_start_timeout` and `master_stop_timeout` in global configuration are still accepted. 3. `master` tag is still preserved in Consul services in addition to `primary`. Rationale for these exceptions: DBA doesn't always 100% control the infrastructure and can't adjust the configuration.
1 parent 835d939 commit b470ade

34 files changed

+135
-154
lines changed

docs/ENVIRONMENT.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Consul
5555
- **PATRONI\_CONSUL\_CONSISTENCY**: (optional) Select consul consistency mode. Possible values are ``default``, ``consistent``, or ``stale`` (more details in `consul API reference <https://www.consul.io/api/features/consistency.html/>`__)
5656
- **PATRONI\_CONSUL\_CHECKS**: (optional) list of Consul health checks used for the session. By default an empty list is used.
5757
- **PATRONI\_CONSUL\_REGISTER\_SERVICE**: (optional) whether or not to register a service with the name defined by the scope parameter and the tag master, primary, replica, or standby-leader depending on the node's role. Defaults to **false**
58-
- **PATRONI\_CONSUL\_SERVICE\_TAGS**: (optional) additional static tags to add to the Consul service apart from the role (``master``/``primary``/``replica``/``standby-leader``). By default an empty list is used.
58+
- **PATRONI\_CONSUL\_SERVICE\_TAGS**: (optional) additional static tags to add to the Consul service apart from the role (``primary``/``replica``/``standby-leader``). By default an empty list is used.
5959
- **PATRONI\_CONSUL\_SERVICE\_CHECK\_INTERVAL**: (optional) how often to perform health check against registered url
6060
- **PATRONI\_CONSUL\_SERVICE\_CHECK\_TLS\_SERVER\_NAME**: (optional) overide SNI host when connecting via TLS, see also `consul agent check API reference <https://www.consul.io/api-docs/agent/check#tlsservername>`__.
6161

@@ -113,11 +113,11 @@ Kubernetes
113113
- **PATRONI\_KUBERNETES\_NAMESPACE**: (optional) Kubernetes namespace where the Patroni pod is running. Default value is `default`.
114114
- **PATRONI\_KUBERNETES\_LABELS**: Labels in format ``{label1: value1, label2: value2}``. These labels will be used to find existing objects (Pods and either Endpoints or ConfigMaps) associated with the current cluster. Also Patroni will set them on every object (Endpoint or ConfigMap) it creates.
115115
- **PATRONI\_KUBERNETES\_SCOPE\_LABEL**: (optional) name of the label containing cluster name. Default value is `cluster-name`.
116-
- **PATRONI\_KUBERNETES\_ROLE\_LABEL**: (optional) name of the label containing role (master or replica or other custom value). Patroni will set this label on the pod it runs in. Default value is ``role``.
117-
- **PATRONI\_KUBERNETES\_LEADER\_LABEL\_VALUE**: (optional) value of the pod label when Postgres role is `master`. Default value is `master`.
116+
- **PATRONI\_KUBERNETES\_ROLE\_LABEL**: (optional) name of the label containing role (`primary`, `replica` or other custom value). Patroni will set this label on the pod it runs in. Default value is ``role``.
117+
- **PATRONI\_KUBERNETES\_LEADER\_LABEL\_VALUE**: (optional) value of the pod label when Postgres role is `primary`. Default value is `primary`.
118118
- **PATRONI\_KUBERNETES\_FOLLOWER\_LABEL\_VALUE**: (optional) value of the pod label when Postgres role is `replica`. Default value is `replica`.
119-
- **PATRONI\_KUBERNETES\_STANDBY\_LEADER\_LABEL\_VALUE**: (optional) value of the pod label when Postgres role is ``standby_leader``. Default value is ``master``.
120-
- **PATRONI\_KUBERNETES\_TMP\_ROLE\_LABEL**: (optional) name of the temporary label containing role (master or replica). Value of this label will always use the default of corresponding role. Set only when necessary.
119+
- **PATRONI\_KUBERNETES\_STANDBY\_LEADER\_LABEL\_VALUE**: (optional) value of the pod label when Postgres role is ``standby_leader``. Default value is ``primary``.
120+
- **PATRONI\_KUBERNETES\_TMP\_ROLE\_LABEL**: (optional) name of the temporary label containing role (`primary` or `replica`). Value of this label will always use the default of corresponding role. Set only when necessary.
121121
- **PATRONI\_KUBERNETES\_USE\_ENDPOINTS**: (optional) if set to true, Patroni will use Endpoints instead of ConfigMaps to run leader elections and keep cluster state.
122122
- **PATRONI\_KUBERNETES\_POD\_IP**: (optional) IP address of the pod Patroni is running in. This value is required when `PATRONI_KUBERNETES_USE_ENDPOINTS` is enabled and is used to populate the leader endpoint subsets when the pod's PostgreSQL is promoted.
123123
- **PATRONI\_KUBERNETES\_PORTS**: (optional) if the Service object has the name for the port, the same name must appear in the Endpoint object, otherwise service won't work. For example, if your service is defined as ``{Kind: Service, spec: {ports: [{name: postgresql, port: 5432, targetPort: 5432}]}}``, then you have to set ``PATRONI_KUBERNETES_PORTS='[{"name": "postgresql", "port": 5432}]'`` and Patroni will use it for updating subsets of the leader Endpoint. This parameter is used only if `PATRONI_KUBERNETES_USE_ENDPOINTS` is set.

docs/ha_loop_diagram.dot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ digraph G {
109109
subgraph cluster_process_healthy_cluster {
110110
label = "process_healthy_cluster"
111111
"healthy_has_lock" [label="Am I the owner of the leader lock?", shape=diamond]
112-
"healthy_is_leader" [label="Is Postgres running as master?", shape=diamond]
112+
"healthy_is_leader" [label="Is Postgres running as primary?", shape=diamond]
113113
"healthy_no_lock" [label="Follow the leader (async,\ncreate/update recovery.conf and restart if necessary)"]
114114
"healthy_has_lock" -> "healthy_no_lock" [label="no" color="red"]
115115
"healthy_has_lock" -> "healthy_update_leader_lock" [label="yes" color="green"]
@@ -119,7 +119,7 @@ digraph G {
119119
"healthy_update_success" -> "healthy_is_leader" [label="yes" color="green"]
120120
"healthy_update_success" -> "healthy_demote" [label="no" color="red"]
121121
"healthy_demote" [label="Demote (async,\nrestart in read-only)"]
122-
"healthy_failover" [label="Promote Postgres to master"]
122+
"healthy_failover" [label="Promote Postgres to primary"]
123123
"healthy_is_leader" -> "healthy_failover" [label="no" color="red"]
124124
}
125125
"healthy_demote" -> "update_member"
@@ -134,10 +134,10 @@ digraph G {
134134
"unhealthy_leader_race" [label="Try to create leader key"]
135135
"unhealthy_leader_race" -> "unhealthy_acquire_lock"
136136
"unhealthy_acquire_lock" [label="Was I able to get the lock?", shape="diamond"]
137-
"unhealthy_is_leader" [label="Is Postgres running as master?", shape=diamond]
137+
"unhealthy_is_leader" [label="Is Postgres running as primary?", shape=diamond]
138138
"unhealthy_acquire_lock" -> "unhealthy_is_leader" [label="yes" color="green"]
139139
"unhealthy_is_leader" -> "unhealthy_promote" [label="no" color="red"]
140-
"unhealthy_promote" [label="Promote to master"]
140+
"unhealthy_promote" [label="Promote to primary"]
141141
"unhealthy_is_healthiest" -> "unhealthy_follow" [label="no" color="red"]
142142
"unhealthy_follow" [label="try to follow somebody else()"]
143143
"unhealthy_acquire_lock" -> "unhealthy_follow" [label="no" color="red"]

docs/ha_loop_diagram.png

17.5 KB
Loading

docs/kubernetes.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Patroni Kubernetes :ref:`settings <kubernetes_settings>` and :ref:`environment v
3737
Customize role label
3838
^^^^^^^^^^^^^^^^^^^^
3939

40-
By default, Patroni will set corresponding labels on the pod it runs in based on node's role, such as ``role=master``.
40+
By default, Patroni will set corresponding labels on the pod it runs in based on node's role, such as ``role=primary``.
4141
The key and value of label can be customized by `kubernetes.role_label`, `kubernetes.leader_label_value`, `kubernetes.follower_label_value` and `kubernetes.standby_leader_label_value`.
4242

4343
Note that if you migrate from default role labels to custom ones, you can reduce downtime by following migration steps:
@@ -48,16 +48,16 @@ Note that if you migrate from default role labels to custom ones, you can reduce
4848
4949
labels:
5050
cluster-name: foo
51-
role: master
52-
tmp_role: master
51+
role: primary
52+
tmp_role: primary
5353
5454
2. After all pods have been updated, modify the service selector to select the temporary label.
5555

5656
.. code:: YAML
5757
5858
selector:
5959
cluster-name: foo
60-
tmp_role: master
60+
tmp_role: primary
6161
6262
3. Add your custom role label (e.g., set `kubernetes.leader_label_value=primary`). Once pods are restarted they will get following new labels set by Patroni:
6363

@@ -66,7 +66,7 @@ Note that if you migrate from default role labels to custom ones, you can reduce
6666
labels:
6767
cluster-name: foo
6868
role: primary
69-
tmp_role: master
69+
tmp_role: primary
7070
7171
4. After all pods have been updated again, modify the service selector to use new role value.
7272

docs/rest_api.rst

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ The ``GET /patroni`` is used by Patroni during the leader race. It also could be
103103
$ curl -s http://localhost:8008/patroni | jq .
104104
{
105105
"state": "running",
106-
"postmaster_start_time": "2023-08-18 11:03:37.966359+00:00",
107-
"role": "master",
108-
"server_version": 150004,
106+
"postmaster_start_time": "2024-08-18 11:03:37.966359+00:00",
107+
"role": "primary",
108+
"server_version": 160004,
109109
"xlog": {
110110
"location": 67395656
111111
},
@@ -134,7 +134,7 @@ The ``GET /patroni`` is used by Patroni during the leader race. It also could be
134134
},
135135
"database_system_identifier": "7268616322854375442",
136136
"patroni": {
137-
"version": "3.1.0",
137+
"version": "4.0.0",
138138
"scope": "demo",
139139
"name": "patroni1"
140140
}
@@ -147,9 +147,9 @@ The ``GET /patroni`` is used by Patroni during the leader race. It also could be
147147
$ curl -s http://localhost:8008/patroni | jq .
148148
{
149149
"state": "running",
150-
"postmaster_start_time": "2023-08-18 11:09:08.615242+00:00",
150+
"postmaster_start_time": "2024-08-18 11:09:08.615242+00:00",
151151
"role": "replica",
152-
"server_version": 150004,
152+
"server_version": 160004,
153153
"xlog": {
154154
"received_location": 67419744,
155155
"replayed_location": 67419744,
@@ -182,7 +182,7 @@ The ``GET /patroni`` is used by Patroni during the leader race. It also could be
182182
},
183183
"database_system_identifier": "7268616322854375442",
184184
"patroni": {
185-
"version": "3.1.0",
185+
"version": "4.0.0",
186186
"scope": "demo",
187187
"name": "patroni1"
188188
}
@@ -195,9 +195,9 @@ The ``GET /patroni`` is used by Patroni during the leader race. It also could be
195195
$ curl -s http://localhost:8008/patroni | jq .
196196
{
197197
"state": "running",
198-
"postmaster_start_time": "2023-08-18 11:09:08.615242+00:00",
198+
"postmaster_start_time": "2024-08-18 11:09:08.615242+00:00",
199199
"role": "replica",
200-
"server_version": 150004,
200+
"server_version": 160004,
201201
"xlog": {
202202
"location": 67420024
203203
},
@@ -228,7 +228,7 @@ The ``GET /patroni`` is used by Patroni during the leader race. It also could be
228228
},
229229
"database_system_identifier": "7268616322854375442",
230230
"patroni": {
231-
"version": "3.1.0",
231+
"version": "4.0.0",
232232
"scope": "demo",
233233
"name": "patroni1"
234234
}
@@ -241,9 +241,9 @@ The ``GET /patroni`` is used by Patroni during the leader race. It also could be
241241
$ curl -s http://localhost:8008/patroni | jq .
242242
{
243243
"state": "running",
244-
"postmaster_start_time": "2023-08-18 11:09:08.615242+00:00",
244+
"postmaster_start_time": "2024-08-18 11:09:08.615242+00:00",
245245
"role": "replica",
246-
"server_version": 150004,
246+
"server_version": 160004,
247247
"xlog": {
248248
"location": 67420024
249249
},
@@ -273,7 +273,7 @@ The ``GET /patroni`` is used by Patroni during the leader race. It also could be
273273
},
274274
"database_system_identifier": "7268616322854375442",
275275
"patroni": {
276-
"version": "3.1.0",
276+
"version": "4.0.0",
277277
"scope": "demo",
278278
"name": "patroni1"
279279
}
@@ -287,16 +287,13 @@ Retrieve the Patroni metrics in Prometheus format through the ``GET /metrics`` e
287287
288288
# HELP patroni_version Patroni semver without periods. \
289289
# TYPE patroni_version gauge
290-
patroni_version{scope="batman",name="patroni1"} 020103
290+
patroni_version{scope="batman",name="patroni1"} 040000
291291
# HELP patroni_postgres_running Value is 1 if Postgres is running, 0 otherwise.
292292
# TYPE patroni_postgres_running gauge
293293
patroni_postgres_running{scope="batman",name="patroni1"} 1
294294
# HELP patroni_postmaster_start_time Epoch seconds since Postgres started.
295295
# TYPE patroni_postmaster_start_time gauge
296296
patroni_postmaster_start_time{scope="batman",name="patroni1"} 1657656955.179243
297-
# HELP patroni_master Value is 1 if this node is the leader, 0 otherwise.
298-
# TYPE patroni_master gauge
299-
patroni_master{scope="batman",name="patroni1"} 1
300297
# HELP patroni_primary Value is 1 if this node is the leader, 0 otherwise.
301298
# TYPE patroni_primary gauge
302299
patroni_primary{scope="batman",name="patroni1"} 1
@@ -335,7 +332,7 @@ Retrieve the Patroni metrics in Prometheus format through the ``GET /metrics`` e
335332
patroni_postgres_in_archive_recovery{scope="batman",name="patroni1"} 0
336333
# HELP patroni_postgres_server_version Version of Postgres (if running), 0 otherwise.
337334
# TYPE patroni_postgres_server_version gauge
338-
patroni_postgres_server_version{scope="batman",name="patroni1"} 140004
335+
patroni_postgres_server_version{scope="batman",name="patroni1"} 160004
339336
# HELP patroni_cluster_unlocked Value is 1 if the cluster is unlocked, 0 if locked.
340337
# TYPE patroni_cluster_unlocked gauge
341338
patroni_cluster_unlocked{scope="batman",name="patroni1"} 0
@@ -497,18 +494,18 @@ Let's check that the node processed this configuration. First of all it should s
497494
{
498495
"pending_restart": true,
499496
"database_system_identifier": "6287881213849985952",
500-
"postmaster_start_time": "2016-06-13 13:13:05.211 CEST",
497+
"postmaster_start_time": "2024-08-18 13:13:05.211 CEST",
501498
"xlog": {
502499
"location": 2197818976
503500
},
504501
"patroni": {
505-
"version": "1.0",
502+
"version": "4.0.0",
506503
"scope": "batman",
507504
"name": "patroni1"
508505
},
509506
"state": "running",
510-
"role": "master",
511-
"server_version": 90503
507+
"role": "primary",
508+
"server_version": 160004
512509
}
513510
514511
Removing parameters:

docs/yaml_configuration.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Most of the parameters are optional, but you have to specify one of the **host**
104104
- **consistency**: (optional) Select consul consistency mode. Possible values are ``default``, ``consistent``, or ``stale`` (more details in `consul API reference <https://www.consul.io/api/features/consistency.html/>`__)
105105
- **checks**: (optional) list of Consul health checks used for the session. By default an empty list is used.
106106
- **register\_service**: (optional) whether or not to register a service with the name defined by the scope parameter and the tag master, primary, replica, or standby-leader depending on the node's role. Defaults to **false**.
107-
- **service\_tags**: (optional) additional static tags to add to the Consul service apart from the role (``master``/``primary``/``replica``/``standby-leader``). By default an empty list is used.
107+
- **service\_tags**: (optional) additional static tags to add to the Consul service apart from the role (``primary``/``replica``/``standby-leader``). By default an empty list is used.
108108
- **service\_check\_interval**: (optional) how often to perform health check against registered url. Defaults to '5s'.
109109
- **service\_check\_tls\_server\_name**: (optional) overide SNI host when connecting via TLS, see also `consul agent check API reference <https://www.consul.io/api-docs/agent/check#tlsservername>`__.
110110

@@ -178,11 +178,11 @@ Kubernetes
178178
- **namespace**: (optional) Kubernetes namespace where Patroni pod is running. Default value is `default`.
179179
- **labels**: Labels in format ``{label1: value1, label2: value2}``. These labels will be used to find existing objects (Pods and either Endpoints or ConfigMaps) associated with the current cluster. Also Patroni will set them on every object (Endpoint or ConfigMap) it creates.
180180
- **scope\_label**: (optional) name of the label containing cluster name. Default value is `cluster-name`.
181-
- **role\_label**: (optional) name of the label containing role (master or replica or other custom value). Patroni will set this label on the pod it runs in. Default value is ``role``.
182-
- **leader\_label\_value**: (optional) value of the pod label when Postgres role is ``master``. Default value is ``master``.
181+
- **role\_label**: (optional) name of the label containing role (`primary`, `replica`, or other custom value). Patroni will set this label on the pod it runs in. Default value is ``role``.
182+
- **leader\_label\_value**: (optional) value of the pod label when Postgres role is ``primary``. Default value is ``primary``.
183183
- **follower\_label\_value**: (optional) value of the pod label when Postgres role is ``replica``. Default value is ``replica``.
184-
- **standby\_leader\_label\_value**: (optional) value of the pod label when Postgres role is ``standby_leader``. Default value is ``master``.
185-
- **tmp_\role\_label**: (optional) name of the temporary label containing role (master or replica). Value of this label will always use the default of corresponding role. Set only when necessary.
184+
- **standby\_leader\_label\_value**: (optional) value of the pod label when Postgres role is ``standby_leader``. Default value is ``primary``.
185+
- **tmp_\role\_label**: (optional) name of the temporary label containing role (`primary` or `replica`). Value of this label will always use the default of corresponding role. Set only when necessary.
186186
- **use\_endpoints**: (optional) if set to true, Patroni will use Endpoints instead of ConfigMaps to run leader elections and keep cluster state.
187187
- **pod\_ip**: (optional) IP address of the pod Patroni is running in. This value is required when `use_endpoints` is enabled and is used to populate the leader endpoint subsets when the pod's PostgreSQL is promoted.
188188
- **ports**: (optional) if the Service object has the name for the port, the same name must appear in the Endpoint object, otherwise service won't work. For example, if your service is defined as ``{Kind: Service, spec: {ports: [{name: postgresql, port: 5432, targetPort: 5432}]}}``, then you have to set ``kubernetes.ports: [{"name": "postgresql", "port": 5432}]`` and Patroni will use it for updating subsets of the leader Endpoint. This parameter is used only if `kubernetes.use_endpoints` is set.

features/basic_replication.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Feature: basic replication
6565
Then I receive a response returncode 0
6666
And postgres2 role is the primary after 24 seconds
6767
And Response on GET http://127.0.0.1:8010/history contains recovery after 10 seconds
68-
And there is a postgres2_cb.log with "on_role_change master batman" in postgres2 data directory
68+
And there is a postgres2_cb.log with "on_role_change primary batman" in postgres2 data directory
6969
When I issue a PATCH request to http://127.0.0.1:8010/config with {"synchronous_mode": null, "master_start_timeout": 0}
7070
Then I receive a response code 200
7171
When I add the table bar to postgres2

features/citus.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Feature: citus
6969
Scenario: check that in-flight transaction is rolled back after timeout when other workers need to change pg_dist_node
7070
Given I start postgres4 in citus group 2
7171
Then postgres4 is a leader in a group 2 after 10 seconds
72-
And "members/postgres4" key in a group 2 in DCS has role=master after 3 seconds
72+
And "members/postgres4" key in a group 2 in DCS has role=primary after 3 seconds
7373
When I run patronictl.py edit-config batman --group 2 -s ttl=20 --force
7474
Then I receive a response returncode 0
7575
And I receive a response output "+ttl: 20"

0 commit comments

Comments
 (0)