eventPersister workers

This commit is contained in:
Daniel Lovbrotte Olsen 2022-12-14 08:21:53 +01:00
parent a2b4d2e341
commit c7f34ff60b
1 changed files with 43 additions and 8 deletions

View File

@ -131,6 +131,12 @@ in
default = 0; default = 0;
}; };
eventPersisters = lib.mkOption {
type = lib.types.ints.unsigned;
description = "How many automatically configured event-persisters to set up";
default = 0;
};
instances = lib.mkOption { instances = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule ({config, ...}: { type = lib.types.attrsOf (lib.types.submodule ({config, ...}: {
@ -163,6 +169,7 @@ in
"fed-receiver" = "synapse.app.generic_worker"; "fed-receiver" = "synapse.app.generic_worker";
"initial-sync" = "synapse.app.generic_worker"; "initial-sync" = "synapse.app.generic_worker";
"normal-sync" = "synapse.app.generic_worker"; "normal-sync" = "synapse.app.generic_worker";
"event-persist" = "synapse.app.generic_worker";
}.${t}; }.${t};
defaultApp = if (!isAuto) defaultApp = if (!isAuto)
then "synapse.app.generic_worker" then "synapse.app.generic_worker"
@ -222,6 +229,7 @@ in
"fed-sender" = [ ]; "fed-sender" = [ ];
"initial-sync" = [ "client" ]; "initial-sync" = [ "client" ];
"normal-sync" = [ "client" ]; "normal-sync" = [ "client" ];
"event-persist" = [ "replication" ];
}.${t}; }.${t};
in lib.mkOption { in lib.mkOption {
type = lib.types.listOf (lib.types.submodule { type = lib.types.listOf (lib.types.submodule {
@ -589,6 +597,33 @@ in
}; };
}); });
}) })
({
services.matrix-synapse-next.settings.instance_map = genAttrs' (lib.lists.range 1 cfg.workers.eventPersisters)
(i: "auto-event-persist${toString i}")
(i: let
isReplication = l: lib.lists.any (r: lib.lists.any (n: n == "replication") r.names) l.resources;
wRL = lib.lists.findFirst isReplication
(throw "No replication listener configured!")
cfg.workers.instances."auto-event-persist${toString i}".settings.listeners;
wRH = lib.findFirst (x: true) (throw "Replication listener had no addresses")
wRL.bind_addresses;
wRP = wRL.port;
in {
host = wRH;
port = wRP;
}
);
services.matrix-synapse-next.settings.stream_writers.events = lib.genList (i: "auto-event-persist${toString (i + 1)}") cfg.workers.eventPersisters;
services.matrix-synapse-next.workers.instances = genAttrs' (lib.lists.range 1 cfg.workers.eventPersisters)
(i: "auto-event-persist${toString i}")
(i: {
isAuto = true; type = "event-persist"; index = i;
settings.worker_listeners = [{ port = cfg.workers.workerStartingPort + cfg.workers.federationReceivers + cfg.workers.initialSyncers + cfg.workers.normalSyncers + i - 1;}]
++ lib.optional wcfg.enableMetrics { port = cfg.workers.metricsStartingPort + cfg.workers.federationSenders + cfg.workers.federationReceivers + cfg.workers.initialSyncers + cfg.workers.normalSyncers + i;
};
});
})
]) ])
({ ({