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

Add a config option for torture-testing worker replication. #4902

Merged
merged 1 commit into from
Mar 20, 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/4902.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a config option for torture-testing worker replication.
5 changes: 5 additions & 0 deletions synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ def read_config(self, config):
self.public_baseurl += '/'
self.start_pushers = config.get("start_pushers", True)

# (undocumented) option for torturing the worker-mode replication a bit,
# for testing. The value defines the number of milliseconds to pause before
# sending out any replication updates.
self.replication_torture_level = config.get("replication_torture_level")

self.listeners = []
for listener in config.get("listeners", []):
if not isinstance(listener.get("port", None), int):
Expand Down
18 changes: 17 additions & 1 deletion synapse/replication/tcp/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

import logging
import random

from six import itervalues

Expand Down Expand Up @@ -74,6 +75,8 @@ def __init__(self, hs):
self.notifier = hs.get_notifier()
self._server_notices_sender = hs.get_server_notices_sender()

self._replication_torture_level = hs.config.replication_torture_level

# Current connections.
self.connections = []

Expand Down Expand Up @@ -157,10 +160,23 @@ def _run_notifier_loop(self):
for stream in self.streams:
stream.advance_current_token()

for stream in self.streams:
all_streams = self.streams

if self._replication_torture_level is not None:
# there is no guarantee about ordering between the streams,
# so let's shuffle them around a bit when we are in torture mode.
all_streams = list(all_streams)
random.shuffle(all_streams)

for stream in all_streams:
if stream.last_token == stream.upto_token:
continue

if self._replication_torture_level:
yield self.clock.sleep(
self._replication_torture_level / 1000.0
)

logger.debug(
"Getting stream: %s: %s -> %s",
stream.NAME, stream.last_token, stream.upto_token
Expand Down