-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Pass in Database object to data stores. #6487
Changes from 7 commits
9a4fb45
d64bb32
d537be1
75f8745
852f80d
5e35f69
71ee22c
65b37f6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Pass in `Database` object to data stores. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this isn't a great changelog entry, but we probably want to change all the datastore refactoring PRs to group them together, which is most easily done at release time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, though I find it difficult to write sensible change logs for internal refactors tbh |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ from synapse.storage.data_stores.main.stats import StatsStore | |
from synapse.storage.data_stores.main.user_directory import ( | ||
UserDirectoryBackgroundUpdateStore, | ||
) | ||
from synapse.storage.database import Database | ||
from synapse.storage.engines import create_engine | ||
from synapse.storage.prepare_database import prepare_database | ||
from synapse.util import Clock | ||
|
@@ -139,39 +140,6 @@ class Store( | |
UserDirectoryBackgroundUpdateStore, | ||
StatsStore, | ||
): | ||
def __init__(self, db_conn, hs): | ||
super().__init__(db_conn, hs) | ||
self.db_pool = hs.get_db_pool() | ||
|
||
@defer.inlineCallbacks | ||
def runInteraction(self, desc, func, *args, **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there must have been a reason this was here: any idea what it was, and why it no longer applies? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We didn't inherit from SQLBaseStore previously, instead we just cherry-picked stuff out by the looks of things There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, but we didn't inherit from that when the script was first written and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm right. |
||
def r(conn): | ||
try: | ||
i = 0 | ||
N = 5 | ||
while True: | ||
try: | ||
txn = conn.cursor() | ||
return func( | ||
LoggingTransaction(txn, desc, self.database_engine, [], []), | ||
*args, | ||
**kwargs | ||
) | ||
except self.database_engine.module.DatabaseError as e: | ||
if self.database_engine.is_deadlock(e): | ||
logger.warning("[TXN DEADLOCK] {%s} %d/%d", desc, i, N) | ||
if i < N: | ||
i += 1 | ||
conn.rollback() | ||
continue | ||
raise | ||
except Exception as e: | ||
logger.debug("[TXN FAIL] {%s} %s", desc, e) | ||
raise | ||
|
||
with PreserveLoggingContext(): | ||
return (yield self.db_pool.runWithConnection(r)) | ||
|
||
def execute(self, f, *args, **kwargs): | ||
return self.db.runInteraction(f.__name__, f, *args, **kwargs) | ||
|
||
|
@@ -512,7 +480,7 @@ class Porter(object): | |
|
||
hs = MockHomeserver(self.hs_config, engine, conn, db_pool) | ||
|
||
store = Store(conn, hs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wonder if we could use a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, though we only want to include the background update stores rather than building out full data stores. (Currently you could use main_store_class to do this, but when we have future data stores that won't necessarily be true) |
||
store = Store(Database(hs), conn, hs) | ||
|
||
yield store.db.runInteraction( | ||
"%s_engine.check_database" % config["name"], engine.check_database, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a thing that should be here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. The users in the test db are from
localhost:8800
and we now run the DB checks during the port DB run as they've been moved from synapse/app to the data stores.