Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 68cdb37

Browse files
Rename 'populate_stats_process_rooms_2' background job back to 'populate_stats_process_rooms' again (#8243)
Fixes #8238 Alongside the delta file, some changes were also necessary to the codebase to remove references to the now defunct `populate_stats_process_rooms_2` background job. Thankfully the latter doesn't seem to have made it into any documentation yet :)
1 parent 8d6f97f commit 68cdb37

File tree

4 files changed

+35
-39
lines changed

4 files changed

+35
-39
lines changed

changelog.d/8243.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove the 'populate_stats_process_rooms_2' background job and restore functionality to 'populate_stats_process_rooms'.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* Copyright 2020 The Matrix.org Foundation C.I.C.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
-- This delta file fixes a regression introduced by 58/12room_stats.sql, removing the hacky
16+
-- populate_stats_process_rooms_2 background job and restores the functionality under the
17+
-- original name.
18+
-- See https://github.com/matrix-org/synapse/issues/8238 for details
19+
20+
DELETE FROM background_updates WHERE update_name = 'populate_stats_process_rooms';
21+
UPDATE background_updates SET update_name = 'populate_stats_process_rooms'
22+
WHERE update_name = 'populate_stats_process_rooms_2';

synapse/storage/databases/main/stats.py

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ def __init__(self, database: DatabasePool, db_conn, hs):
7373
self.db_pool.updates.register_background_update_handler(
7474
"populate_stats_process_rooms", self._populate_stats_process_rooms
7575
)
76-
self.db_pool.updates.register_background_update_handler(
77-
"populate_stats_process_rooms_2", self._populate_stats_process_rooms_2
78-
)
7976
self.db_pool.updates.register_background_update_handler(
8077
"populate_stats_process_users", self._populate_stats_process_users
8178
)
@@ -148,31 +145,10 @@ def _get_next_batch(txn):
148145
return len(users_to_work_on)
149146

150147
async def _populate_stats_process_rooms(self, progress, batch_size):
151-
"""
152-
This was a background update which regenerated statistics for rooms.
153-
154-
It has been replaced by StatsStore._populate_stats_process_rooms_2. This background
155-
job has been scheduled to run as part of Synapse v1.0.0, and again now. To ensure
156-
someone upgrading from <v1.0.0, this background task has been turned into a no-op
157-
so that the potentially expensive task is not run twice.
158-
159-
Further context: https://github.com/matrix-org/synapse/pull/7977
160-
"""
161-
await self.db_pool.updates._end_background_update(
162-
"populate_stats_process_rooms"
163-
)
164-
return 1
165-
166-
async def _populate_stats_process_rooms_2(self, progress, batch_size):
167-
"""
168-
This is a background update which regenerates statistics for rooms.
169-
170-
It replaces StatsStore._populate_stats_process_rooms. See its docstring for the
171-
reasoning.
172-
"""
148+
"""This is a background update which regenerates statistics for rooms."""
173149
if not self.stats_enabled:
174150
await self.db_pool.updates._end_background_update(
175-
"populate_stats_process_rooms_2"
151+
"populate_stats_process_rooms"
176152
)
177153
return 1
178154

@@ -189,13 +165,13 @@ def _get_next_batch(txn):
189165
return [r for r, in txn]
190166

191167
rooms_to_work_on = await self.db_pool.runInteraction(
192-
"populate_stats_rooms_2_get_batch", _get_next_batch
168+
"populate_stats_rooms_get_batch", _get_next_batch
193169
)
194170

195171
# No more rooms -- complete the transaction.
196172
if not rooms_to_work_on:
197173
await self.db_pool.updates._end_background_update(
198-
"populate_stats_process_rooms_2"
174+
"populate_stats_process_rooms"
199175
)
200176
return 1
201177

@@ -204,9 +180,9 @@ def _get_next_batch(txn):
204180
progress["last_room_id"] = room_id
205181

206182
await self.db_pool.runInteraction(
207-
"_populate_stats_process_rooms_2",
183+
"_populate_stats_process_rooms",
208184
self.db_pool.updates._background_update_progress_txn,
209-
"populate_stats_process_rooms_2",
185+
"populate_stats_process_rooms",
210186
progress,
211187
)
212188

tests/handlers/test_stats.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _add_background_updates(self):
5454
self.store.db_pool.simple_insert(
5555
"background_updates",
5656
{
57-
"update_name": "populate_stats_process_rooms_2",
57+
"update_name": "populate_stats_process_rooms",
5858
"progress_json": "{}",
5959
"depends_on": "populate_stats_prepare",
6060
},
@@ -66,7 +66,7 @@ def _add_background_updates(self):
6666
{
6767
"update_name": "populate_stats_process_users",
6868
"progress_json": "{}",
69-
"depends_on": "populate_stats_process_rooms_2",
69+
"depends_on": "populate_stats_process_rooms",
7070
},
7171
)
7272
)
@@ -219,10 +219,7 @@ def test_initial_earliest_token(self):
219219
self.get_success(
220220
self.store.db_pool.simple_insert(
221221
"background_updates",
222-
{
223-
"update_name": "populate_stats_process_rooms_2",
224-
"progress_json": "{}",
225-
},
222+
{"update_name": "populate_stats_process_rooms", "progress_json": "{}"},
226223
)
227224
)
228225
self.get_success(
@@ -231,7 +228,7 @@ def test_initial_earliest_token(self):
231228
{
232229
"update_name": "populate_stats_cleanup",
233230
"progress_json": "{}",
234-
"depends_on": "populate_stats_process_rooms_2",
231+
"depends_on": "populate_stats_process_rooms",
235232
},
236233
)
237234
)
@@ -728,7 +725,7 @@ def test_incomplete_stats(self):
728725
self.store.db_pool.simple_insert(
729726
"background_updates",
730727
{
731-
"update_name": "populate_stats_process_rooms_2",
728+
"update_name": "populate_stats_process_rooms",
732729
"progress_json": "{}",
733730
"depends_on": "populate_stats_prepare",
734731
},
@@ -740,7 +737,7 @@ def test_incomplete_stats(self):
740737
{
741738
"update_name": "populate_stats_process_users",
742739
"progress_json": "{}",
743-
"depends_on": "populate_stats_process_rooms_2",
740+
"depends_on": "populate_stats_process_rooms",
744741
},
745742
)
746743
)

0 commit comments

Comments
 (0)