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

Commit 71ee22c

Browse files
committed
Fix port db script
1 parent 5e35f69 commit 71ee22c

File tree

4 files changed

+5
-37
lines changed

4 files changed

+5
-37
lines changed

.buildkite/postgres-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Configuration file used for testing the 'synapse_port_db' script.
22
# Tells the script to connect to the postgresql database that will be available in the
33
# CI's Docker setup at the point where this file is considered.
4-
server_name: "test"
4+
server_name: "localhost:8800"
55

66
signing_key_path: "/src/.buildkite/test.signing.key"
77

.buildkite/sqlite-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Configuration file used for testing the 'synapse_port_db' script.
22
# Tells the 'update_database' script to connect to the test SQLite database to upgrade its
33
# schema and run background updates on it.
4-
server_name: "test"
4+
server_name: "localhost:8800"
55

66
signing_key_path: "/src/.buildkite/test.signing.key"
77

scripts/synapse_port_db

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ from synapse.storage.data_stores.main.stats import StatsStore
5555
from synapse.storage.data_stores.main.user_directory import (
5656
UserDirectoryBackgroundUpdateStore,
5757
)
58+
from synapse.storage.database import Database
5859
from synapse.storage.engines import create_engine
5960
from synapse.storage.prepare_database import prepare_database
6061
from synapse.util import Clock
@@ -139,39 +140,6 @@ class Store(
139140
UserDirectoryBackgroundUpdateStore,
140141
StatsStore,
141142
):
142-
def __init__(self, db_conn, hs):
143-
super().__init__(db_conn, hs)
144-
self.db_pool = hs.get_db_pool()
145-
146-
@defer.inlineCallbacks
147-
def runInteraction(self, desc, func, *args, **kwargs):
148-
def r(conn):
149-
try:
150-
i = 0
151-
N = 5
152-
while True:
153-
try:
154-
txn = conn.cursor()
155-
return func(
156-
LoggingTransaction(txn, desc, self.database_engine, [], []),
157-
*args,
158-
**kwargs
159-
)
160-
except self.database_engine.module.DatabaseError as e:
161-
if self.database_engine.is_deadlock(e):
162-
logger.warning("[TXN DEADLOCK] {%s} %d/%d", desc, i, N)
163-
if i < N:
164-
i += 1
165-
conn.rollback()
166-
continue
167-
raise
168-
except Exception as e:
169-
logger.debug("[TXN FAIL] {%s} %s", desc, e)
170-
raise
171-
172-
with PreserveLoggingContext():
173-
return (yield self.db_pool.runWithConnection(r))
174-
175143
def execute(self, f, *args, **kwargs):
176144
return self.db.runInteraction(f.__name__, f, *args, **kwargs)
177145

@@ -512,7 +480,7 @@ class Porter(object):
512480

513481
hs = MockHomeserver(self.hs_config, engine, conn, db_pool)
514482

515-
store = Store(conn, hs)
483+
store = Store(Database(hs), conn, hs)
516484

517485
yield store.db.runInteraction(
518486
"%s_engine.check_database" % config["name"], engine.check_database,

synapse/storage/data_stores/main/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def __init__(self, database: Database, db_conn, hs):
124124
raise Exception(
125125
"Found users in database not native to %s!\n"
126126
"You cannot changed a synapse server_name after it's been configured"
127-
% (self.hostname,)
127+
% (hs.hostname,)
128128
)
129129

130130
self._stream_id_gen = StreamIdGenerator(

0 commit comments

Comments
 (0)