diff --git a/docs/SETTINGS.rst b/docs/SETTINGS.rst index 7a2ed244..74a5e2b7 100644 --- a/docs/SETTINGS.rst +++ b/docs/SETTINGS.rst @@ -15,6 +15,7 @@ Dynamic configuration is stored in the DCS (Distributed Configuration Store) and - **ttl**: the TTL to acquire the leader lock (in seconds). Think of it as the length of time before initiation of the automatic failover process. Default value: 30 - **retry\_timeout**: timeout for DCS and PostgreSQL operation retries (in seconds). DCS or network issues shorter than this will not cause Patroni to demote the leader. Default value: 10 - **maximum\_lag\_on\_failover**: the maximum bytes a follower may lag to be able to participate in leader election. +- **max\_timelines\_history**: maximum number of timeline history items kept in DCS. Default value: 0. When set to 0, it keeps the full history in DCS. - **master\_start\_timeout**: the amount of time a master is allowed to recover from failures before failover is triggered (in seconds). Default is 300 seconds. When set to 0 failover is done immediately after a crash is detected if possible. When using asynchronous replication a failover can cause lost transactions. Worst case failover time for master failure is: loop\_wait + master\_start\_timeout + loop\_wait, unless master\_start\_timeout is zero, in which case it's just loop\_wait. Set the value according to your durability/availability tradeoff. - **master\_stop\_timeout**: The number of seconds Patroni is allowed to wait when stopping Postgres and effective only when synchronous_mode is enabled. When set to > 0 and the synchronous_mode is enabled, Patroni sends SIGKILL to the postmaster if the stop operation is running for more than the value set by master_stop_timeout. Set the value according to your durability/availability tradeoff. If the parameter is not set or set <= 0, master_stop_timeout does not apply. - **synchronous\_mode**: turns on synchronous replication mode. In this mode a replica will be chosen as synchronous and only the latest leader and synchronous replica are able to participate in leader election. Synchronous mode makes sure that successfully committed transactions will not be lost at failover, at the cost of losing availability for writes when Patroni cannot ensure transaction durability. See :ref:`replication modes documentation ` for details. diff --git a/docs/dynamic_configuration.rst b/docs/dynamic_configuration.rst index 85c7cb1d..6f350b18 100644 --- a/docs/dynamic_configuration.rst +++ b/docs/dynamic_configuration.rst @@ -76,6 +76,7 @@ Also, the following Patroni configuration options can be changed only dynamicall - loop_wait: 10 - retry_timeouts: 10 - maximum_lag_on_failover: 1048576 +- max_timelines_history: 0 - check_timeline: false - postgresql.use_slots: true diff --git a/patroni/dcs/__init__.py b/patroni/dcs/__init__.py index 946a65e5..193b7fe1 100644 --- a/patroni/dcs/__init__.py +++ b/patroni/dcs/__init__.py @@ -341,6 +341,10 @@ class ClusterConfig(namedtuple('ClusterConfig', 'index,data,modify_index')): self.data.get('permanent_slots') or self.data.get('slots') ) or {} + @property + def max_timelines_history(self): + return self.data.get('max_timelines_history', 0) + class SyncState(namedtuple('SyncState', 'index,leader,sync_standby')): """Immutable object (namedtuple) which represents last observed synhcronous replication state diff --git a/patroni/ha.py b/patroni/ha.py index bdc943e4..4ef19fe4 100644 --- a/patroni/ha.py +++ b/patroni/ha.py @@ -526,6 +526,7 @@ class Ha(object): cluster_history = {l[0]: l for l in cluster_history or []} history = self.state_handler.get_history(master_timeline) if history: + history = history[-self.cluster.config.max_timelines_history:] for line in history: # enrich current history with promotion timestamps stored in DCS if len(line) == 3 and line[0] in cluster_history \