synapse_port_db 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright 2015, 2016 OpenMarket Ltd
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. from twisted.internet import defer, reactor
  17. from twisted.enterprise import adbapi
  18. from synapse.storage._base import LoggingTransaction, SQLBaseStore
  19. from synapse.storage.engines import create_engine
  20. import argparse
  21. import curses
  22. import logging
  23. import sys
  24. import time
  25. import traceback
  26. import yaml
  27. logger = logging.getLogger("synapse_port_db")
  28. BOOLEAN_COLUMNS = {
  29. "events": ["processed", "outlier"],
  30. "rooms": ["is_public"],
  31. "event_edges": ["is_state"],
  32. "presence_list": ["accepted"],
  33. }
  34. APPEND_ONLY_TABLES = [
  35. "event_content_hashes",
  36. "event_reference_hashes",
  37. "event_signatures",
  38. "event_edge_hashes",
  39. "events",
  40. "event_json",
  41. "state_events",
  42. "room_memberships",
  43. "feedback",
  44. "topics",
  45. "room_names",
  46. "rooms",
  47. "local_media_repository",
  48. "local_media_repository_thumbnails",
  49. "remote_media_cache",
  50. "remote_media_cache_thumbnails",
  51. "redactions",
  52. "event_edges",
  53. "event_auth",
  54. "received_transactions",
  55. "sent_transactions",
  56. "transaction_id_to_pdu",
  57. "users",
  58. "state_groups",
  59. "state_groups_state",
  60. "event_to_state_groups",
  61. "rejections",
  62. "event_search",
  63. ]
  64. end_error_exec_info = None
  65. class Store(object):
  66. """This object is used to pull out some of the convenience API from the
  67. Storage layer.
  68. *All* database interactions should go through this object.
  69. """
  70. def __init__(self, db_pool, engine):
  71. self.db_pool = db_pool
  72. self.database_engine = engine
  73. _simple_insert_txn = SQLBaseStore.__dict__["_simple_insert_txn"]
  74. _simple_insert = SQLBaseStore.__dict__["_simple_insert"]
  75. _simple_select_onecol_txn = SQLBaseStore.__dict__["_simple_select_onecol_txn"]
  76. _simple_select_onecol = SQLBaseStore.__dict__["_simple_select_onecol"]
  77. _simple_select_one_onecol = SQLBaseStore.__dict__["_simple_select_one_onecol"]
  78. _simple_select_one_onecol_txn = SQLBaseStore.__dict__["_simple_select_one_onecol_txn"]
  79. _simple_update_one = SQLBaseStore.__dict__["_simple_update_one"]
  80. _simple_update_one_txn = SQLBaseStore.__dict__["_simple_update_one_txn"]
  81. def runInteraction(self, desc, func, *args, **kwargs):
  82. def r(conn):
  83. try:
  84. i = 0
  85. N = 5
  86. while True:
  87. try:
  88. txn = conn.cursor()
  89. return func(
  90. LoggingTransaction(txn, desc, self.database_engine, []),
  91. *args, **kwargs
  92. )
  93. except self.database_engine.module.DatabaseError as e:
  94. if self.database_engine.is_deadlock(e):
  95. logger.warn("[TXN DEADLOCK] {%s} %d/%d", desc, i, N)
  96. if i < N:
  97. i += 1
  98. conn.rollback()
  99. continue
  100. raise
  101. except Exception as e:
  102. logger.debug("[TXN FAIL] {%s} %s", desc, e)
  103. raise
  104. return self.db_pool.runWithConnection(r)
  105. def execute(self, f, *args, **kwargs):
  106. return self.runInteraction(f.__name__, f, *args, **kwargs)
  107. def execute_sql(self, sql, *args):
  108. def r(txn):
  109. txn.execute(sql, args)
  110. return txn.fetchall()
  111. return self.runInteraction("execute_sql", r)
  112. def insert_many_txn(self, txn, table, headers, rows):
  113. sql = "INSERT INTO %s (%s) VALUES (%s)" % (
  114. table,
  115. ", ".join(k for k in headers),
  116. ", ".join("%s" for _ in headers)
  117. )
  118. try:
  119. txn.executemany(sql, rows)
  120. except:
  121. logger.exception(
  122. "Failed to insert: %s",
  123. table,
  124. )
  125. raise
  126. class Porter(object):
  127. def __init__(self, **kwargs):
  128. self.__dict__.update(kwargs)
  129. @defer.inlineCallbacks
  130. def setup_table(self, table):
  131. if table in APPEND_ONLY_TABLES:
  132. # It's safe to just carry on inserting.
  133. next_chunk = yield self.postgres_store._simple_select_one_onecol(
  134. table="port_from_sqlite3",
  135. keyvalues={"table_name": table},
  136. retcol="rowid",
  137. allow_none=True,
  138. )
  139. total_to_port = None
  140. if next_chunk is None:
  141. if table == "sent_transactions":
  142. next_chunk, already_ported, total_to_port = (
  143. yield self._setup_sent_transactions()
  144. )
  145. else:
  146. yield self.postgres_store._simple_insert(
  147. table="port_from_sqlite3",
  148. values={"table_name": table, "rowid": 1}
  149. )
  150. next_chunk = 1
  151. already_ported = 0
  152. if total_to_port is None:
  153. already_ported, total_to_port = yield self._get_total_count_to_port(
  154. table, next_chunk
  155. )
  156. else:
  157. def delete_all(txn):
  158. txn.execute(
  159. "DELETE FROM port_from_sqlite3 WHERE table_name = %s",
  160. (table,)
  161. )
  162. txn.execute("TRUNCATE %s CASCADE" % (table,))
  163. yield self.postgres_store.execute(delete_all)
  164. yield self.postgres_store._simple_insert(
  165. table="port_from_sqlite3",
  166. values={"table_name": table, "rowid": 0}
  167. )
  168. next_chunk = 1
  169. already_ported, total_to_port = yield self._get_total_count_to_port(
  170. table, next_chunk
  171. )
  172. defer.returnValue((table, already_ported, total_to_port, next_chunk))
  173. @defer.inlineCallbacks
  174. def handle_table(self, table, postgres_size, table_size, next_chunk):
  175. if not table_size:
  176. return
  177. self.progress.add_table(table, postgres_size, table_size)
  178. select = (
  179. "SELECT rowid, * FROM %s WHERE rowid >= ? ORDER BY rowid LIMIT ?"
  180. % (table,)
  181. )
  182. while True:
  183. def r(txn):
  184. txn.execute(select, (next_chunk, self.batch_size,))
  185. rows = txn.fetchall()
  186. headers = [column[0] for column in txn.description]
  187. return headers, rows
  188. headers, rows = yield self.sqlite_store.runInteraction("select", r)
  189. if rows:
  190. next_chunk = rows[-1][0] + 1
  191. if table == "event_search":
  192. # We have to treat event_search differently since it has a
  193. # different structure in the two different databases.
  194. def insert(txn):
  195. sql = (
  196. "INSERT INTO event_search (event_id, room_id, key, sender, vector)"
  197. " VALUES (?,?,?,?,to_tsvector('english', ?))"
  198. )
  199. rows_dict = [
  200. dict(zip(headers, row))
  201. for row in rows
  202. ]
  203. txn.executemany(sql, [
  204. (
  205. row["event_id"],
  206. row["room_id"],
  207. row["key"],
  208. row["sender"],
  209. row["value"],
  210. )
  211. for row in rows_dict
  212. ])
  213. self.postgres_store._simple_update_one_txn(
  214. txn,
  215. table="port_from_sqlite3",
  216. keyvalues={"table_name": table},
  217. updatevalues={"rowid": next_chunk},
  218. )
  219. else:
  220. self._convert_rows(table, headers, rows)
  221. def insert(txn):
  222. self.postgres_store.insert_many_txn(
  223. txn, table, headers[1:], rows
  224. )
  225. self.postgres_store._simple_update_one_txn(
  226. txn,
  227. table="port_from_sqlite3",
  228. keyvalues={"table_name": table},
  229. updatevalues={"rowid": next_chunk},
  230. )
  231. yield self.postgres_store.execute(insert)
  232. postgres_size += len(rows)
  233. self.progress.update(table, postgres_size)
  234. else:
  235. return
  236. def setup_db(self, db_config, database_engine):
  237. db_conn = database_engine.module.connect(
  238. **{
  239. k: v for k, v in db_config.get("args", {}).items()
  240. if not k.startswith("cp_")
  241. }
  242. )
  243. database_engine.prepare_database(db_conn)
  244. db_conn.commit()
  245. @defer.inlineCallbacks
  246. def run(self):
  247. try:
  248. sqlite_db_pool = adbapi.ConnectionPool(
  249. self.sqlite_config["name"],
  250. **self.sqlite_config["args"]
  251. )
  252. postgres_db_pool = adbapi.ConnectionPool(
  253. self.postgres_config["name"],
  254. **self.postgres_config["args"]
  255. )
  256. sqlite_engine = create_engine(FakeConfig(sqlite_config))
  257. postgres_engine = create_engine(FakeConfig(postgres_config))
  258. self.sqlite_store = Store(sqlite_db_pool, sqlite_engine)
  259. self.postgres_store = Store(postgres_db_pool, postgres_engine)
  260. yield self.postgres_store.execute(
  261. postgres_engine.check_database
  262. )
  263. # Step 1. Set up databases.
  264. self.progress.set_state("Preparing SQLite3")
  265. self.setup_db(sqlite_config, sqlite_engine)
  266. self.progress.set_state("Preparing PostgreSQL")
  267. self.setup_db(postgres_config, postgres_engine)
  268. # Step 2. Get tables.
  269. self.progress.set_state("Fetching tables")
  270. sqlite_tables = yield self.sqlite_store._simple_select_onecol(
  271. table="sqlite_master",
  272. keyvalues={
  273. "type": "table",
  274. },
  275. retcol="name",
  276. )
  277. postgres_tables = yield self.postgres_store._simple_select_onecol(
  278. table="information_schema.tables",
  279. keyvalues={
  280. "table_schema": "public",
  281. },
  282. retcol="distinct table_name",
  283. )
  284. tables = set(sqlite_tables) & set(postgres_tables)
  285. self.progress.set_state("Creating tables")
  286. logger.info("Found %d tables", len(tables))
  287. def create_port_table(txn):
  288. txn.execute(
  289. "CREATE TABLE port_from_sqlite3 ("
  290. " table_name varchar(100) NOT NULL UNIQUE,"
  291. " rowid bigint NOT NULL"
  292. ")"
  293. )
  294. try:
  295. yield self.postgres_store.runInteraction(
  296. "create_port_table", create_port_table
  297. )
  298. except Exception as e:
  299. logger.info("Failed to create port table: %s", e)
  300. self.progress.set_state("Setting up")
  301. # Set up tables.
  302. setup_res = yield defer.gatherResults(
  303. [
  304. self.setup_table(table)
  305. for table in tables
  306. if table not in ["schema_version", "applied_schema_deltas"]
  307. and not table.startswith("sqlite_")
  308. ],
  309. consumeErrors=True,
  310. )
  311. # Process tables.
  312. yield defer.gatherResults(
  313. [
  314. self.handle_table(*res)
  315. for res in setup_res
  316. ],
  317. consumeErrors=True,
  318. )
  319. self.progress.done()
  320. except:
  321. global end_error_exec_info
  322. end_error_exec_info = sys.exc_info()
  323. logger.exception("")
  324. finally:
  325. reactor.stop()
  326. def _convert_rows(self, table, headers, rows):
  327. bool_col_names = BOOLEAN_COLUMNS.get(table, [])
  328. bool_cols = [
  329. i for i, h in enumerate(headers) if h in bool_col_names
  330. ]
  331. def conv(j, col):
  332. if j in bool_cols:
  333. return bool(col)
  334. return col
  335. for i, row in enumerate(rows):
  336. rows[i] = tuple(
  337. conv(j, col)
  338. for j, col in enumerate(row)
  339. if j > 0
  340. )
  341. @defer.inlineCallbacks
  342. def _setup_sent_transactions(self):
  343. # Only save things from the last day
  344. yesterday = int(time.time()*1000) - 86400000
  345. # And save the max transaction id from each destination
  346. select = (
  347. "SELECT rowid, * FROM sent_transactions WHERE rowid IN ("
  348. "SELECT max(rowid) FROM sent_transactions"
  349. " GROUP BY destination"
  350. ")"
  351. )
  352. def r(txn):
  353. txn.execute(select)
  354. rows = txn.fetchall()
  355. headers = [column[0] for column in txn.description]
  356. ts_ind = headers.index('ts')
  357. return headers, [r for r in rows if r[ts_ind] < yesterday]
  358. headers, rows = yield self.sqlite_store.runInteraction(
  359. "select", r,
  360. )
  361. self._convert_rows("sent_transactions", headers, rows)
  362. inserted_rows = len(rows)
  363. if inserted_rows:
  364. max_inserted_rowid = max(r[0] for r in rows)
  365. def insert(txn):
  366. self.postgres_store.insert_many_txn(
  367. txn, "sent_transactions", headers[1:], rows
  368. )
  369. yield self.postgres_store.execute(insert)
  370. else:
  371. max_inserted_rowid = 0
  372. def get_start_id(txn):
  373. txn.execute(
  374. "SELECT rowid FROM sent_transactions WHERE ts >= ?"
  375. " ORDER BY rowid ASC LIMIT 1",
  376. (yesterday,)
  377. )
  378. rows = txn.fetchall()
  379. if rows:
  380. return rows[0][0]
  381. else:
  382. return 1
  383. next_chunk = yield self.sqlite_store.execute(get_start_id)
  384. next_chunk = max(max_inserted_rowid + 1, next_chunk)
  385. yield self.postgres_store._simple_insert(
  386. table="port_from_sqlite3",
  387. values={"table_name": "sent_transactions", "rowid": next_chunk}
  388. )
  389. def get_sent_table_size(txn):
  390. txn.execute(
  391. "SELECT count(*) FROM sent_transactions"
  392. " WHERE ts >= ?",
  393. (yesterday,)
  394. )
  395. size, = txn.fetchone()
  396. return int(size)
  397. remaining_count = yield self.sqlite_store.execute(
  398. get_sent_table_size
  399. )
  400. total_count = remaining_count + inserted_rows
  401. defer.returnValue((next_chunk, inserted_rows, total_count))
  402. @defer.inlineCallbacks
  403. def _get_remaining_count_to_port(self, table, next_chunk):
  404. rows = yield self.sqlite_store.execute_sql(
  405. "SELECT count(*) FROM %s WHERE rowid >= ?" % (table,),
  406. next_chunk,
  407. )
  408. defer.returnValue(rows[0][0])
  409. @defer.inlineCallbacks
  410. def _get_already_ported_count(self, table):
  411. rows = yield self.postgres_store.execute_sql(
  412. "SELECT count(*) FROM %s" % (table,),
  413. )
  414. defer.returnValue(rows[0][0])
  415. @defer.inlineCallbacks
  416. def _get_total_count_to_port(self, table, next_chunk):
  417. remaining, done = yield defer.gatherResults(
  418. [
  419. self._get_remaining_count_to_port(table, next_chunk),
  420. self._get_already_ported_count(table),
  421. ],
  422. consumeErrors=True,
  423. )
  424. remaining = int(remaining) if remaining else 0
  425. done = int(done) if done else 0
  426. defer.returnValue((done, remaining + done))
  427. ##############################################
  428. ###### The following is simply UI stuff ######
  429. ##############################################
  430. class Progress(object):
  431. """Used to report progress of the port
  432. """
  433. def __init__(self):
  434. self.tables = {}
  435. self.start_time = int(time.time())
  436. def add_table(self, table, cur, size):
  437. self.tables[table] = {
  438. "start": cur,
  439. "num_done": cur,
  440. "total": size,
  441. "perc": int(cur * 100 / size),
  442. }
  443. def update(self, table, num_done):
  444. data = self.tables[table]
  445. data["num_done"] = num_done
  446. data["perc"] = int(num_done * 100 / data["total"])
  447. def done(self):
  448. pass
  449. class CursesProgress(Progress):
  450. """Reports progress to a curses window
  451. """
  452. def __init__(self, stdscr):
  453. self.stdscr = stdscr
  454. curses.use_default_colors()
  455. curses.curs_set(0)
  456. curses.init_pair(1, curses.COLOR_RED, -1)
  457. curses.init_pair(2, curses.COLOR_GREEN, -1)
  458. self.last_update = 0
  459. self.finished = False
  460. self.total_processed = 0
  461. self.total_remaining = 0
  462. super(CursesProgress, self).__init__()
  463. def update(self, table, num_done):
  464. super(CursesProgress, self).update(table, num_done)
  465. self.total_processed = 0
  466. self.total_remaining = 0
  467. for table, data in self.tables.items():
  468. self.total_processed += data["num_done"] - data["start"]
  469. self.total_remaining += data["total"] - data["num_done"]
  470. self.render()
  471. def render(self, force=False):
  472. now = time.time()
  473. if not force and now - self.last_update < 0.2:
  474. # reactor.callLater(1, self.render)
  475. return
  476. self.stdscr.clear()
  477. rows, cols = self.stdscr.getmaxyx()
  478. duration = int(now) - int(self.start_time)
  479. minutes, seconds = divmod(duration, 60)
  480. duration_str = '%02dm %02ds' % (minutes, seconds,)
  481. if self.finished:
  482. status = "Time spent: %s (Done!)" % (duration_str,)
  483. else:
  484. if self.total_processed > 0:
  485. left = float(self.total_remaining) / self.total_processed
  486. est_remaining = (int(now) - self.start_time) * left
  487. est_remaining_str = '%02dm %02ds remaining' % divmod(est_remaining, 60)
  488. else:
  489. est_remaining_str = "Unknown"
  490. status = (
  491. "Time spent: %s (est. remaining: %s)"
  492. % (duration_str, est_remaining_str,)
  493. )
  494. self.stdscr.addstr(
  495. 0, 0,
  496. status,
  497. curses.A_BOLD,
  498. )
  499. max_len = max([len(t) for t in self.tables.keys()])
  500. left_margin = 5
  501. middle_space = 1
  502. items = self.tables.items()
  503. items.sort(
  504. key=lambda i: (i[1]["perc"], i[0]),
  505. )
  506. for i, (table, data) in enumerate(items):
  507. if i + 2 >= rows:
  508. break
  509. perc = data["perc"]
  510. color = curses.color_pair(2) if perc == 100 else curses.color_pair(1)
  511. self.stdscr.addstr(
  512. i+2, left_margin + max_len - len(table),
  513. table,
  514. curses.A_BOLD | color,
  515. )
  516. size = 20
  517. progress = "[%s%s]" % (
  518. "#" * int(perc*size/100),
  519. " " * (size - int(perc*size/100)),
  520. )
  521. self.stdscr.addstr(
  522. i+2, left_margin + max_len + middle_space,
  523. "%s %3d%% (%d/%d)" % (progress, perc, data["num_done"], data["total"]),
  524. )
  525. if self.finished:
  526. self.stdscr.addstr(
  527. rows-1, 0,
  528. "Press any key to exit...",
  529. )
  530. self.stdscr.refresh()
  531. self.last_update = time.time()
  532. def done(self):
  533. self.finished = True
  534. self.render(True)
  535. self.stdscr.getch()
  536. def set_state(self, state):
  537. self.stdscr.clear()
  538. self.stdscr.addstr(
  539. 0, 0,
  540. state + "...",
  541. curses.A_BOLD,
  542. )
  543. self.stdscr.refresh()
  544. class TerminalProgress(Progress):
  545. """Just prints progress to the terminal
  546. """
  547. def update(self, table, num_done):
  548. super(TerminalProgress, self).update(table, num_done)
  549. data = self.tables[table]
  550. print "%s: %d%% (%d/%d)" % (
  551. table, data["perc"],
  552. data["num_done"], data["total"],
  553. )
  554. def set_state(self, state):
  555. print state + "..."
  556. ##############################################
  557. ##############################################
  558. if __name__ == "__main__":
  559. parser = argparse.ArgumentParser(
  560. description="A script to port an existing synapse SQLite database to"
  561. " a new PostgreSQL database."
  562. )
  563. parser.add_argument("-v", action='store_true')
  564. parser.add_argument(
  565. "--sqlite-database", required=True,
  566. help="The snapshot of the SQLite database file. This must not be"
  567. " currently used by a running synapse server"
  568. )
  569. parser.add_argument(
  570. "--postgres-config", type=argparse.FileType('r'), required=True,
  571. help="The database config file for the PostgreSQL database"
  572. )
  573. parser.add_argument(
  574. "--curses", action='store_true',
  575. help="display a curses based progress UI"
  576. )
  577. parser.add_argument(
  578. "--batch-size", type=int, default=1000,
  579. help="The number of rows to select from the SQLite table each"
  580. " iteration [default=1000]",
  581. )
  582. args = parser.parse_args()
  583. logging_config = {
  584. "level": logging.DEBUG if args.v else logging.INFO,
  585. "format": "%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(message)s"
  586. }
  587. if args.curses:
  588. logging_config["filename"] = "port-synapse.log"
  589. logging.basicConfig(**logging_config)
  590. sqlite_config = {
  591. "name": "sqlite3",
  592. "args": {
  593. "database": args.sqlite_database,
  594. "cp_min": 1,
  595. "cp_max": 1,
  596. "check_same_thread": False,
  597. },
  598. }
  599. postgres_config = yaml.safe_load(args.postgres_config)
  600. if "database" in postgres_config:
  601. postgres_config = postgres_config["database"]
  602. if "name" not in postgres_config:
  603. sys.stderr.write("Malformed database config: no 'name'")
  604. sys.exit(2)
  605. if postgres_config["name"] != "psycopg2":
  606. sys.stderr.write("Database must use 'psycopg2' connector.")
  607. sys.exit(3)
  608. def start(stdscr=None):
  609. if stdscr:
  610. progress = CursesProgress(stdscr)
  611. else:
  612. progress = TerminalProgress()
  613. porter = Porter(
  614. sqlite_config=sqlite_config,
  615. postgres_config=postgres_config,
  616. progress=progress,
  617. batch_size=args.batch_size,
  618. )
  619. reactor.callWhenRunning(porter.run)
  620. reactor.run()
  621. if args.curses:
  622. curses.wrapper(start)
  623. else:
  624. start()
  625. if end_error_exec_info:
  626. exc_type, exc_value, exc_traceback = end_error_exec_info
  627. traceback.print_exception(exc_type, exc_value, exc_traceback)
  628. class FakeConfig:
  629. def __init__(self, database_config):
  630. self.database_config = database_config