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

Commit

Permalink
Remove code which updates application_services_state.last_txn
Browse files Browse the repository at this point in the history
This column is unused as of #12209, so let's stop writing to it.
  • Loading branch information
richvdh committed May 9, 2022
1 parent a00462d commit 12fb065
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 30 deletions.
1 change: 1 addition & 0 deletions changelog.d/12680.misc
@@ -0,0 +1 @@
Remove code which updates unused database column `application_services_state.last_txn`.
8 changes: 0 additions & 8 deletions synapse/storage/databases/main/appservice.py
Expand Up @@ -296,14 +296,6 @@ async def complete_appservice_txn(
"""

def _complete_appservice_txn(txn: LoggingTransaction) -> None:
# Set current txn_id for AS to 'txn_id'
self.db_pool.simple_upsert_txn(
txn,
"application_services_state",
{"as_id": service.id},
{"last_txn": txn_id},
)

# Delete txn
self.db_pool.simple_delete_txn(
txn,
Expand Down
5 changes: 4 additions & 1 deletion synapse/storage/schema/__init__.py
Expand Up @@ -61,13 +61,16 @@
Changes in SCHEMA_VERSION = 69:
- We now write to `device_lists_changes_in_room` table.
- Use sequence to generate future `application_services_txns.txn_id`s
- We now use a PostgreSQL sequence to generate future txn_ids for
`application_services_txns`. `application_services_state.last_txn` is no longer
updated.
"""


SCHEMA_COMPAT_VERSION = (
# We now assume that `device_lists_changes_in_room` has been filled out for
# recent device_list_updates.
# ... and that `application_services_state.last_txn` is not used.
69
)
"""Limit on how far the synapse codebase can be rolled back without breaking db compat
Expand Down
27 changes: 6 additions & 21 deletions tests/storage/test_appservice.py
Expand Up @@ -14,7 +14,7 @@
import json
import os
import tempfile
from typing import List, Optional, cast
from typing import List, cast
from unittest.mock import Mock

import yaml
Expand Down Expand Up @@ -149,15 +149,12 @@ def _add_service(self, url, as_token, id) -> None:
outfile.write(yaml.dump(as_yaml))
self.as_yaml_files.append(as_token)

def _set_state(
self, id: str, state: ApplicationServiceState, txn: Optional[int] = None
):
def _set_state(self, id: str, state: ApplicationServiceState):
return self.db_pool.runOperation(
self.engine.convert_param_style(
"INSERT INTO application_services_state(as_id, state, last_txn) "
"VALUES(?,?,?)"
"INSERT INTO application_services_state(as_id, state) VALUES(?,?)"
),
(id, state.value, txn),
(id, state.value),
)

def _insert_txn(self, as_id, txn_id, events):
Expand Down Expand Up @@ -280,17 +277,6 @@ def test_complete_appservice_txn_first_txn(
self.store.complete_appservice_txn(txn_id=txn_id, service=service)
)

res = self.get_success(
self.db_pool.runQuery(
self.engine.convert_param_style(
"SELECT last_txn FROM application_services_state WHERE as_id=?"
),
(service.id,),
)
)
self.assertEqual(1, len(res))
self.assertEqual(txn_id, res[0][0])

res = self.get_success(
self.db_pool.runQuery(
self.engine.convert_param_style(
Expand All @@ -316,14 +302,13 @@ def test_complete_appservice_txn_updates_last_txn_state(
res = self.get_success(
self.db_pool.runQuery(
self.engine.convert_param_style(
"SELECT last_txn, state FROM application_services_state WHERE as_id=?"
"SELECT state FROM application_services_state WHERE as_id=?"
),
(service.id,),
)
)
self.assertEqual(1, len(res))
self.assertEqual(txn_id, res[0][0])
self.assertEqual(ApplicationServiceState.UP.value, res[0][1])
self.assertEqual(ApplicationServiceState.UP.value, res[0][0])

res = self.get_success(
self.db_pool.runQuery(
Expand Down

0 comments on commit 12fb065

Please sign in to comment.