Setup tweaks

This commit is contained in:
Neil Alexander 2022-05-03 11:08:33 +01:00
parent 32f699c254
commit 622df1a8fc
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
2 changed files with 7 additions and 4 deletions

View file

@ -194,17 +194,20 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base
// have a separate database config of their own. // have a separate database config of their own.
var db *sql.DB var db *sql.DB
var writer sqlutil.Writer var writer sqlutil.Writer
if cfg.Global.DatabaseOptions != nil && isMonolith { if cfg.Global.DatabaseOptions.ConnectionString != "" && isMonolith {
switch { switch {
case cfg.Global.DatabaseOptions.ConnectionString.IsSQLite(): case cfg.Global.DatabaseOptions.ConnectionString.IsSQLite():
writer = sqlutil.NewExclusiveWriter() writer = sqlutil.NewExclusiveWriter()
default: default:
writer = sqlutil.NewDummyWriter() writer = sqlutil.NewDummyWriter()
} }
db, err = sqlutil.Open(cfg.Global.DatabaseOptions, writer) db, err = sqlutil.Open(&cfg.Global.DatabaseOptions, writer)
if err != nil { if err != nil {
logrus.WithError(err).Panic("Failed to set up global database connections") logrus.WithError(err).Panic("Failed to set up global database connections")
} }
logrus.Info("Using global database connection pool")
} else {
logrus.Info("Not using global database connection pool")
} }
// Ideally we would only use SkipClean on routes which we know can allow '/' but due to // Ideally we would only use SkipClean on routes which we know can allow '/' but due to
@ -249,7 +252,7 @@ func (b *BaseDendrite) Close() error {
// DatabaseConnection sets up a new database connection if appropriate, // DatabaseConnection sets up a new database connection if appropriate,
// or returns the global connection pool if not (monolith mode only). // or returns the global connection pool if not (monolith mode only).
func (b *BaseDendrite) DatabaseConnection(dbProperties *config.DatabaseOptions, writer sqlutil.Writer) (*sql.DB, sqlutil.Writer, error) { func (b *BaseDendrite) DatabaseConnection(dbProperties *config.DatabaseOptions, writer sqlutil.Writer) (*sql.DB, sqlutil.Writer, error) {
if dbProperties != nil || b == nil { if dbProperties.ConnectionString != "" || b == nil {
db, err := sqlutil.Open(dbProperties, writer) db, err := sqlutil.Open(dbProperties, writer)
return db, writer, err return db, writer, err
} }

View file

@ -39,7 +39,7 @@ type Global struct {
// connections will be used instead. This way we don't have to manage connection // connections will be used instead. This way we don't have to manage connection
// counts on a per-component basis, but can instead do it for the entire monolith. // counts on a per-component basis, but can instead do it for the entire monolith.
// In a polylith deployment, this will be ignored. // In a polylith deployment, this will be ignored.
DatabaseOptions *DatabaseOptions `yaml:"database"` DatabaseOptions DatabaseOptions `yaml:"database"`
// The server name to delegate server-server communications to, with optional port // The server name to delegate server-server communications to, with optional port
WellKnownServerName string `yaml:"well_known_server_name"` WellKnownServerName string `yaml:"well_known_server_name"`