From beb2ddf03deb35e74212195927e5950672a18210 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 14 Jul 2021 10:23:04 +0100 Subject: [PATCH] Make sure NATS uses own persistent directory (TODO: make this configurable) --- go.mod | 2 +- go.sum | 4 ++-- setup/config/config.go | 1 + setup/config/config_kafka.go | 2 ++ setup/kafka/kafka.go | 5 ++++- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 95c6ec69..54731b39 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/matrix-org/dendrite -replace github.com/nats-io/nats-server/v2 => github.com/neilalexander/nats-server/v2 v2.3.3-0.20210713120756-c663f55fedeb +replace github.com/nats-io/nats-server/v2 => github.com/neilalexander/nats-server/v2 v2.3.3-0.20210714083537-9e5eeca686a2 replace github.com/nats-io/nats.go => github.com/neilalexander/nats.go v1.11.1-0.20210713114907-f78197deadf1 diff --git a/go.sum b/go.sum index c0bcb9e4..f3f3a3d7 100644 --- a/go.sum +++ b/go.sum @@ -1125,8 +1125,8 @@ github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uY github.com/ncw/swift v1.0.47/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= -github.com/neilalexander/nats-server/v2 v2.3.3-0.20210713120756-c663f55fedeb h1:fhQF1iw+4BbVlNDtJj202IJk0A2JeRfkqJ1OyJsGMIU= -github.com/neilalexander/nats-server/v2 v2.3.3-0.20210713120756-c663f55fedeb/go.mod h1:dUf7Cm5z5LbciFVwWx54owyCKm8x4/hL6p7rrljhLFY= +github.com/neilalexander/nats-server/v2 v2.3.3-0.20210714083537-9e5eeca686a2 h1:hy3Y+7o4B7U3lFrrjw0JMO2ayepMWkSVEZmu4d3cxUY= +github.com/neilalexander/nats-server/v2 v2.3.3-0.20210714083537-9e5eeca686a2/go.mod h1:dUf7Cm5z5LbciFVwWx54owyCKm8x4/hL6p7rrljhLFY= github.com/neilalexander/nats.go v1.11.1-0.20210713114907-f78197deadf1 h1:bI5JbW/nR/3klqVi9UBFjLimzyw8XqkgwuFEG7ROMh4= github.com/neilalexander/nats.go v1.11.1-0.20210713114907-f78197deadf1/go.mod h1:BPko4oXsySz4aSWeFgOHLZs3G4Jq4ZAyE6/zMCxRT6w= github.com/neilalexander/utp v0.1.1-0.20210622132614-ee9a34a30488 h1:xZk82i6JK2d0SqRIXwaxj7J/NQB6ngq0PuMx3wXBaRQ= diff --git a/setup/config/config.go b/setup/config/config.go index b9114407..c9fdbf6c 100644 --- a/setup/config/config.go +++ b/setup/config/config.go @@ -329,6 +329,7 @@ func (c *Dendrite) Verify(configErrs *ConfigErrors, isMonolith bool) { } func (c *Dendrite) Wiring() { + c.Global.Kafka.Matrix = &c.Global c.ClientAPI.Matrix = &c.Global c.EDUServer.Matrix = &c.Global c.FederationAPI.Matrix = &c.Global diff --git a/setup/config/config_kafka.go b/setup/config/config_kafka.go index b6ad88c7..c7c7f09f 100644 --- a/setup/config/config_kafka.go +++ b/setup/config/config_kafka.go @@ -23,6 +23,8 @@ var KafkaTopics = []string{ } type Kafka struct { + Matrix *Global `yaml:"-"` + // A list of kafka/NATS addresses to connect to. Addresses []string `yaml:"addresses"` // The prefix to use for Kafka topic names for this homeserver - really only diff --git a/setup/kafka/kafka.go b/setup/kafka/kafka.go index b6988ed8..78b8767d 100644 --- a/setup/kafka/kafka.go +++ b/setup/kafka/kafka.go @@ -37,6 +37,7 @@ func SetupConsumerProducer(cfg *config.Kafka) (sarama.Consumer, sarama.SyncProdu ServerName: "monolith", DontListen: true, JetStream: true, + StoreDir: string(cfg.Matrix.ServerName), LogFile: "nats.log", Debug: true, }) @@ -48,7 +49,9 @@ func SetupConsumerProducer(cfg *config.Kafka) (sarama.Consumer, sarama.SyncProdu s = natsServer } natsServerMutex.Unlock() - natsServer.WaitForStartup() + if !natsServer.ReadyForConnections(time.Second * 10) { + logrus.Fatalln("NATS did not start in time") + } conn, err := s.InProcessConn() if err != nil { logrus.Fatalln("Failed to get a NATS in-process conn")