Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
5b452df2
Unverified
Commit
5b452df2
authored
4 years ago
by
Richard van der Hoff
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Run database updates in a transaction (#8265)
Fixes: #6467
parent
765437df
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
changelog.d/8265.bugfix
+1
-0
1 addition, 0 deletions
changelog.d/8265.bugfix
synapse/storage/prepare_database.py
+22
-5
22 additions, 5 deletions
synapse/storage/prepare_database.py
with
23 additions
and
5 deletions
changelog.d/8265.bugfix
0 → 100644
+
1
−
0
View file @
5b452df2
Fix logstanding bug which could lead to incomplete database upgrades on SQLite.
This diff is collapsed.
Click to expand it.
synapse/storage/prepare_database.py
+
22
−
5
View file @
5b452df2
...
...
@@ -19,12 +19,15 @@ import logging
import
os
import
re
from
collections
import
Counter
from
typing
import
TextIO
from
typing
import
Optional
,
TextIO
import
attr
from
synapse.config.homeserver
import
HomeServerConfig
from
synapse.storage.engines
import
BaseDatabaseEngine
from
synapse.storage.engines.postgres
import
PostgresEngine
from
synapse.storage.types
import
Cursor
from
synapse.storage.types
import
Connection
,
Cursor
from
synapse.types
import
Collection
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -47,7 +50,12 @@ class UpgradeDatabaseException(PrepareDatabaseException):
pass
def
prepare_database
(
db_conn
,
database_engine
,
config
,
databases
=
[
"
main
"
,
"
state
"
]):
def
prepare_database
(
db_conn
:
Connection
,
database_engine
:
BaseDatabaseEngine
,
config
:
Optional
[
HomeServerConfig
],
databases
:
Collection
[
str
]
=
[
"
main
"
,
"
state
"
],
):
"""
Prepares a physical database for usage. Will either create all necessary tables
or upgrade from an older schema version.
...
...
@@ -57,15 +65,24 @@ def prepare_database(db_conn, database_engine, config, databases=["main", "state
Args:
db_conn:
database_engine:
config
(synapse.config.homeserver.HomeServerConfig|None)
:
config :
application config, or None if we are connecting to an existing
database which we expect to be configured already
databases
(list[str])
: The name of the databases that will be used
databases: The name of the databases that will be used
with this physical database. Defaults to all databases.
"""
try
:
cur
=
db_conn
.
cursor
()
# sqlite does not automatically start transactions for DDL / SELECT statements,
# so we start one before running anything. This ensures that any upgrades
# are either applied completely, or not at all.
#
# (psycopg2 automatically starts a transaction as soon as we run any statements
# at all, so this is redundant but harmless there.)
cur
.
execute
(
"
BEGIN TRANSACTION
"
)
version_info
=
_get_or_create_schema_state
(
cur
,
database_engine
)
if
version_info
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment