mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Global database connection pool (for monolith mode) (#2411)
* Allow monolith components to share a single database pool * Don't yell about missing connection strings * Rename field * Setup tweaks * Fix panic * Improve configuration checks * Update config * Fix lint errors * Update comments
This commit is contained in:
parent
979a551f1e
commit
4ad5f9c982
71 changed files with 345 additions and 240 deletions
|
@ -25,8 +25,8 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/matrix-org/dendrite/setup"
|
||||
"github.com/matrix-org/dendrite/setup/base"
|
||||
"github.com/matrix-org/dendrite/userapi/api"
|
||||
"github.com/matrix-org/dendrite/userapi/storage"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
@ -99,8 +99,18 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
b := base.NewBaseDendrite(cfg, "Monolith")
|
||||
accountDB := b.CreateAccountsDB()
|
||||
accountDB, err := storage.NewUserAPIDatabase(
|
||||
nil,
|
||||
&cfg.UserAPI.AccountDatabase,
|
||||
cfg.Global.ServerName,
|
||||
cfg.UserAPI.BCryptCost,
|
||||
cfg.UserAPI.OpenIDTokenLifetimeMS,
|
||||
0, // TODO
|
||||
cfg.Global.ServerNotices.LocalPart,
|
||||
)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Fatalln("Failed to connect to the database")
|
||||
}
|
||||
|
||||
accType := api.AccountTypeUser
|
||||
if *isAdmin {
|
||||
|
|
|
@ -149,7 +149,6 @@ func main() {
|
|||
base := base.NewBaseDendrite(cfg, "Monolith")
|
||||
defer base.Close() // nolint: errcheck
|
||||
|
||||
accountDB := base.CreateAccountsDB()
|
||||
federation := conn.CreateFederationClient(base, pQUIC)
|
||||
|
||||
serverKeyAPI := &signing.YggdrasilKeys{}
|
||||
|
@ -162,7 +161,7 @@ func main() {
|
|||
)
|
||||
|
||||
keyAPI := keyserver.NewInternalAPI(base, &base.Cfg.KeyServer, fsAPI)
|
||||
userAPI := userapi.NewInternalAPI(base, accountDB, &cfg.UserAPI, nil, keyAPI, rsAPI, base.PushGatewayHTTPClient())
|
||||
userAPI := userapi.NewInternalAPI(base, &cfg.UserAPI, nil, keyAPI, rsAPI, base.PushGatewayHTTPClient())
|
||||
keyAPI.SetUserAPI(userAPI)
|
||||
|
||||
asAPI := appservice.NewInternalAPI(base, userAPI, rsAPI)
|
||||
|
@ -174,7 +173,6 @@ func main() {
|
|||
|
||||
monolith := setup.Monolith{
|
||||
Config: base.Cfg,
|
||||
AccountDB: accountDB,
|
||||
Client: conn.CreateClient(base, pQUIC),
|
||||
FedClient: federation,
|
||||
KeyRing: keyRing,
|
||||
|
@ -188,7 +186,7 @@ func main() {
|
|||
ExtUserDirectoryProvider: userProvider,
|
||||
}
|
||||
monolith.AddAllPublicRoutes(
|
||||
base.ProcessContext,
|
||||
base,
|
||||
base.PublicClientAPIMux,
|
||||
base.PublicFederationAPIMux,
|
||||
base.PublicKeyAPIMux,
|
||||
|
|
|
@ -104,7 +104,6 @@ func main() {
|
|||
base := base.NewBaseDendrite(cfg, "Monolith")
|
||||
defer base.Close() // nolint: errcheck
|
||||
|
||||
accountDB := base.CreateAccountsDB()
|
||||
federation := ygg.CreateFederationClient(base)
|
||||
|
||||
serverKeyAPI := &signing.YggdrasilKeys{}
|
||||
|
@ -117,7 +116,7 @@ func main() {
|
|||
)
|
||||
rsAPI := rsComponent
|
||||
|
||||
userAPI := userapi.NewInternalAPI(base, accountDB, &cfg.UserAPI, nil, keyAPI, rsAPI, base.PushGatewayHTTPClient())
|
||||
userAPI := userapi.NewInternalAPI(base, &cfg.UserAPI, nil, keyAPI, rsAPI, base.PushGatewayHTTPClient())
|
||||
keyAPI.SetUserAPI(userAPI)
|
||||
|
||||
asAPI := appservice.NewInternalAPI(base, userAPI, rsAPI)
|
||||
|
@ -130,7 +129,6 @@ func main() {
|
|||
|
||||
monolith := setup.Monolith{
|
||||
Config: base.Cfg,
|
||||
AccountDB: accountDB,
|
||||
Client: ygg.CreateClient(base),
|
||||
FedClient: federation,
|
||||
KeyRing: keyRing,
|
||||
|
@ -145,7 +143,7 @@ func main() {
|
|||
),
|
||||
}
|
||||
monolith.AddAllPublicRoutes(
|
||||
base.ProcessContext,
|
||||
base,
|
||||
base.PublicClientAPIMux,
|
||||
base.PublicFederationAPIMux,
|
||||
base.PublicKeyAPIMux,
|
||||
|
|
|
@ -71,7 +71,6 @@ func main() {
|
|||
base := basepkg.NewBaseDendrite(cfg, "Monolith", options...)
|
||||
defer base.Close() // nolint: errcheck
|
||||
|
||||
accountDB := base.CreateAccountsDB()
|
||||
federation := base.CreateFederationClient()
|
||||
|
||||
rsImpl := roomserver.NewInternalAPI(base)
|
||||
|
@ -104,7 +103,7 @@ func main() {
|
|||
}
|
||||
|
||||
pgClient := base.PushGatewayHTTPClient()
|
||||
userImpl := userapi.NewInternalAPI(base, accountDB, &cfg.UserAPI, cfg.Derived.ApplicationServices, keyAPI, rsAPI, pgClient)
|
||||
userImpl := userapi.NewInternalAPI(base, &cfg.UserAPI, cfg.Derived.ApplicationServices, keyAPI, rsAPI, pgClient)
|
||||
userAPI := userImpl
|
||||
if base.UseHTTPAPIs {
|
||||
userapi.AddInternalRoutes(base.InternalAPIMux, userAPI)
|
||||
|
@ -135,7 +134,6 @@ func main() {
|
|||
|
||||
monolith := setup.Monolith{
|
||||
Config: base.Cfg,
|
||||
AccountDB: accountDB,
|
||||
Client: base.CreateClient(),
|
||||
FedClient: federation,
|
||||
KeyRing: keyRing,
|
||||
|
@ -146,7 +144,7 @@ func main() {
|
|||
KeyAPI: keyAPI,
|
||||
}
|
||||
monolith.AddAllPublicRoutes(
|
||||
base.ProcessContext,
|
||||
base,
|
||||
base.PublicClientAPIMux,
|
||||
base.PublicFederationAPIMux,
|
||||
base.PublicKeyAPIMux,
|
||||
|
|
|
@ -24,7 +24,10 @@ func MediaAPI(base *basepkg.BaseDendrite, cfg *config.Dendrite) {
|
|||
userAPI := base.UserAPIClient()
|
||||
client := base.CreateClient()
|
||||
|
||||
mediaapi.AddPublicRoutes(base.PublicMediaAPIMux, &base.Cfg.MediaAPI, &base.Cfg.ClientAPI.RateLimiting, userAPI, client)
|
||||
mediaapi.AddPublicRoutes(
|
||||
base, base.PublicMediaAPIMux, &base.Cfg.MediaAPI, &base.Cfg.ClientAPI.RateLimiting,
|
||||
userAPI, client,
|
||||
)
|
||||
|
||||
base.SetupAndServeHTTP(
|
||||
base.Cfg.MediaAPI.InternalAPI.Listen,
|
||||
|
|
|
@ -27,7 +27,7 @@ func SyncAPI(base *basepkg.BaseDendrite, cfg *config.Dendrite) {
|
|||
rsAPI := base.RoomserverHTTPClient()
|
||||
|
||||
syncapi.AddPublicRoutes(
|
||||
base.ProcessContext,
|
||||
base,
|
||||
base.PublicClientAPIMux, userAPI, rsAPI,
|
||||
base.KeyServerHTTPClient(),
|
||||
federation, &cfg.SyncAPI,
|
||||
|
|
|
@ -21,10 +21,8 @@ import (
|
|||
)
|
||||
|
||||
func UserAPI(base *basepkg.BaseDendrite, cfg *config.Dendrite) {
|
||||
accountDB := base.CreateAccountsDB()
|
||||
|
||||
userAPI := userapi.NewInternalAPI(
|
||||
base, accountDB, &cfg.UserAPI, cfg.Derived.ApplicationServices,
|
||||
base, &cfg.UserAPI, cfg.Derived.ApplicationServices,
|
||||
base.KeyServerHTTPClient(), base.RoomserverHTTPClient(),
|
||||
base.PushGatewayHTTPClient(),
|
||||
)
|
||||
|
|
|
@ -180,7 +180,6 @@ func startup() {
|
|||
base := base.NewBaseDendrite(cfg, "Monolith")
|
||||
defer base.Close() // nolint: errcheck
|
||||
|
||||
accountDB := base.CreateAccountsDB()
|
||||
federation := conn.CreateFederationClient(base, pSessions)
|
||||
keyAPI := keyserver.NewInternalAPI(base, &base.Cfg.KeyServer, federation)
|
||||
|
||||
|
@ -189,7 +188,7 @@ func startup() {
|
|||
|
||||
rsAPI := roomserver.NewInternalAPI(base)
|
||||
|
||||
userAPI := userapi.NewInternalAPI(base, accountDB, &cfg.UserAPI, nil, keyAPI, rsAPI, base.PushGatewayHTTPClient())
|
||||
userAPI := userapi.NewInternalAPI(base, &cfg.UserAPI, nil, keyAPI, rsAPI, base.PushGatewayHTTPClient())
|
||||
keyAPI.SetUserAPI(userAPI)
|
||||
|
||||
asQuery := appservice.NewInternalAPI(
|
||||
|
@ -201,7 +200,6 @@ func startup() {
|
|||
|
||||
monolith := setup.Monolith{
|
||||
Config: base.Cfg,
|
||||
AccountDB: accountDB,
|
||||
Client: conn.CreateClient(base, pSessions),
|
||||
FedClient: federation,
|
||||
KeyRing: keyRing,
|
||||
|
@ -215,7 +213,7 @@ func startup() {
|
|||
ExtPublicRoomsProvider: rooms.NewPineconeRoomProvider(pRouter, pSessions, fedSenderAPI, federation),
|
||||
}
|
||||
monolith.AddAllPublicRoutes(
|
||||
base.ProcessContext,
|
||||
base,
|
||||
base.PublicClientAPIMux,
|
||||
base.PublicFederationAPIMux,
|
||||
base.PublicKeyAPIMux,
|
||||
|
|
|
@ -45,7 +45,7 @@ func main() {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
roomserverDB, err := storage.Open(&cfg.RoomServer.Database, cache)
|
||||
roomserverDB, err := storage.Open(nil, &cfg.RoomServer.Database, cache)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue