From 7abaada35e1aa6a78d1aae1031bee82a4a99fcab Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Tue, 3 May 2022 12:31:57 +0100 Subject: [PATCH] Update config --- dendrite-config.yaml | 10 ++++++++++ setup/base/base.go | 21 ++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/dendrite-config.yaml b/dendrite-config.yaml index 1c11ef96d..1647af15d 100644 --- a/dendrite-config.yaml +++ b/dendrite-config.yaml @@ -54,6 +54,16 @@ global: # considered valid by other homeservers. key_validity_period: 168h0m0s + # Global database connection pool, for PostgreSQL monolith deployments only. If + # this section is populated then you can omit the "database" blocks in all other + # sections. For polylith deployments, or monolith deployments using SQLite databases, + # you must configure the "database" block for each component instead. + # database: + # connection_string: postgres://user:pass@hostname/database?sslmode=disable + # max_open_conns: 100 + # max_idle_conns: 5 + # conn_max_lifetime: -1 + # The server name to delegate server-server communications to, with optional port # e.g. localhost:443 well_known_server_name: "" diff --git a/setup/base/base.go b/setup/base/base.go index 1d15a9b89..27e2e3347 100644 --- a/setup/base/base.go +++ b/setup/base/base.go @@ -195,21 +195,16 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base var db *sql.DB var writer sqlutil.Writer if cfg.Global.DatabaseOptions.ConnectionString != "" { - if isMonolith { - switch { - case cfg.Global.DatabaseOptions.ConnectionString.IsSQLite(): - writer = sqlutil.NewExclusiveWriter() - default: - writer = sqlutil.NewDummyWriter() - } - db, err = sqlutil.Open(&cfg.Global.DatabaseOptions, writer) - if err != nil { - logrus.WithError(err).Panic("Failed to set up global database connections") - } - logrus.Info("Using global database connection pool") - } else { + if !isMonolith { logrus.Panic("Using a global database connection pool is not supported in polylith deployments") } + if cfg.Global.DatabaseOptions.ConnectionString.IsSQLite() { + logrus.Panic("Using a global database connection pool is not supported with SQLite databases") + } + if db, err = sqlutil.Open(&cfg.Global.DatabaseOptions, sqlutil.NewDummyWriter()); err != nil { + logrus.WithError(err).Panic("Failed to set up global database connections") + } + logrus.Debug("Using global database connection pool") } // Ideally we would only use SkipClean on routes which we know can allow '/' but due to