Use pointer when passing the connection manager around (#3152)

As otherwise existing connections aren't reused.
This commit is contained in:
Till 2023-07-19 13:37:04 +02:00 committed by GitHub
parent a01faee17c
commit 297479ea49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 143 additions and 79 deletions

View File

@ -126,7 +126,7 @@ func (p *P2PMonolith) SetupPinecone(sk ed25519.PrivateKey) {
} }
func (p *P2PMonolith) SetupDendrite( func (p *P2PMonolith) SetupDendrite(
processCtx *process.ProcessContext, cfg *config.Dendrite, cm sqlutil.Connections, routers httputil.Routers, processCtx *process.ProcessContext, cfg *config.Dendrite, cm *sqlutil.Connections, routers httputil.Routers,
port int, enableRelaying bool, enableMetrics bool, enableWebsockets bool) { port int, enableRelaying bool, enableMetrics bool, enableWebsockets bool) {
p.port = port p.port = port

View File

@ -95,7 +95,7 @@ func AddPublicRoutes(
func NewInternalAPI( func NewInternalAPI(
processContext *process.ProcessContext, processContext *process.ProcessContext,
dendriteCfg *config.Dendrite, dendriteCfg *config.Dendrite,
cm sqlutil.Connections, cm *sqlutil.Connections,
natsInstance *jetstream.NATSInstance, natsInstance *jetstream.NATSInstance,
federation fclient.FederationClient, federation fclient.FederationClient,
rsAPI roomserverAPI.FederationRoomserverAPI, rsAPI roomserverAPI.FederationRoomserverAPI,

View File

@ -36,7 +36,7 @@ type Database struct {
} }
// NewDatabase opens a new database // NewDatabase opens a new database
func NewDatabase(ctx context.Context, conMan sqlutil.Connections, dbProperties *config.DatabaseOptions, cache caching.FederationCache, isLocalServerName func(spec.ServerName) bool) (*Database, error) { func NewDatabase(ctx context.Context, conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions, cache caching.FederationCache, isLocalServerName func(spec.ServerName) bool) (*Database, error) {
var d Database var d Database
var err error var err error
if d.db, d.writer, err = conMan.Connection(dbProperties); err != nil { if d.db, d.writer, err = conMan.Connection(dbProperties); err != nil {

View File

@ -34,7 +34,7 @@ type Database struct {
} }
// NewDatabase opens a new database // NewDatabase opens a new database
func NewDatabase(ctx context.Context, conMan sqlutil.Connections, dbProperties *config.DatabaseOptions, cache caching.FederationCache, isLocalServerName func(spec.ServerName) bool) (*Database, error) { func NewDatabase(ctx context.Context, conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions, cache caching.FederationCache, isLocalServerName func(spec.ServerName) bool) (*Database, error) {
var d Database var d Database
var err error var err error
if d.db, d.writer, err = conMan.Connection(dbProperties); err != nil { if d.db, d.writer, err = conMan.Connection(dbProperties); err != nil {

View File

@ -30,7 +30,7 @@ import (
) )
// NewDatabase opens a new database // NewDatabase opens a new database
func NewDatabase(ctx context.Context, conMan sqlutil.Connections, dbProperties *config.DatabaseOptions, cache caching.FederationCache, isLocalServerName func(spec.ServerName) bool) (Database, error) { func NewDatabase(ctx context.Context, conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions, cache caching.FederationCache, isLocalServerName func(spec.ServerName) bool) (Database, error) {
switch { switch {
case dbProperties.ConnectionString.IsSQLite(): case dbProperties.ConnectionString.IsSQLite():
return sqlite3.NewDatabase(ctx, conMan, dbProperties, cache, isLocalServerName) return sqlite3.NewDatabase(ctx, conMan, dbProperties, cache, isLocalServerName)

View File

@ -29,24 +29,26 @@ type Connections struct {
processContext *process.ProcessContext processContext *process.ProcessContext
} }
func NewConnectionManager(processCtx *process.ProcessContext, globalConfig config.DatabaseOptions) Connections { func NewConnectionManager(processCtx *process.ProcessContext, globalConfig config.DatabaseOptions) *Connections {
return Connections{ return &Connections{
globalConfig: globalConfig, globalConfig: globalConfig,
processContext: processCtx, processContext: processCtx,
} }
} }
func (c *Connections) Connection(dbProperties *config.DatabaseOptions) (*sql.DB, Writer, error) { func (c *Connections) Connection(dbProperties *config.DatabaseOptions) (*sql.DB, Writer, error) {
writer := NewDummyWriter()
if dbProperties.ConnectionString.IsSQLite() {
writer = NewExclusiveWriter()
}
var err error var err error
if dbProperties.ConnectionString == "" { if dbProperties.ConnectionString == "" {
// if no connectionString was provided, try the global one // if no connectionString was provided, try the global one
dbProperties = &c.globalConfig dbProperties = &c.globalConfig
} }
if dbProperties.ConnectionString != "" || c.db == nil {
writer := NewDummyWriter()
if dbProperties.ConnectionString.IsSQLite() {
writer = NewExclusiveWriter()
}
if dbProperties.ConnectionString != "" && c.db == nil {
// Open a new database connection using the supplied config. // Open a new database connection using the supplied config.
c.db, err = Open(dbProperties, writer) c.db, err = Open(dbProperties, writer)
if err != nil { if err != nil {

View File

@ -6,51 +6,113 @@ import (
"github.com/matrix-org/dendrite/internal/sqlutil" "github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/dendrite/setup/process"
"github.com/matrix-org/dendrite/test" "github.com/matrix-org/dendrite/test"
) )
func TestConnectionManager(t *testing.T) { func TestConnectionManager(t *testing.T) {
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
conStr, close := test.PrepareDBConnectionString(t, dbType)
t.Cleanup(close)
cm := sqlutil.NewConnectionManager(nil, config.DatabaseOptions{})
dbProps := &config.DatabaseOptions{ConnectionString: config.DataSource(conStr)} t.Run("component defined connection string", func(t *testing.T) {
db, writer, err := cm.Connection(dbProps) test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
if err != nil { conStr, close := test.PrepareDBConnectionString(t, dbType)
t.Fatal(err) t.Cleanup(close)
} cm := sqlutil.NewConnectionManager(nil, config.DatabaseOptions{})
switch dbType { dbProps := &config.DatabaseOptions{ConnectionString: config.DataSource(conStr)}
case test.DBTypeSQLite: db, writer, err := cm.Connection(dbProps)
_, ok := writer.(*sqlutil.ExclusiveWriter) if err != nil {
if !ok { t.Fatal(err)
t.Fatalf("expected exclusive writer")
} }
case test.DBTypePostgres:
_, ok := writer.(*sqlutil.DummyWriter) switch dbType {
if !ok { case test.DBTypeSQLite:
t.Fatalf("expected dummy writer") _, ok := writer.(*sqlutil.ExclusiveWriter)
if !ok {
t.Fatalf("expected exclusive writer")
}
case test.DBTypePostgres:
_, ok := writer.(*sqlutil.DummyWriter)
if !ok {
t.Fatalf("expected dummy writer")
}
} }
}
// test global db pool // reuse existing connection
dbGlobal, writerGlobal, err := cm.Connection(&config.DatabaseOptions{}) db2, writer2, err := cm.Connection(dbProps)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
if !reflect.DeepEqual(db, dbGlobal) { if !reflect.DeepEqual(db, db2) {
t.Fatalf("expected database connection to be reused") t.Fatalf("expected database connection to be reused")
} }
if !reflect.DeepEqual(writer, writerGlobal) { if !reflect.DeepEqual(writer, writer2) {
t.Fatalf("expected database writer to be reused") t.Fatalf("expected database writer to be reused")
} }
})
// test invalid connection string configured
cm2 := sqlutil.NewConnectionManager(nil, config.DatabaseOptions{})
_, _, err = cm2.Connection(&config.DatabaseOptions{ConnectionString: "http://"})
if err == nil {
t.Fatal("expected an error but got none")
}
}) })
t.Run("global connection pool", func(t *testing.T) {
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
conStr, close := test.PrepareDBConnectionString(t, dbType)
t.Cleanup(close)
cm := sqlutil.NewConnectionManager(nil, config.DatabaseOptions{ConnectionString: config.DataSource(conStr)})
dbProps := &config.DatabaseOptions{}
db, writer, err := cm.Connection(dbProps)
if err != nil {
t.Fatal(err)
}
switch dbType {
case test.DBTypeSQLite:
_, ok := writer.(*sqlutil.ExclusiveWriter)
if !ok {
t.Fatalf("expected exclusive writer")
}
case test.DBTypePostgres:
_, ok := writer.(*sqlutil.DummyWriter)
if !ok {
t.Fatalf("expected dummy writer")
}
}
// reuse existing connection
db2, writer2, err := cm.Connection(dbProps)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(db, db2) {
t.Fatalf("expected database connection to be reused")
}
if !reflect.DeepEqual(writer, writer2) {
t.Fatalf("expected database writer to be reused")
}
})
})
t.Run("shutdown", func(t *testing.T) {
test.WithAllDatabases(t, func(t *testing.T, dbType test.DBType) {
conStr, close := test.PrepareDBConnectionString(t, dbType)
t.Cleanup(close)
processCtx := process.NewProcessContext()
cm := sqlutil.NewConnectionManager(processCtx, config.DatabaseOptions{ConnectionString: config.DataSource(conStr)})
dbProps := &config.DatabaseOptions{}
_, _, err := cm.Connection(dbProps)
if err != nil {
t.Fatal(err)
}
processCtx.ShutdownDendrite()
processCtx.WaitForComponentsToFinish()
})
})
// test invalid connection string configured
cm2 := sqlutil.NewConnectionManager(nil, config.DatabaseOptions{})
_, _, err := cm2.Connection(&config.DatabaseOptions{ConnectionString: "http://"})
if err == nil {
t.Fatal("expected an error but got none")
}
} }

View File

@ -28,7 +28,7 @@ import (
// AddPublicRoutes sets up and registers HTTP handlers for the MediaAPI component. // AddPublicRoutes sets up and registers HTTP handlers for the MediaAPI component.
func AddPublicRoutes( func AddPublicRoutes(
mediaRouter *mux.Router, mediaRouter *mux.Router,
cm sqlutil.Connections, cm *sqlutil.Connections,
cfg *config.Dendrite, cfg *config.Dendrite,
userAPI userapi.MediaUserAPI, userAPI userapi.MediaUserAPI,
client *fclient.Client, client *fclient.Client,

View File

@ -24,7 +24,7 @@ import (
) )
// NewDatabase opens a postgres database. // NewDatabase opens a postgres database.
func NewDatabase(conMan sqlutil.Connections, dbProperties *config.DatabaseOptions) (*shared.Database, error) { func NewDatabase(conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions) (*shared.Database, error) {
db, writer, err := conMan.Connection(dbProperties) db, writer, err := conMan.Connection(dbProperties)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -23,7 +23,7 @@ import (
) )
// NewDatabase opens a SQLIte database. // NewDatabase opens a SQLIte database.
func NewDatabase(conMan sqlutil.Connections, dbProperties *config.DatabaseOptions) (*shared.Database, error) { func NewDatabase(conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions) (*shared.Database, error) {
db, writer, err := conMan.Connection(dbProperties) db, writer, err := conMan.Connection(dbProperties)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -27,7 +27,7 @@ import (
) )
// NewMediaAPIDatasource opens a database connection. // NewMediaAPIDatasource opens a database connection.
func NewMediaAPIDatasource(conMan sqlutil.Connections, dbProperties *config.DatabaseOptions) (Database, error) { func NewMediaAPIDatasource(conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions) (Database, error) {
switch { switch {
case dbProperties.ConnectionString.IsSQLite(): case dbProperties.ConnectionString.IsSQLite():
return sqlite3.NewDatabase(conMan, dbProperties) return sqlite3.NewDatabase(conMan, dbProperties)

View File

@ -53,7 +53,7 @@ func AddPublicRoutes(
func NewRelayInternalAPI( func NewRelayInternalAPI(
dendriteCfg *config.Dendrite, dendriteCfg *config.Dendrite,
cm sqlutil.Connections, cm *sqlutil.Connections,
fedClient fclient.FederationClient, fedClient fclient.FederationClient,
rsAPI rsAPI.RoomserverInternalAPI, rsAPI rsAPI.RoomserverInternalAPI,
keyRing *gomatrixserverlib.KeyRing, keyRing *gomatrixserverlib.KeyRing,

View File

@ -33,7 +33,7 @@ type Database struct {
// NewDatabase opens a new database // NewDatabase opens a new database
func NewDatabase( func NewDatabase(
conMan sqlutil.Connections, conMan *sqlutil.Connections,
dbProperties *config.DatabaseOptions, dbProperties *config.DatabaseOptions,
cache caching.FederationCache, cache caching.FederationCache,
isLocalServerName func(spec.ServerName) bool, isLocalServerName func(spec.ServerName) bool,

View File

@ -33,7 +33,7 @@ type Database struct {
// NewDatabase opens a new database // NewDatabase opens a new database
func NewDatabase( func NewDatabase(
conMan sqlutil.Connections, conMan *sqlutil.Connections,
dbProperties *config.DatabaseOptions, dbProperties *config.DatabaseOptions,
cache caching.FederationCache, cache caching.FederationCache,
isLocalServerName func(spec.ServerName) bool, isLocalServerName func(spec.ServerName) bool,

View File

@ -30,7 +30,7 @@ import (
// NewDatabase opens a new database // NewDatabase opens a new database
func NewDatabase( func NewDatabase(
conMan sqlutil.Connections, conMan *sqlutil.Connections,
dbProperties *config.DatabaseOptions, dbProperties *config.DatabaseOptions,
cache caching.FederationCache, cache caching.FederationCache,
isLocalServerName func(spec.ServerName) bool, isLocalServerName func(spec.ServerName) bool,

View File

@ -31,7 +31,7 @@ import (
func NewInternalAPI( func NewInternalAPI(
processContext *process.ProcessContext, processContext *process.ProcessContext,
cfg *config.Dendrite, cfg *config.Dendrite,
cm sqlutil.Connections, cm *sqlutil.Connections,
natsInstance *jetstream.NATSInstance, natsInstance *jetstream.NATSInstance,
caches caching.RoomServerCaches, caches caching.RoomServerCaches,
enableMetrics bool, enableMetrics bool,

View File

@ -37,7 +37,7 @@ type Database struct {
} }
// Open a postgres database. // Open a postgres database.
func Open(ctx context.Context, conMan sqlutil.Connections, dbProperties *config.DatabaseOptions, cache caching.RoomServerCaches) (*Database, error) { func Open(ctx context.Context, conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions, cache caching.RoomServerCaches) (*Database, error) {
var d Database var d Database
var err error var err error
db, writer, err := conMan.Connection(dbProperties) db, writer, err := conMan.Connection(dbProperties)

View File

@ -36,7 +36,7 @@ type Database struct {
} }
// Open a sqlite database. // Open a sqlite database.
func Open(ctx context.Context, conMan sqlutil.Connections, dbProperties *config.DatabaseOptions, cache caching.RoomServerCaches) (*Database, error) { func Open(ctx context.Context, conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions, cache caching.RoomServerCaches) (*Database, error) {
var d Database var d Database
var err error var err error
db, writer, err := conMan.Connection(dbProperties) db, writer, err := conMan.Connection(dbProperties)

View File

@ -29,7 +29,7 @@ import (
) )
// Open opens a database connection. // Open opens a database connection.
func Open(ctx context.Context, conMan sqlutil.Connections, dbProperties *config.DatabaseOptions, cache caching.RoomServerCaches) (Database, error) { func Open(ctx context.Context, conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions, cache caching.RoomServerCaches) (Database, error) {
switch { switch {
case dbProperties.ConnectionString.IsSQLite(): case dbProperties.ConnectionString.IsSQLite():
return sqlite3.Open(ctx, conMan, dbProperties, cache) return sqlite3.Open(ctx, conMan, dbProperties, cache)

View File

@ -61,7 +61,7 @@ func (m *Monolith) AddAllPublicRoutes(
processCtx *process.ProcessContext, processCtx *process.ProcessContext,
cfg *config.Dendrite, cfg *config.Dendrite,
routers httputil.Routers, routers httputil.Routers,
cm sqlutil.Connections, cm *sqlutil.Connections,
natsInstance *jetstream.NATSInstance, natsInstance *jetstream.NATSInstance,
caches *caching.Caches, caches *caching.Caches,
enableMetrics bool, enableMetrics bool,

View File

@ -105,7 +105,7 @@ func toClientResponse(ctx context.Context, res *MSC2836EventRelationshipsRespons
// Enable this MSC // Enable this MSC
func Enable( func Enable(
cfg *config.Dendrite, cm sqlutil.Connections, routers httputil.Routers, rsAPI roomserver.RoomserverInternalAPI, fsAPI fs.FederationInternalAPI, cfg *config.Dendrite, cm *sqlutil.Connections, routers httputil.Routers, rsAPI roomserver.RoomserverInternalAPI, fsAPI fs.FederationInternalAPI,
userAPI userapi.UserInternalAPI, keyRing gomatrixserverlib.JSONVerifier, userAPI userapi.UserInternalAPI, keyRing gomatrixserverlib.JSONVerifier,
) error { ) error {
db, err := NewDatabase(cm, &cfg.MSCs.Database) db, err := NewDatabase(cm, &cfg.MSCs.Database)

View File

@ -59,14 +59,14 @@ type DB struct {
} }
// NewDatabase loads the database for msc2836 // NewDatabase loads the database for msc2836
func NewDatabase(conMan sqlutil.Connections, dbOpts *config.DatabaseOptions) (Database, error) { func NewDatabase(conMan *sqlutil.Connections, dbOpts *config.DatabaseOptions) (Database, error) {
if dbOpts.ConnectionString.IsPostgres() { if dbOpts.ConnectionString.IsPostgres() {
return newPostgresDatabase(conMan, dbOpts) return newPostgresDatabase(conMan, dbOpts)
} }
return newSQLiteDatabase(conMan, dbOpts) return newSQLiteDatabase(conMan, dbOpts)
} }
func newPostgresDatabase(conMan sqlutil.Connections, dbOpts *config.DatabaseOptions) (Database, error) { func newPostgresDatabase(conMan *sqlutil.Connections, dbOpts *config.DatabaseOptions) (Database, error) {
d := DB{} d := DB{}
var err error var err error
if d.db, d.writer, err = conMan.Connection(dbOpts); err != nil { if d.db, d.writer, err = conMan.Connection(dbOpts); err != nil {
@ -144,7 +144,7 @@ func newPostgresDatabase(conMan sqlutil.Connections, dbOpts *config.DatabaseOpti
return &d, err return &d, err
} }
func newSQLiteDatabase(conMan sqlutil.Connections, dbOpts *config.DatabaseOptions) (Database, error) { func newSQLiteDatabase(conMan *sqlutil.Connections, dbOpts *config.DatabaseOptions) (Database, error) {
d := DB{} d := DB{}
var err error var err error
if d.db, d.writer, err = conMan.Connection(dbOpts); err != nil { if d.db, d.writer, err = conMan.Connection(dbOpts); err != nil {

View File

@ -30,7 +30,7 @@ import (
) )
// Enable MSCs - returns an error on unknown MSCs // Enable MSCs - returns an error on unknown MSCs
func Enable(cfg *config.Dendrite, cm sqlutil.Connections, routers httputil.Routers, monolith *setup.Monolith, caches *caching.Caches) error { func Enable(cfg *config.Dendrite, cm *sqlutil.Connections, routers httputil.Routers, monolith *setup.Monolith, caches *caching.Caches) error {
for _, msc := range cfg.MSCs.MSCs { for _, msc := range cfg.MSCs.MSCs {
util.GetLogger(context.Background()).WithField("msc", msc).Info("Enabling MSC") util.GetLogger(context.Background()).WithField("msc", msc).Info("Enabling MSC")
if err := EnableMSC(cfg, cm, routers, monolith, msc, caches); err != nil { if err := EnableMSC(cfg, cm, routers, monolith, msc, caches); err != nil {
@ -40,7 +40,7 @@ func Enable(cfg *config.Dendrite, cm sqlutil.Connections, routers httputil.Route
return nil return nil
} }
func EnableMSC(cfg *config.Dendrite, cm sqlutil.Connections, routers httputil.Routers, monolith *setup.Monolith, msc string, caches *caching.Caches) error { func EnableMSC(cfg *config.Dendrite, cm *sqlutil.Connections, routers httputil.Routers, monolith *setup.Monolith, msc string, caches *caching.Caches) error {
switch msc { switch msc {
case "msc2836": case "msc2836":
return msc2836.Enable(cfg, cm, routers, monolith.RoomserverAPI, monolith.FederationAPI, monolith.UserAPI, monolith.KeyRing) return msc2836.Enable(cfg, cm, routers, monolith.RoomserverAPI, monolith.FederationAPI, monolith.UserAPI, monolith.KeyRing)

View File

@ -36,7 +36,7 @@ type SyncServerDatasource struct {
} }
// NewDatabase creates a new sync server database // NewDatabase creates a new sync server database
func NewDatabase(ctx context.Context, cm sqlutil.Connections, dbProperties *config.DatabaseOptions) (*SyncServerDatasource, error) { func NewDatabase(ctx context.Context, cm *sqlutil.Connections, dbProperties *config.DatabaseOptions) (*SyncServerDatasource, error) {
var d SyncServerDatasource var d SyncServerDatasource
var err error var err error
if d.db, d.writer, err = cm.Connection(dbProperties); err != nil { if d.db, d.writer, err = cm.Connection(dbProperties); err != nil {

View File

@ -36,7 +36,7 @@ type SyncServerDatasource struct {
// NewDatabase creates a new sync server database // NewDatabase creates a new sync server database
// nolint: gocyclo // nolint: gocyclo
func NewDatabase(ctx context.Context, conMan sqlutil.Connections, dbProperties *config.DatabaseOptions) (*SyncServerDatasource, error) { func NewDatabase(ctx context.Context, conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions) (*SyncServerDatasource, error) {
var d SyncServerDatasource var d SyncServerDatasource
var err error var err error

View File

@ -28,7 +28,7 @@ import (
) )
// NewSyncServerDatasource opens a database connection. // NewSyncServerDatasource opens a database connection.
func NewSyncServerDatasource(ctx context.Context, conMan sqlutil.Connections, dbProperties *config.DatabaseOptions) (Database, error) { func NewSyncServerDatasource(ctx context.Context, conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions) (Database, error) {
switch { switch {
case dbProperties.ConnectionString.IsSQLite(): case dbProperties.ConnectionString.IsSQLite():
return sqlite3.NewDatabase(ctx, conMan, dbProperties) return sqlite3.NewDatabase(ctx, conMan, dbProperties)

View File

@ -45,7 +45,7 @@ func AddPublicRoutes(
processContext *process.ProcessContext, processContext *process.ProcessContext,
routers httputil.Routers, routers httputil.Routers,
dendriteCfg *config.Dendrite, dendriteCfg *config.Dendrite,
cm sqlutil.Connections, cm *sqlutil.Connections,
natsInstance *jetstream.NATSInstance, natsInstance *jetstream.NATSInstance,
userAPI userapi.SyncUserAPI, userAPI userapi.SyncUserAPI,
rsAPI api.SyncRoomserverAPI, rsAPI api.SyncRoomserverAPI,

View File

@ -31,7 +31,7 @@ import (
) )
// NewDatabase creates a new accounts and profiles database // NewDatabase creates a new accounts and profiles database
func NewDatabase(ctx context.Context, conMan sqlutil.Connections, dbProperties *config.DatabaseOptions, serverName spec.ServerName, bcryptCost int, openIDTokenLifetimeMS int64, loginTokenLifetime time.Duration, serverNoticesLocalpart string) (*shared.Database, error) { func NewDatabase(ctx context.Context, conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions, serverName spec.ServerName, bcryptCost int, openIDTokenLifetimeMS int64, loginTokenLifetime time.Duration, serverNoticesLocalpart string) (*shared.Database, error) {
db, writer, err := conMan.Connection(dbProperties) db, writer, err := conMan.Connection(dbProperties)
if err != nil { if err != nil {
return nil, err return nil, err
@ -140,7 +140,7 @@ func NewDatabase(ctx context.Context, conMan sqlutil.Connections, dbProperties *
}, nil }, nil
} }
func NewKeyDatabase(conMan sqlutil.Connections, dbProperties *config.DatabaseOptions) (*shared.KeyDatabase, error) { func NewKeyDatabase(conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions) (*shared.KeyDatabase, error) {
db, writer, err := conMan.Connection(dbProperties) db, writer, err := conMan.Connection(dbProperties)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -29,7 +29,7 @@ import (
) )
// NewUserDatabase creates a new accounts and profiles database // NewUserDatabase creates a new accounts and profiles database
func NewUserDatabase(ctx context.Context, conMan sqlutil.Connections, dbProperties *config.DatabaseOptions, serverName spec.ServerName, bcryptCost int, openIDTokenLifetimeMS int64, loginTokenLifetime time.Duration, serverNoticesLocalpart string) (*shared.Database, error) { func NewUserDatabase(ctx context.Context, conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions, serverName spec.ServerName, bcryptCost int, openIDTokenLifetimeMS int64, loginTokenLifetime time.Duration, serverNoticesLocalpart string) (*shared.Database, error) {
db, writer, err := conMan.Connection(dbProperties) db, writer, err := conMan.Connection(dbProperties)
if err != nil { if err != nil {
return nil, err return nil, err
@ -137,7 +137,7 @@ func NewUserDatabase(ctx context.Context, conMan sqlutil.Connections, dbProperti
}, nil }, nil
} }
func NewKeyDatabase(conMan sqlutil.Connections, dbProperties *config.DatabaseOptions) (*shared.KeyDatabase, error) { func NewKeyDatabase(conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions) (*shared.KeyDatabase, error) {
db, writer, err := conMan.Connection(dbProperties) db, writer, err := conMan.Connection(dbProperties)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -34,7 +34,7 @@ import (
// and sets postgres connection parameters // and sets postgres connection parameters
func NewUserDatabase( func NewUserDatabase(
ctx context.Context, ctx context.Context,
conMan sqlutil.Connections, conMan *sqlutil.Connections,
dbProperties *config.DatabaseOptions, dbProperties *config.DatabaseOptions,
serverName spec.ServerName, serverName spec.ServerName,
bcryptCost int, bcryptCost int,
@ -54,7 +54,7 @@ func NewUserDatabase(
// NewKeyDatabase opens a new Postgres or Sqlite database (base on dataSourceName) scheme) // NewKeyDatabase opens a new Postgres or Sqlite database (base on dataSourceName) scheme)
// and sets postgres connection parameters. // and sets postgres connection parameters.
func NewKeyDatabase(conMan sqlutil.Connections, dbProperties *config.DatabaseOptions) (KeyDatabase, error) { func NewKeyDatabase(conMan *sqlutil.Connections, dbProperties *config.DatabaseOptions) (KeyDatabase, error) {
switch { switch {
case dbProperties.ConnectionString.IsSQLite(): case dbProperties.ConnectionString.IsSQLite():
return sqlite3.NewKeyDatabase(conMan, dbProperties) return sqlite3.NewKeyDatabase(conMan, dbProperties)

View File

@ -39,7 +39,7 @@ import (
func NewInternalAPI( func NewInternalAPI(
processContext *process.ProcessContext, processContext *process.ProcessContext,
dendriteCfg *config.Dendrite, dendriteCfg *config.Dendrite,
cm sqlutil.Connections, cm *sqlutil.Connections,
natsInstance *jetstream.NATSInstance, natsInstance *jetstream.NATSInstance,
rsAPI rsapi.UserRoomserverAPI, rsAPI rsapi.UserRoomserverAPI,
fedClient fedsenderapi.KeyserverFederationAPI, fedClient fedsenderapi.KeyserverFederationAPI,