From f798abaf673859dfaf2266b7941b24e8878598c2 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 27 Jan 2022 12:13:24 -0800 Subject: [PATCH 01/16] make using cache expiry the default behavior --- synapse/config/cache.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/synapse/config/cache.py b/synapse/config/cache.py index d9d85f98e155..66179a9c5dc7 100644 --- a/synapse/config/cache.py +++ b/synapse/config/cache.py @@ -152,7 +152,7 @@ def generate_config_section(self, **kwargs) -> str: # accessed before being evicted. Defaults to None, which means # entries are never evicted based on time. # - #expiry_time: 30m + expiry_time: 30m # Controls how long the results of a /sync request are cached for after # a successful response is returned. A higher duration can help clients with From adbd8edd10f3bb01dc86e9f429c1452f141bb55a Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 27 Jan 2022 12:18:08 -0800 Subject: [PATCH 02/16] newsfragment --- changelog.d/11848.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/11848.misc diff --git a/changelog.d/11848.misc b/changelog.d/11848.misc new file mode 100644 index 000000000000..b3dfa3a8d3cf --- /dev/null +++ b/changelog.d/11848.misc @@ -0,0 +1 @@ +Enable cache time-based expiry by default. From bdeaf52c865f218072a50c601b4051bd18507d5c Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 27 Jan 2022 12:35:25 -0800 Subject: [PATCH 03/16] update comment --- synapse/config/cache.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse/config/cache.py b/synapse/config/cache.py index 66179a9c5dc7..93528bc60736 100644 --- a/synapse/config/cache.py +++ b/synapse/config/cache.py @@ -149,8 +149,8 @@ def generate_config_section(self, **kwargs) -> str: #get_users_who_share_room_with_user: 2.0 # Controls how long an entry can be in a cache without having been - # accessed before being evicted. Defaults to None, which means - # entries are never evicted based on time. + # accessed before being evicted. Defaults to 30m. Comment out this + # option if you don't want entries to be evicted based on time. # expiry_time: 30m From 83661c5df59e69bd77e1d07d88bb05a96c531388 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 27 Jan 2022 14:38:14 -0800 Subject: [PATCH 04/16] newsfragment and update sample config --- changelog.d/{11848.misc => 11849.misc} | 0 docs/sample_config.yaml | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) rename changelog.d/{11848.misc => 11849.misc} (100%) diff --git a/changelog.d/11848.misc b/changelog.d/11849.misc similarity index 100% rename from changelog.d/11848.misc rename to changelog.d/11849.misc diff --git a/docs/sample_config.yaml b/docs/sample_config.yaml index abf28e449089..bf1ff9b00a60 100644 --- a/docs/sample_config.yaml +++ b/docs/sample_config.yaml @@ -738,10 +738,10 @@ caches: #get_users_who_share_room_with_user: 2.0 # Controls how long an entry can be in a cache without having been - # accessed before being evicted. Defaults to None, which means - # entries are never evicted based on time. + # accessed before being evicted. Defaults to 30m. Comment out this + # option if you don't want entries to be evicted based on time. # - #expiry_time: 30m + expiry_time: 30m # Controls how long the results of a /sync request are cached for after # a successful response is returned. A higher duration can help clients with From 4eb3e6af32e824f969c4f3bb69bfdbb8d2c46049 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 3 Feb 2022 13:45:39 -0800 Subject: [PATCH 05/16] add boolean flag, rename expiry time --- synapse/config/cache.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/synapse/config/cache.py b/synapse/config/cache.py index 93528bc60736..2a199a028877 100644 --- a/synapse/config/cache.py +++ b/synapse/config/cache.py @@ -148,11 +148,15 @@ def generate_config_section(self, **kwargs) -> str: per_cache_factors: #get_users_who_share_room_with_user: 2.0 - # Controls how long an entry can be in a cache without having been - # accessed before being evicted. Defaults to 30m. Comment out this - # option if you don't want entries to be evicted based on time. + # Controls whether cache entries are evicted after a specified time + # period. Defaults to true. + # expire_caches: false + + # If expire_caches is enabled, this flag controls how long an entry can + # be in a cache without having been accessed before being evicted. + # Defaults to 30m. Uncomment to set a different time to live for cache entries. # - expiry_time: 30m + # cache_entry_ttl: 30m # Controls how long the results of a /sync request are cached for after # a successful response is returned. A higher duration can help clients with @@ -217,9 +221,16 @@ def read_config(self, config, **kwargs) -> None: e.message # noqa: B306, DependencyException.message is a property ) - expiry_time = cache_config.get("expiry_time") - if expiry_time: - self.expiry_time_msec: Optional[int] = self.parse_duration(expiry_time) + expire_caches = cache_config.get("expire_caches", True) + cache_entry_ttl = cache_config.get("cache_entry_ttl") + + if expire_caches: + if cache_entry_ttl: + self.expiry_time_msec: Optional[int] = self.parse_duration( + cache_entry_ttl + ) + else: + self.expiry_time_msec = 1800000 else: self.expiry_time_msec = None From 652c620a8d9575dcc923e0719301ed39b2a92fd7 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 3 Feb 2022 13:54:07 -0800 Subject: [PATCH 06/16] regenerate sample config --- docs/sample_config.yaml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/sample_config.yaml b/docs/sample_config.yaml index bf1ff9b00a60..1ef420d6b056 100644 --- a/docs/sample_config.yaml +++ b/docs/sample_config.yaml @@ -737,11 +737,15 @@ caches: per_cache_factors: #get_users_who_share_room_with_user: 2.0 - # Controls how long an entry can be in a cache without having been - # accessed before being evicted. Defaults to 30m. Comment out this - # option if you don't want entries to be evicted based on time. + # Controls whether cache entries are evicted after a specified time + # period. Defaults to true. + # expire_caches: false + + # If expire_caches is enabled, this flag controls how long an entry can + # be in a cache without having been accessed before being evicted. + # Defaults to 30m. Uncomment to set a different time to live for cache entries. # - expiry_time: 30m + # cache_entry_ttl: 30m # Controls how long the results of a /sync request are cached for after # a successful response is returned. A higher duration can help clients with From 6784e1eb1f11ef1d43146798acab74eb6866ea19 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Fri, 4 Feb 2022 10:26:36 -0800 Subject: [PATCH 07/16] requested changes --- synapse/config/cache.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/synapse/config/cache.py b/synapse/config/cache.py index 2a199a028877..0ff546e96266 100644 --- a/synapse/config/cache.py +++ b/synapse/config/cache.py @@ -149,7 +149,7 @@ def generate_config_section(self, **kwargs) -> str: #get_users_who_share_room_with_user: 2.0 # Controls whether cache entries are evicted after a specified time - # period. Defaults to true. + # period. Defaults to true. Uncomment to disable this feature. # expire_caches: false # If expire_caches is enabled, this flag controls how long an entry can @@ -222,18 +222,22 @@ def read_config(self, config, **kwargs) -> None: ) expire_caches = cache_config.get("expire_caches", True) - cache_entry_ttl = cache_config.get("cache_entry_ttl") + cache_entry_ttl = cache_config.get("cache_entry_ttl", "30m") if expire_caches: - if cache_entry_ttl: - self.expiry_time_msec: Optional[int] = self.parse_duration( + self.expiry_time_msec: Optional[int] = self.parse_duration( cache_entry_ttl - ) - else: - self.expiry_time_msec = 1800000 + ) else: self.expiry_time_msec = None + # Backwards compatibility support for the now-removed "expiry_time" config flag. + expiry_time = cache_config.get("expiry_time") + if expiry_time: + self.expiry_time_msec = Optional[int] = self.parse_duration( + expiry_time + ) + self.sync_response_cache_duration = self.parse_duration( cache_config.get("sync_response_cache_duration", 0) ) From 775cbf70fe631c9289704b24245915a2583395ca Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Fri, 4 Feb 2022 10:43:15 -0800 Subject: [PATCH 08/16] add note in upgrade notes about changes --- docs/upgrade.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/upgrade.md b/docs/upgrade.md index 8ce37bcdee4f..6783a0d8d1f5 100644 --- a/docs/upgrade.md +++ b/docs/upgrade.md @@ -86,6 +86,13 @@ process, for example: ``` # Upgrading to v1.(next) +## Time-based cache expiry is now enabled by default + +Formerly, entries in the cache were not evicted regardless of whether they were accessed after storing. +This behavior has now changed. By default entries in the cache are now evicted after 30m of not being accessed. +To change the default behavior, go to the `caches` section of the config and change the `expire_caches` and +`cache_entry_ttl` flags as necessary. Please note that these flags replace the `expiry_time` flag in the config. + ## Stablisation of MSC3231 The unstable validity-check endpoint for the From 6dddbc70e451b4f292201a61f7dbe3ef9f66f83e Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Fri, 4 Feb 2022 10:46:07 -0800 Subject: [PATCH 09/16] lint --- synapse/config/cache.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/synapse/config/cache.py b/synapse/config/cache.py index 0ff546e96266..0e7152cc4817 100644 --- a/synapse/config/cache.py +++ b/synapse/config/cache.py @@ -225,18 +225,14 @@ def read_config(self, config, **kwargs) -> None: cache_entry_ttl = cache_config.get("cache_entry_ttl", "30m") if expire_caches: - self.expiry_time_msec: Optional[int] = self.parse_duration( - cache_entry_ttl - ) + self.expiry_time_msec: Optional[int] = self.parse_duration(cache_entry_ttl) else: self.expiry_time_msec = None # Backwards compatibility support for the now-removed "expiry_time" config flag. expiry_time = cache_config.get("expiry_time") if expiry_time: - self.expiry_time_msec = Optional[int] = self.parse_duration( - expiry_time - ) + self.expiry_time_msec = self.parse_duration(expiry_time) self.sync_response_cache_duration = self.parse_duration( cache_config.get("sync_response_cache_duration", 0) From 8efac83f42049957d5502dd9250e6706657d0c04 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Fri, 4 Feb 2022 10:52:46 -0800 Subject: [PATCH 10/16] renew sample config --- docs/sample_config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sample_config.yaml b/docs/sample_config.yaml index 6c635fca821b..b009ccc3f959 100644 --- a/docs/sample_config.yaml +++ b/docs/sample_config.yaml @@ -752,7 +752,7 @@ caches: #get_users_who_share_room_with_user: 2.0 # Controls whether cache entries are evicted after a specified time - # period. Defaults to true. + # period. Defaults to true. Uncomment to disable this feature. # expire_caches: false # If expire_caches is enabled, this flag controls how long an entry can From c86e536d6d223afd1783a7d15c5377d0e6514aba Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Wed, 9 Feb 2022 11:46:01 -0800 Subject: [PATCH 11/16] follow config code style --- synapse/config/background_updates.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 synapse/config/background_updates.py diff --git a/synapse/config/background_updates.py b/synapse/config/background_updates.py new file mode 100644 index 000000000000..e69de29bb2d1 From 327ea5ac3a35bc3fd362a36196251b5375b7ff09 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Wed, 9 Feb 2022 11:46:20 -0800 Subject: [PATCH 12/16] follow config code style --- synapse/config/cache.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/synapse/config/cache.py b/synapse/config/cache.py index 0e7152cc4817..1fd0be18d014 100644 --- a/synapse/config/cache.py +++ b/synapse/config/cache.py @@ -150,13 +150,14 @@ def generate_config_section(self, **kwargs) -> str: # Controls whether cache entries are evicted after a specified time # period. Defaults to true. Uncomment to disable this feature. - # expire_caches: false + # + #expire_caches: false # If expire_caches is enabled, this flag controls how long an entry can # be in a cache without having been accessed before being evicted. # Defaults to 30m. Uncomment to set a different time to live for cache entries. # - # cache_entry_ttl: 30m + #cache_entry_ttl: 30m # Controls how long the results of a /sync request are cached for after # a successful response is returned. A higher duration can help clients with From 8d06aac43b9dc8f866dfb62290adaac5c56e41ae Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Wed, 9 Feb 2022 11:46:48 -0800 Subject: [PATCH 13/16] regenerate sample config --- docs/sample_config.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/sample_config.yaml b/docs/sample_config.yaml index b009ccc3f959..d2bb3d42080a 100644 --- a/docs/sample_config.yaml +++ b/docs/sample_config.yaml @@ -753,13 +753,14 @@ caches: # Controls whether cache entries are evicted after a specified time # period. Defaults to true. Uncomment to disable this feature. - # expire_caches: false + # + #expire_caches: false # If expire_caches is enabled, this flag controls how long an entry can # be in a cache without having been accessed before being evicted. # Defaults to 30m. Uncomment to set a different time to live for cache entries. # - # cache_entry_ttl: 30m + #cache_entry_ttl: 30m # Controls how long the results of a /sync request are cached for after # a successful response is returned. A higher duration can help clients with From f37e95f65c4b9706600364915bccfd78241553b4 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 10 Feb 2022 11:30:59 -0800 Subject: [PATCH 14/16] requested changes --- changelog.d/11849.misc | 2 +- docs/upgrade.md | 14 ++++++++------ synapse/config/cache.py | 11 +++++++++++ 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/changelog.d/11849.misc b/changelog.d/11849.misc index b3dfa3a8d3cf..9561eab1927c 100644 --- a/changelog.d/11849.misc +++ b/changelog.d/11849.misc @@ -1 +1 @@ -Enable cache time-based expiry by default. +Enable cache time-based expiry by default. The `expiry_time` config flag will be superseded by `expire_caches` and `cache_entry_ttl`. diff --git a/docs/upgrade.md b/docs/upgrade.md index 6783a0d8d1f5..55c38111313a 100644 --- a/docs/upgrade.md +++ b/docs/upgrade.md @@ -86,12 +86,6 @@ process, for example: ``` # Upgrading to v1.(next) -## Time-based cache expiry is now enabled by default - -Formerly, entries in the cache were not evicted regardless of whether they were accessed after storing. -This behavior has now changed. By default entries in the cache are now evicted after 30m of not being accessed. -To change the default behavior, go to the `caches` section of the config and change the `expire_caches` and -`cache_entry_ttl` flags as necessary. Please note that these flags replace the `expiry_time` flag in the config. ## Stablisation of MSC3231 @@ -109,6 +103,14 @@ Please update any relevant reverse proxy or firewall configurations appropriatel # Upgrading to v1.53.0 +## Time-based cache expiry is now enabled by default + +Formerly, entries in the cache were not evicted regardless of whether they were accessed after storing. +This behavior has now changed. By default entries in the cache are now evicted after 30m of not being accessed. +To change the default behavior, go to the `caches` section of the config and change the `expire_caches` and +`cache_entry_ttl` flags as necessary. Please note that these flags replace the `expiry_time` flag in the config. + + ## Dropping support for `webclient` listeners and non-HTTP(S) `web_client_location` Per the deprecation notice in Synapse v1.51.0, listeners of type `webclient` diff --git a/synapse/config/cache.py b/synapse/config/cache.py index 1fd0be18d014..85827a84130a 100644 --- a/synapse/config/cache.py +++ b/synapse/config/cache.py @@ -15,6 +15,8 @@ import os import re import threading +import logging + from typing import Callable, Dict, Optional import attr @@ -23,6 +25,8 @@ from ._base import Config, ConfigError +logger = logging.getLogger(__name__) + # The prefix for all cache factor-related environment variables _CACHE_PREFIX = "SYNAPSE_CACHE_FACTOR" @@ -232,7 +236,14 @@ def read_config(self, config, **kwargs) -> None: # Backwards compatibility support for the now-removed "expiry_time" config flag. expiry_time = cache_config.get("expiry_time") + + if expiry_time and expire_caches: + logger.warning("You have set two incompatible flags, expiry_time and expire_caches. Please only use the " + "expire_caches and cache_entry_ttl flags and delete the expiry_time flag as it is " + "deprecated.") if expiry_time: + logger.warning("Expiry_time is a deprecated flag, please use the expire_caches and cache_entry_ttl flags " + "instead.") self.expiry_time_msec = self.parse_duration(expiry_time) self.sync_response_cache_duration = self.parse_duration( From 3299583570f329f23ff40f205106b2b88f34d013 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Thu, 10 Feb 2022 11:31:56 -0800 Subject: [PATCH 15/16] d'oh! lints --- synapse/config/cache.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/synapse/config/cache.py b/synapse/config/cache.py index 85827a84130a..008aa7e46644 100644 --- a/synapse/config/cache.py +++ b/synapse/config/cache.py @@ -12,11 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging import os import re import threading -import logging - from typing import Callable, Dict, Optional import attr @@ -238,12 +237,16 @@ def read_config(self, config, **kwargs) -> None: expiry_time = cache_config.get("expiry_time") if expiry_time and expire_caches: - logger.warning("You have set two incompatible flags, expiry_time and expire_caches. Please only use the " - "expire_caches and cache_entry_ttl flags and delete the expiry_time flag as it is " - "deprecated.") + logger.warning( + "You have set two incompatible flags, expiry_time and expire_caches. Please only use the " + "expire_caches and cache_entry_ttl flags and delete the expiry_time flag as it is " + "deprecated." + ) if expiry_time: - logger.warning("Expiry_time is a deprecated flag, please use the expire_caches and cache_entry_ttl flags " - "instead.") + logger.warning( + "Expiry_time is a deprecated flag, please use the expire_caches and cache_entry_ttl flags " + "instead." + ) self.expiry_time_msec = self.parse_duration(expiry_time) self.sync_response_cache_duration = self.parse_duration( From 77ac0d70d653a87e01d2fc02deb2a095e5e0b4b5 Mon Sep 17 00:00:00 2001 From: "H. Shay" Date: Fri, 11 Feb 2022 09:05:08 -0800 Subject: [PATCH 16/16] cleanup v1 header and reword flags --- docs/upgrade.md | 6 +++--- synapse/config/cache.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/upgrade.md b/docs/upgrade.md index 55c38111313a..20e878434513 100644 --- a/docs/upgrade.md +++ b/docs/upgrade.md @@ -84,9 +84,11 @@ process, for example: wget https://packages.matrix.org/debian/pool/main/m/matrix-synapse-py3/matrix-synapse-py3_1.3.0+stretch1_amd64.deb dpkg -i matrix-synapse-py3_1.3.0+stretch1_amd64.deb ``` -# Upgrading to v1.(next) + +# Upgrading to v1.53.0 + ## Stablisation of MSC3231 The unstable validity-check endpoint for the @@ -101,8 +103,6 @@ to: Please update any relevant reverse proxy or firewall configurations appropriately. -# Upgrading to v1.53.0 - ## Time-based cache expiry is now enabled by default Formerly, entries in the cache were not evicted regardless of whether they were accessed after storing. diff --git a/synapse/config/cache.py b/synapse/config/cache.py index 008aa7e46644..387ac6d115e3 100644 --- a/synapse/config/cache.py +++ b/synapse/config/cache.py @@ -238,13 +238,13 @@ def read_config(self, config, **kwargs) -> None: if expiry_time and expire_caches: logger.warning( - "You have set two incompatible flags, expiry_time and expire_caches. Please only use the " - "expire_caches and cache_entry_ttl flags and delete the expiry_time flag as it is " + "You have set two incompatible options, expiry_time and expire_caches. Please only use the " + "expire_caches and cache_entry_ttl options and delete the expiry_time option as it is " "deprecated." ) if expiry_time: logger.warning( - "Expiry_time is a deprecated flag, please use the expire_caches and cache_entry_ttl flags " + "Expiry_time is a deprecated option, please use the expire_caches and cache_entry_ttl options " "instead." ) self.expiry_time_msec = self.parse_duration(expiry_time)