From 0dae7d80bfb497d417a53e52b8353bbcd6d10d58 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Mon, 7 Sep 2020 13:36:02 +0100 Subject: Add more logging to debug slow startup (#8264) I'm hoping this will provide some pointers for debugging https://github.com/matrix-org/synapse/issues/7968. --- synapse/storage/databases/main/__init__.py | 1 + 1 file changed, 1 insertion(+) (limited to 'synapse/storage/databases/main') diff --git a/synapse/storage/databases/main/__init__.py b/synapse/storage/databases/main/__init__.py index 99890ffbf3..b315ae66d2 100644 --- a/synapse/storage/databases/main/__init__.py +++ b/synapse/storage/databases/main/__init__.py @@ -591,6 +591,7 @@ def check_database_before_upgrade(cur, database_engine, config: HomeServerConfig """Called before upgrading an existing database to check that it is broadly sane compared with the configuration. """ + logger.info("Running sanity-checks on database...") domain = config.server_name sql = database_engine.convert_param_style( -- cgit 1.4.1 From a55e2707d73c19b555c18ebc19df3170a96055e2 Mon Sep 17 00:00:00 2001 From: Brendan Abolivier Date: Mon, 7 Sep 2020 15:15:06 +0100 Subject: Fix unread count failing on NULL values (#8270) Fix unread counts making sync fail if the value of the `unread_count` column in `event_push_summary` is `None`. --- changelog.d/8270.feature | 1 + synapse/storage/databases/main/event_push_actions.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelog.d/8270.feature (limited to 'synapse/storage/databases/main') diff --git a/changelog.d/8270.feature b/changelog.d/8270.feature new file mode 100644 index 0000000000..feb02be234 --- /dev/null +++ b/changelog.d/8270.feature @@ -0,0 +1 @@ +Add unread messages count to sync responses, as specified in [MSC2654](https://github.com/matrix-org/matrix-doc/pull/2654). diff --git a/synapse/storage/databases/main/event_push_actions.py b/synapse/storage/databases/main/event_push_actions.py index 001d06378d..50fac9e72e 100644 --- a/synapse/storage/databases/main/event_push_actions.py +++ b/synapse/storage/databases/main/event_push_actions.py @@ -177,7 +177,12 @@ class EventPushActionsWorkerStore(SQLBaseStore): if row: notif_count += row[0] - unread_count += row[1] + + if row[1] is not None: + # The unread_count column of event_push_summary is NULLable, so we need + # to make sure we don't try increasing the unread counts if it's NULL + # for this row. + unread_count += row[1] return { "notify_count": notif_count, -- cgit 1.4.1 From ef2804d27c766595f9eae134422652d1d32df9a6 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Mon, 7 Sep 2020 16:48:52 +0100 Subject: Avoid table-scanning users at startup (#8271) This takes about 10 seconds in the best case; often more. --- changelog.d/8271.bugfix | 1 + synapse/storage/databases/main/__init__.py | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 changelog.d/8271.bugfix (limited to 'synapse/storage/databases/main') diff --git a/changelog.d/8271.bugfix b/changelog.d/8271.bugfix new file mode 100644 index 0000000000..b75f07b03c --- /dev/null +++ b/changelog.d/8271.bugfix @@ -0,0 +1 @@ +Fix slow start times for large servers by removing a table scan of the `users` table from startup code. diff --git a/synapse/storage/databases/main/__init__.py b/synapse/storage/databases/main/__init__.py index b315ae66d2..2ae2fbd5d7 100644 --- a/synapse/storage/databases/main/__init__.py +++ b/synapse/storage/databases/main/__init__.py @@ -29,6 +29,7 @@ from synapse.storage.util.id_generators import ( MultiWriterIdGenerator, StreamIdGenerator, ) +from synapse.types import get_domain_from_id from synapse.util.caches.stream_change_cache import StreamChangeCache from .account_data import AccountDataStore @@ -591,22 +592,24 @@ def check_database_before_upgrade(cur, database_engine, config: HomeServerConfig """Called before upgrading an existing database to check that it is broadly sane compared with the configuration. """ - logger.info("Running sanity-checks on database...") - domain = config.server_name + logger.info("Checking database for consistency with configuration...") - sql = database_engine.convert_param_style( - "SELECT COUNT(*) FROM users WHERE name NOT LIKE ?" - ) - pat = "%:" + domain - cur.execute(sql, (pat,)) - num_not_matching = cur.fetchall()[0][0] - if num_not_matching == 0: + # if there are any users in the database, check that the username matches our + # configured server name. + + cur.execute("SELECT name FROM users LIMIT 1") + rows = cur.fetchall() + if not rows: + return + + user_domain = get_domain_from_id(rows[0][0]) + if user_domain == config.server_name: return raise Exception( "Found users in database not native to %s!\n" - "You cannot changed a synapse server_name after it's been configured" - % (domain,) + "You cannot change a synapse server_name after it's been configured" + % (config.server_name,) ) -- cgit 1.4.1