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

Fix race condition in room stats. #6029

Merged
merged 3 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6029.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix room and user stats tracking.
14 changes: 10 additions & 4 deletions synapse/handlers/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ def _unsafe_process(self):
# Loop round handling deltas until we're up to date

while True:
# Be sure to read the max stream_ordering *before* checking if there are any outstanding
# deltas, since there is otherwise a chance that we could miss updates which arrive
# after we check the deltas.
room_max_stream_ordering = yield self.store.get_room_max_stream_ordering()
richvdh marked this conversation as resolved.
Show resolved Hide resolved
if self.pos == room_max_stream_ordering:
break

deltas = yield self.store.get_current_state_deltas(self.pos)

if deltas:
Expand All @@ -94,7 +101,7 @@ def _unsafe_process(self):
else:
room_deltas = {}
user_deltas = {}
max_pos = yield self.store.get_room_max_stream_ordering()
max_pos = room_max_stream_ordering

# Then count deltas for total_events and total_event_bytes.
room_count, user_count = yield self.store.get_changes_room_total_events_and_bytes(
Expand All @@ -117,10 +124,9 @@ def _unsafe_process(self):
stream_id=max_pos,
)

event_processing_positions.labels("stats").set(max_pos)
logger.debug("Handled room stats to %s -> %s", self.pos, max_pos)

if self.pos == max_pos:
break
event_processing_positions.labels("stats").set(max_pos)

self.pos = max_pos

Expand Down