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

Move database config from apps into HomeServer object #6511

Merged
merged 4 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6511.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move database config from apps into HomeServer object.
33 changes: 6 additions & 27 deletions scripts-dev/update_database
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ from synapse.config.homeserver import HomeServerConfig
from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.server import HomeServer
from synapse.storage import DataStore
from synapse.storage.engines import create_engine
from synapse.storage.prepare_database import prepare_database

logger = logging.getLogger("update_database")
Expand All @@ -35,21 +34,11 @@ logger = logging.getLogger("update_database")
class MockHomeserver(HomeServer):
DATASTORE_CLASS = DataStore

def __init__(self, config, database_engine, db_conn, **kwargs):
def __init__(self, config, **kwargs):
super(MockHomeserver, self).__init__(
config.server_name,
reactor=reactor,
config=config,
database_engine=database_engine,
**kwargs
config.server_name, reactor=reactor, config=config, **kwargs
)

self.database_engine = database_engine
self.db_conn = db_conn

def get_db_conn(self):
return self.db_conn


if __name__ == "__main__":
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -85,24 +74,14 @@ if __name__ == "__main__":
config = HomeServerConfig()
config.parse_config_dict(hs_config, "", "")

# Create the database engine and a connection to it.
database_engine = create_engine(config.database_config)
db_conn = database_engine.module.connect(
**{
k: v
for k, v in config.database_config.get("args", {}).items()
if not k.startswith("cp_")
}
)
# Instantiate and initialise the homeserver object.
hs = MockHomeserver(config)

db_conn = hs.get_db_conn()
# Update the database to the latest schema.
prepare_database(db_conn, database_engine, config=config)
prepare_database(db_conn, hs.database_engine, config=config)
db_conn.commit()

# Instantiate and initialise the homeserver object.
hs = MockHomeserver(
config, database_engine, db_conn, db_config=config.database_config,
)
# setup instantiates the store within the homeserver object.
hs.setup()
store = hs.get_datastore()
Expand Down
5 changes: 0 additions & 5 deletions synapse/app/admin_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
from synapse.replication.slave.storage.room import RoomStore
from synapse.replication.tcp.client import ReplicationClientHandler
from synapse.server import HomeServer
from synapse.storage.engines import create_engine
from synapse.util.logcontext import LoggingContext
from synapse.util.versionstring import get_version_string

Expand Down Expand Up @@ -229,14 +228,10 @@ def start(config_options):

synapse.events.USE_FROZEN_DICTS = config.use_frozen_dicts

database_engine = create_engine(config.database_config)

ss = AdminCmdServer(
config.server_name,
db_config=config.database_config,
config=config,
version_string="Synapse/" + get_version_string(synapse),
database_engine=database_engine,
)

setup_logging(ss, config, use_worker_options=True)
Expand Down
5 changes: 0 additions & 5 deletions synapse/app/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from synapse.replication.slave.storage.registration import SlavedRegistrationStore
from synapse.replication.tcp.client import ReplicationClientHandler
from synapse.server import HomeServer
from synapse.storage.engines import create_engine
from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.manhole import manhole
from synapse.util.versionstring import get_version_string
Expand Down Expand Up @@ -143,8 +142,6 @@ def start(config_options):

events.USE_FROZEN_DICTS = config.use_frozen_dicts

database_engine = create_engine(config.database_config)

if config.notify_appservices:
sys.stderr.write(
"\nThe appservices must be disabled in the main synapse process"
Expand All @@ -159,10 +156,8 @@ def start(config_options):

ps = AppserviceServer(
config.server_name,
db_config=config.database_config,
config=config,
version_string="Synapse/" + get_version_string(synapse),
database_engine=database_engine,
)

setup_logging(ps, config, use_worker_options=True)
Expand Down
5 changes: 0 additions & 5 deletions synapse/app/client_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
from synapse.rest.client.v2_alpha.register import RegisterRestServlet
from synapse.rest.client.versions import VersionsRestServlet
from synapse.server import HomeServer
from synapse.storage.engines import create_engine
from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.manhole import manhole
from synapse.util.versionstring import get_version_string
Expand Down Expand Up @@ -181,14 +180,10 @@ def start(config_options):

events.USE_FROZEN_DICTS = config.use_frozen_dicts

database_engine = create_engine(config.database_config)

ss = ClientReaderServer(
config.server_name,
db_config=config.database_config,
config=config,
version_string="Synapse/" + get_version_string(synapse),
database_engine=database_engine,
)

setup_logging(ss, config, use_worker_options=True)
Expand Down
5 changes: 0 additions & 5 deletions synapse/app/event_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
)
from synapse.server import HomeServer
from synapse.storage.data_stores.main.user_directory import UserDirectoryStore
from synapse.storage.engines import create_engine
from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.manhole import manhole
from synapse.util.versionstring import get_version_string
Expand Down Expand Up @@ -180,14 +179,10 @@ def start(config_options):

events.USE_FROZEN_DICTS = config.use_frozen_dicts

database_engine = create_engine(config.database_config)

ss = EventCreatorServer(
config.server_name,
db_config=config.database_config,
config=config,
version_string="Synapse/" + get_version_string(synapse),
database_engine=database_engine,
)

setup_logging(ss, config, use_worker_options=True)
Expand Down
5 changes: 0 additions & 5 deletions synapse/app/federation_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
from synapse.replication.tcp.client import ReplicationClientHandler
from synapse.rest.key.v2 import KeyApiV2Resource
from synapse.server import HomeServer
from synapse.storage.engines import create_engine
from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.manhole import manhole
from synapse.util.versionstring import get_version_string
Expand Down Expand Up @@ -162,14 +161,10 @@ def start(config_options):

events.USE_FROZEN_DICTS = config.use_frozen_dicts

database_engine = create_engine(config.database_config)

ss = FederationReaderServer(
config.server_name,
db_config=config.database_config,
config=config,
version_string="Synapse/" + get_version_string(synapse),
database_engine=database_engine,
)

setup_logging(ss, config, use_worker_options=True)
Expand Down
5 changes: 0 additions & 5 deletions synapse/app/federation_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
from synapse.replication.tcp.streams._base import ReceiptsStream
from synapse.server import HomeServer
from synapse.storage.database import Database
from synapse.storage.engines import create_engine
from synapse.types import ReadReceipt
from synapse.util.async_helpers import Linearizer
from synapse.util.httpresourcetree import create_resource_tree
Expand Down Expand Up @@ -174,8 +173,6 @@ def start(config_options):

events.USE_FROZEN_DICTS = config.use_frozen_dicts

database_engine = create_engine(config.database_config)

if config.send_federation:
sys.stderr.write(
"\nThe send_federation must be disabled in the main synapse process"
Expand All @@ -190,10 +187,8 @@ def start(config_options):

ss = FederationSenderServer(
config.server_name,
db_config=config.database_config,
config=config,
version_string="Synapse/" + get_version_string(synapse),
database_engine=database_engine,
)

setup_logging(ss, config, use_worker_options=True)
Expand Down
5 changes: 0 additions & 5 deletions synapse/app/frontend_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from synapse.replication.tcp.client import ReplicationClientHandler
from synapse.rest.client.v2_alpha._base import client_patterns
from synapse.server import HomeServer
from synapse.storage.engines import create_engine
from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.manhole import manhole
from synapse.util.versionstring import get_version_string
Expand Down Expand Up @@ -234,14 +233,10 @@ def start(config_options):

events.USE_FROZEN_DICTS = config.use_frozen_dicts

database_engine = create_engine(config.database_config)

ss = FrontendProxyServer(
config.server_name,
db_config=config.database_config,
config=config,
version_string="Synapse/" + get_version_string(synapse),
database_engine=database_engine,
)

setup_logging(ss, config, use_worker_options=True)
Expand Down
7 changes: 1 addition & 6 deletions synapse/app/homeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
from synapse.rest.well_known import WellKnownResource
from synapse.server import HomeServer
from synapse.storage import DataStore
from synapse.storage.engines import IncorrectDatabaseSetup, create_engine
from synapse.storage.engines import IncorrectDatabaseSetup
from synapse.storage.prepare_database import UpgradeDatabaseException
from synapse.util.caches import CACHE_SIZE_FACTOR
from synapse.util.httpresourcetree import create_resource_tree
Expand Down Expand Up @@ -328,15 +328,10 @@ def setup(config_options):

events.USE_FROZEN_DICTS = config.use_frozen_dicts

database_engine = create_engine(config.database_config)
config.database_config["args"]["cp_openfun"] = database_engine.on_new_connection

hs = SynapseHomeServer(
config.server_name,
db_config=config.database_config,
config=config,
version_string="Synapse/" + get_version_string(synapse),
database_engine=database_engine,
)

synapse.config.logger.setup_logging(hs, config, use_worker_options=False)
Expand Down
5 changes: 0 additions & 5 deletions synapse/app/media_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
from synapse.rest.media.v0.content_repository import ContentRepoResource
from synapse.server import HomeServer
from synapse.storage.data_stores.main.media_repository import MediaRepositoryStore
from synapse.storage.engines import create_engine
from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.manhole import manhole
from synapse.util.versionstring import get_version_string
Expand Down Expand Up @@ -157,14 +156,10 @@ def start(config_options):

events.USE_FROZEN_DICTS = config.use_frozen_dicts

database_engine = create_engine(config.database_config)

ss = MediaRepositoryServer(
config.server_name,
db_config=config.database_config,
config=config,
version_string="Synapse/" + get_version_string(synapse),
database_engine=database_engine,
)

setup_logging(ss, config, use_worker_options=True)
Expand Down
5 changes: 0 additions & 5 deletions synapse/app/pusher.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from synapse.replication.tcp.client import ReplicationClientHandler
from synapse.server import HomeServer
from synapse.storage import DataStore
from synapse.storage.engines import create_engine
from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.manhole import manhole
from synapse.util.versionstring import get_version_string
Expand Down Expand Up @@ -198,14 +197,10 @@ def start(config_options):
# Force the pushers to start since they will be disabled in the main config
config.start_pushers = True

database_engine = create_engine(config.database_config)

ps = PusherServer(
config.server_name,
db_config=config.database_config,
config=config,
version_string="Synapse/" + get_version_string(synapse),
database_engine=database_engine,
)

setup_logging(ps, config, use_worker_options=True)
Expand Down
5 changes: 0 additions & 5 deletions synapse/app/synchrotron.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
from synapse.rest.client.v2_alpha import sync
from synapse.server import HomeServer
from synapse.storage.data_stores.main.presence import UserPresenceState
from synapse.storage.engines import create_engine
from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.manhole import manhole
from synapse.util.stringutils import random_string
Expand Down Expand Up @@ -437,14 +436,10 @@ def start(config_options):

synapse.events.USE_FROZEN_DICTS = config.use_frozen_dicts

database_engine = create_engine(config.database_config)

ss = SynchrotronServer(
config.server_name,
db_config=config.database_config,
config=config,
version_string="Synapse/" + get_version_string(synapse),
database_engine=database_engine,
application_service_handler=SynchrotronApplicationService(),
)

Expand Down
5 changes: 0 additions & 5 deletions synapse/app/user_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
from synapse.server import HomeServer
from synapse.storage.data_stores.main.user_directory import UserDirectoryStore
from synapse.storage.database import Database
from synapse.storage.engines import create_engine
from synapse.util.caches.stream_change_cache import StreamChangeCache
from synapse.util.httpresourcetree import create_resource_tree
from synapse.util.manhole import manhole
Expand Down Expand Up @@ -200,8 +199,6 @@ def start(config_options):

events.USE_FROZEN_DICTS = config.use_frozen_dicts

database_engine = create_engine(config.database_config)

if config.update_user_directory:
sys.stderr.write(
"\nThe update_user_directory must be disabled in the main synapse process"
Expand All @@ -216,10 +213,8 @@ def start(config_options):

ss = UserDirectoryServer(
config.server_name,
db_config=config.database_config,
config=config,
version_string="Synapse/" + get_version_string(synapse),
database_engine=database_engine,
)

setup_logging(ss, config, use_worker_options=True)
Expand Down
Loading