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

Commit

Permalink
Fix bug when running presence off master (#10149)
Browse files Browse the repository at this point in the history
Hopefully fixes #10027.
  • Loading branch information
erikjohnston committed Jun 11, 2021
1 parent b31daac commit d26d15b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/10149.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug which caused presence updates to stop working some time after restart, when using a presence writer worker.
2 changes: 1 addition & 1 deletion synapse/storage/databases/main/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(
instance_name=self._instance_name,
tables=[("presence_stream", "instance_name", "stream_id")],
sequence_name="presence_stream_sequence",
writers=hs.config.worker.writers.to_device,
writers=hs.config.worker.writers.presence,
)
else:
self._presence_id_gen = StreamIdGenerator(
Expand Down
15 changes: 15 additions & 0 deletions synapse/storage/util/id_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,11 @@ def get_next(self):
# ... persist event ...
"""

# If we have a list of instances that are allowed to write to this
# stream, make sure we're in it.
if self._writers and self._instance_name not in self._writers:
raise Exception("Tried to allocate stream ID on non-writer")

return _MultiWriterCtxManager(self)

def get_next_mult(self, n: int):
Expand All @@ -406,6 +411,11 @@ def get_next_mult(self, n: int):
# ... persist events ...
"""

# If we have a list of instances that are allowed to write to this
# stream, make sure we're in it.
if self._writers and self._instance_name not in self._writers:
raise Exception("Tried to allocate stream ID on non-writer")

return _MultiWriterCtxManager(self, n)

def get_next_txn(self, txn: LoggingTransaction):
Expand All @@ -416,6 +426,11 @@ def get_next_txn(self, txn: LoggingTransaction):
# ... persist event ...
"""

# If we have a list of instances that are allowed to write to this
# stream, make sure we're in it.
if self._writers and self._instance_name not in self._writers:
raise Exception("Tried to allocate stream ID on non-writer")

next_id = self._load_next_id_txn(txn)

with self._lock:
Expand Down

0 comments on commit d26d15b

Please sign in to comment.