mirror of
https://git.anonymousland.org/anonymousland/synapse-product.git
synced 2024-12-24 09:59:21 -05:00
Merge pull request #6675 from matrix-org/rav/die_sqlite37_die_die_die
Refuse to start if sqlite is older than 3.11.0
This commit is contained in:
commit
1d16f5ea0e
@ -133,6 +133,11 @@ sudo yum install libtiff-devel libjpeg-devel libzip-devel freetype-devel \
|
|||||||
sudo yum groupinstall "Development Tools"
|
sudo yum groupinstall "Development Tools"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note that Synapse does not support versions of SQLite before 3.11, and CentOS 7
|
||||||
|
uses SQLite 3.7. You may be able to work around this by installing a more
|
||||||
|
recent SQLite version, but it is recommended that you instead use a Postgres
|
||||||
|
database: see [docs/postgres.md](docs/postgres.md).
|
||||||
|
|
||||||
#### macOS
|
#### macOS
|
||||||
|
|
||||||
Installing prerequisites on macOS:
|
Installing prerequisites on macOS:
|
||||||
|
1
changelog.d/6675.removal
Normal file
1
changelog.d/6675.removal
Normal file
@ -0,0 +1 @@
|
|||||||
|
Synapse no longer supports versions of SQLite before 3.11, and will refuse to start when configured to use an older version. Administrators are recommended to migrate their database to Postgres (see instructions [here](docs/postgres.md)).
|
@ -447,20 +447,15 @@ class Porter(object):
|
|||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
def setup_db(self, db_config: DatabaseConnectionConfig, engine):
|
def build_db_store(
|
||||||
db_conn = make_conn(db_config, engine)
|
self, db_config: DatabaseConnectionConfig, allow_outdated_version: bool = False,
|
||||||
prepare_database(db_conn, engine, config=None)
|
):
|
||||||
|
|
||||||
db_conn.commit()
|
|
||||||
|
|
||||||
return db_conn
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
|
||||||
def build_db_store(self, db_config: DatabaseConnectionConfig):
|
|
||||||
"""Builds and returns a database store using the provided configuration.
|
"""Builds and returns a database store using the provided configuration.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
config: The database configuration
|
db_config: The database configuration
|
||||||
|
allow_outdated_version: True to suppress errors about the database server
|
||||||
|
version being too old to run a complete synapse
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The built Store object.
|
The built Store object.
|
||||||
@ -468,16 +463,16 @@ class Porter(object):
|
|||||||
self.progress.set_state("Preparing %s" % db_config.config["name"])
|
self.progress.set_state("Preparing %s" % db_config.config["name"])
|
||||||
|
|
||||||
engine = create_engine(db_config.config)
|
engine = create_engine(db_config.config)
|
||||||
conn = self.setup_db(db_config, engine)
|
|
||||||
|
|
||||||
hs = MockHomeserver(self.hs_config)
|
hs = MockHomeserver(self.hs_config)
|
||||||
|
|
||||||
store = Store(Database(hs, db_config, engine), conn, hs)
|
with make_conn(db_config, engine) as db_conn:
|
||||||
|
engine.check_database(
|
||||||
yield store.db.runInteraction(
|
db_conn, allow_outdated_version=allow_outdated_version
|
||||||
"%s_engine.check_database" % db_config.config["name"],
|
)
|
||||||
engine.check_database,
|
prepare_database(db_conn, engine, config=None)
|
||||||
)
|
store = Store(Database(hs, db_config, engine), db_conn, hs)
|
||||||
|
db_conn.commit()
|
||||||
|
|
||||||
return store
|
return store
|
||||||
|
|
||||||
@ -502,8 +497,10 @@ class Porter(object):
|
|||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
self.sqlite_store = yield self.build_db_store(
|
# we allow people to port away from outdated versions of sqlite.
|
||||||
DatabaseConnectionConfig("master-sqlite", self.sqlite_config)
|
self.sqlite_store = self.build_db_store(
|
||||||
|
DatabaseConnectionConfig("master-sqlite", self.sqlite_config),
|
||||||
|
allow_outdated_version=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Check if all background updates are done, abort if not.
|
# Check if all background updates are done, abort if not.
|
||||||
@ -518,7 +515,7 @@ class Porter(object):
|
|||||||
)
|
)
|
||||||
defer.returnValue(None)
|
defer.returnValue(None)
|
||||||
|
|
||||||
self.postgres_store = yield self.build_db_store(
|
self.postgres_store = self.build_db_store(
|
||||||
self.hs_config.get_single_database()
|
self.hs_config.get_single_database()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class DataStores(object):
|
|||||||
with make_conn(database_config, engine) as db_conn:
|
with make_conn(database_config, engine) as db_conn:
|
||||||
logger.info("Preparing database %r...", db_name)
|
logger.info("Preparing database %r...", db_name)
|
||||||
|
|
||||||
engine.check_database(db_conn.cursor())
|
engine.check_database(db_conn)
|
||||||
prepare_database(
|
prepare_database(
|
||||||
db_conn, engine, hs.config, data_stores=database_config.data_stores,
|
db_conn, engine, hs.config, data_stores=database_config.data_stores,
|
||||||
)
|
)
|
||||||
|
@ -32,20 +32,7 @@ class PostgresEngine(object):
|
|||||||
self.synchronous_commit = database_config.get("synchronous_commit", True)
|
self.synchronous_commit = database_config.get("synchronous_commit", True)
|
||||||
self._version = None # unknown as yet
|
self._version = None # unknown as yet
|
||||||
|
|
||||||
def check_database(self, txn):
|
def check_database(self, db_conn, allow_outdated_version: bool = False):
|
||||||
txn.execute("SHOW SERVER_ENCODING")
|
|
||||||
rows = txn.fetchall()
|
|
||||||
if rows and rows[0][0] != "UTF8":
|
|
||||||
raise IncorrectDatabaseSetup(
|
|
||||||
"Database has incorrect encoding: '%s' instead of 'UTF8'\n"
|
|
||||||
"See docs/postgres.rst for more information." % (rows[0][0],)
|
|
||||||
)
|
|
||||||
|
|
||||||
def convert_param_style(self, sql):
|
|
||||||
return sql.replace("?", "%s")
|
|
||||||
|
|
||||||
def on_new_connection(self, db_conn):
|
|
||||||
|
|
||||||
# Get the version of PostgreSQL that we're using. As per the psycopg2
|
# Get the version of PostgreSQL that we're using. As per the psycopg2
|
||||||
# docs: The number is formed by converting the major, minor, and
|
# docs: The number is formed by converting the major, minor, and
|
||||||
# revision numbers into two-decimal-digit numbers and appending them
|
# revision numbers into two-decimal-digit numbers and appending them
|
||||||
@ -53,9 +40,22 @@ class PostgresEngine(object):
|
|||||||
self._version = db_conn.server_version
|
self._version = db_conn.server_version
|
||||||
|
|
||||||
# Are we on a supported PostgreSQL version?
|
# Are we on a supported PostgreSQL version?
|
||||||
if self._version < 90500:
|
if not allow_outdated_version and self._version < 90500:
|
||||||
raise RuntimeError("Synapse requires PostgreSQL 9.5+ or above.")
|
raise RuntimeError("Synapse requires PostgreSQL 9.5+ or above.")
|
||||||
|
|
||||||
|
with db_conn.cursor() as txn:
|
||||||
|
txn.execute("SHOW SERVER_ENCODING")
|
||||||
|
rows = txn.fetchall()
|
||||||
|
if rows and rows[0][0] != "UTF8":
|
||||||
|
raise IncorrectDatabaseSetup(
|
||||||
|
"Database has incorrect encoding: '%s' instead of 'UTF8'\n"
|
||||||
|
"See docs/postgres.rst for more information." % (rows[0][0],)
|
||||||
|
)
|
||||||
|
|
||||||
|
def convert_param_style(self, sql):
|
||||||
|
return sql.replace("?", "%s")
|
||||||
|
|
||||||
|
def on_new_connection(self, db_conn):
|
||||||
db_conn.set_isolation_level(
|
db_conn.set_isolation_level(
|
||||||
self.module.extensions.ISOLATION_LEVEL_REPEATABLE_READ
|
self.module.extensions.ISOLATION_LEVEL_REPEATABLE_READ
|
||||||
)
|
)
|
||||||
@ -119,8 +119,8 @@ class PostgresEngine(object):
|
|||||||
Returns:
|
Returns:
|
||||||
string
|
string
|
||||||
"""
|
"""
|
||||||
# note that this is a bit of a hack because it relies on on_new_connection
|
# note that this is a bit of a hack because it relies on check_database
|
||||||
# having been called at least once. Still, that should be a safe bet here.
|
# having been called. Still, that should be a safe bet here.
|
||||||
numver = self._version
|
numver = self._version
|
||||||
assert numver is not None
|
assert numver is not None
|
||||||
|
|
||||||
|
@ -53,8 +53,11 @@ class Sqlite3Engine(object):
|
|||||||
"""
|
"""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def check_database(self, txn):
|
def check_database(self, db_conn, allow_outdated_version: bool = False):
|
||||||
pass
|
if not allow_outdated_version:
|
||||||
|
version = self.module.sqlite_version_info
|
||||||
|
if version < (3, 11, 0):
|
||||||
|
raise RuntimeError("Synapse requires sqlite 3.11 or above.")
|
||||||
|
|
||||||
def convert_param_style(self, sql):
|
def convert_param_style(self, sql):
|
||||||
return sql
|
return sql
|
||||||
|
Loading…
Reference in New Issue
Block a user