User Postgres database rather than Memory for Naffka

This commit is contained in:
Erik Johnston 2017-11-15 15:17:04 +00:00
parent 26155effb4
commit c832469387
2 changed files with 21 additions and 2 deletions

View file

@ -16,6 +16,7 @@ package main
import ( import (
"context" "context"
"database/sql"
"flag" "flag"
"net/http" "net/http"
"os" "os"
@ -199,7 +200,21 @@ func (m *monolith) setupFederation() {
func (m *monolith) setupKafka() { func (m *monolith) setupKafka() {
if m.cfg.Kafka.UseNaffka { if m.cfg.Kafka.UseNaffka {
naff, err := naffka.New(&naffka.MemoryDatabase{}) db, err := sql.Open("postgres", string(m.cfg.Database.Naffka))
if err != nil {
log.WithFields(log.Fields{
log.ErrorKey: err,
}).Panic("Failed to open naffka database")
}
naffkaDB, err := naffka.NewPostgresqlDatabase(db)
if err != nil {
log.WithFields(log.Fields{
log.ErrorKey: err,
}).Panic("Failed to setup naffka database")
}
naff, err := naffka.New(naffkaDB)
if err != nil { if err != nil {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
log.ErrorKey: err, log.ErrorKey: err,

View file

@ -25,8 +25,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/sirupsen/logrus"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/sirupsen/logrus"
"golang.org/x/crypto/ed25519" "golang.org/x/crypto/ed25519"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
@ -148,6 +148,8 @@ type Dendrite struct {
// The PublicRoomsAPI database stores information used to compute the public // The PublicRoomsAPI database stores information used to compute the public
// room directory. It is only accessed by the PublicRoomsAPI server. // room directory. It is only accessed by the PublicRoomsAPI server.
PublicRoomsAPI DataSource `yaml:"public_rooms_api"` PublicRoomsAPI DataSource `yaml:"public_rooms_api"`
// The Naffka database is used internally by the naffka library, if used.
Naffka DataSource `yaml:"naffka,omitempty"`
} `yaml:"database"` } `yaml:"database"`
// TURN Server Config // TURN Server Config
@ -386,6 +388,8 @@ func (config *Dendrite) check(monolithic bool) error {
if !monolithic { if !monolithic {
problems = append(problems, fmt.Sprintf("naffka can only be used in a monolithic server")) problems = append(problems, fmt.Sprintf("naffka can only be used in a monolithic server"))
} }
checkNotEmpty("database.naffka", string(config.Database.Naffka))
} else { } else {
// If we aren't using naffka then we need to have at least one kafka // If we aren't using naffka then we need to have at least one kafka
// server to talk to. // server to talk to.