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

Commit

Permalink
Merge branch 'develop' into remove-worker-replication-deprecated-sett…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
realtyem authored Jul 4, 2023
2 parents be0bb9e + 670d590 commit f9f5ce4
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 57 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ __pycache__/
/logs
/media_store/
/uploads
/homeserver-config-overrides.d

# For direnv users
/.envrc
Expand Down
1 change: 1 addition & 0 deletions changelog.d/15853.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add a timeout that aborts any Postgres statement taking more than 1 hour.
1 change: 1 addition & 0 deletions changelog.d/15854.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the `devenv up` configuration which was ignoring the config overrides.
1 change: 1 addition & 0 deletions changelog.d/15861.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Optimised cleanup of old entries in device_lists_stream.
3 changes: 3 additions & 0 deletions changelog.d/15862.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Pin `pydantic` to ^=1.7.4 to avoid backwards-incompatible API changes from the 2.0.0 release.
Resolves https://github.com/matrix-org/synapse/issues/15858.
Contributed by @PaarthShah.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
EOF
'';
# Start synapse when `devenv up` is run.
processes.synapse.exec = "poetry run python -m synapse.app.homeserver -c homeserver.yaml --config-directory homeserver-config-overrides.d";
processes.synapse.exec = "poetry run python -m synapse.app.homeserver -c homeserver.yaml -c homeserver-config-overrides.d";

# Define the perl modules we require to run SyTest.
#
Expand Down
100 changes: 50 additions & 50 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ packaging = ">=16.1"
# which shipped in Python 3.8. This corresponds to version 1.4 of the backport.
importlib_metadata = { version = ">=1.4", python = "<3.8" }
# This is the most recent version of Pydantic with available on common distros.
pydantic = ">=1.7.4"
# We are currently incompatible with >=2.0.0: (https://github.com/matrix-org/synapse/issues/15858)
pydantic = "^1.7.4"

# This is for building the rust components during "poetry install", which
# currently ignores the `build-system.requires` directive (c.f.
Expand Down
14 changes: 9 additions & 5 deletions synapse/storage/databases/main/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -1950,12 +1950,16 @@ def _add_device_change_to_stream_txn(

# Delete older entries in the table, as we really only care about
# when the latest change happened.
txn.execute_batch(
"""
cleanup_obsolete_stmt = """
DELETE FROM device_lists_stream
WHERE user_id = ? AND device_id = ? AND stream_id < ?
""",
[(user_id, device_id, min_stream_id) for device_id in device_ids],
WHERE user_id = ? AND stream_id < ? AND %s
"""
device_ids_clause, device_ids_args = make_in_list_sql_clause(
txn.database_engine, "device_id", device_ids
)
txn.execute(
cleanup_obsolete_stmt % (device_ids_clause,),
[user_id, min_stream_id] + device_ids_args,
)

self.db_pool.simple_insert_many_txn(
Expand Down
13 changes: 13 additions & 0 deletions synapse/storage/engines/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ def _disable_bytes_adapter(_: bytes) -> NoReturn:

psycopg2.extensions.register_adapter(bytes, _disable_bytes_adapter)
self.synchronous_commit: bool = database_config.get("synchronous_commit", True)
# Set the statement timeout to 1 hour by default.
# Any query taking more than 1 hour should probably be considered a bug;
# most of the time this is a sign that work needs to be split up or that
# some degenerate query plan has been created and the client has probably
# timed out/walked off anyway.
# This is in milliseconds.
self.statement_timeout: Optional[int] = database_config.get(
"statement_timeout", 60 * 60 * 1000
)
self._version: Optional[int] = None # unknown as yet

self.isolation_level_map: Mapping[int, int] = {
Expand Down Expand Up @@ -157,6 +166,10 @@ def on_new_connection(self, db_conn: "LoggingDatabaseConnection") -> None:
if not self.synchronous_commit:
cursor.execute("SET synchronous_commit TO OFF")

# Abort really long-running statements and turn them into errors.
if self.statement_timeout is not None:
cursor.execute("SET statement_timeout TO ?", (self.statement_timeout,))

cursor.close()
db_conn.commit()

Expand Down

0 comments on commit f9f5ce4

Please sign in to comment.