- Add CosmosDB as a Datasource type

- Use the SQLLite as a base for the CosmosDB package(s)
- Update the ConnString to use file: from cosmosdb: so it still works
- Add a yaml file for the config to use CosmosDB
This commit is contained in:
Alex Flatow 2021-05-06 15:09:44 +10:00
parent 4b42a0addb
commit 5ded872da9
10 changed files with 23 additions and 0 deletions

View file

@ -16,6 +16,7 @@
package cosmosdb
import (
"github.com/matrix-org/dendrite/internal/cosmosdbutil"
"context"
"database/sql"
@ -37,6 +38,7 @@ type Database struct {
// NewDatabase opens a new database
func NewDatabase(dbProperties *config.DatabaseOptions) (*Database, error) {
dbProperties.ConnectionString = cosmosdbutil.GetConnectionString(&dbProperties.ConnectionString)
var result Database
var err error
if result.db, err = sqlutil.Open(dbProperties); err != nil {

View file

@ -16,6 +16,7 @@
package cosmosdb
import (
"github.com/matrix-org/dendrite/internal/cosmosdbutil"
"database/sql"
_ "github.com/mattn/go-sqlite3"
@ -37,6 +38,7 @@ type Database struct {
// NewDatabase opens a new database
func NewDatabase(dbProperties *config.DatabaseOptions, cache caching.FederationSenderCache) (*Database, error) {
dbProperties.ConnectionString = cosmosdbutil.GetConnectionString(&dbProperties.ConnectionString)
var d Database
var err error
if d.db, err = sqlutil.Open(dbProperties); err != nil {

View file

@ -15,12 +15,14 @@
package cosmosdb
import (
"github.com/matrix-org/dendrite/internal/cosmosdbutil"
"github.com/matrix-org/dendrite/internal/sqlutil"
"github.com/matrix-org/dendrite/keyserver/storage/shared"
"github.com/matrix-org/dendrite/setup/config"
)
func NewDatabase(dbProperties *config.DatabaseOptions) (*shared.Database, error) {
dbProperties.ConnectionString = cosmosdbutil.GetConnectionString(&dbProperties.ConnectionString)
db, err := sqlutil.Open(dbProperties)
if err != nil {
return nil, err

View file

@ -16,6 +16,7 @@
package cosmosdb
import (
"github.com/matrix-org/dendrite/internal/cosmosdbutil"
"context"
"database/sql"
@ -36,6 +37,7 @@ type Database struct {
// Open opens a postgres database.
func Open(dbProperties *config.DatabaseOptions) (*Database, error) {
dbProperties.ConnectionString = cosmosdbutil.GetConnectionString(&dbProperties.ConnectionString)
d := Database{
writer: sqlutil.NewExclusiveWriter(),
}

View file

@ -16,6 +16,7 @@
package cosmosdb
import (
"github.com/matrix-org/dendrite/internal/cosmosdbutil"
"context"
"database/sql"
@ -37,6 +38,7 @@ type Database struct {
// Open a sqlite database.
func Open(dbProperties *config.DatabaseOptions, cache caching.RoomServerCaches) (*Database, error) {
dbProperties.ConnectionString = cosmosdbutil.GetConnectionString(&dbProperties.ConnectionString)
var d Database
var db *sql.DB
var err error

View file

@ -1,6 +1,7 @@
package kafka
import (
"github.com/matrix-org/dendrite/internal/cosmosdbutil"
"github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/setup/config"
"github.com/matrix-org/naffka"
@ -46,6 +47,10 @@ func setupNaffka(cfg *config.Kafka) (sarama.Consumer, sarama.SyncProducer) {
if naffkaInstance != nil {
return naffkaInstance, naffkaInstance
}
if(cfg.Database.ConnectionString.IsCosmosDB()) {
cfg.Database.ConnectionString = cosmosdbutil.GetConnectionString(&cfg.Database.ConnectionString)
}
naffkaDB, err := naffkaStorage.NewDatabase(string(cfg.Database.ConnectionString))
if err != nil {
logrus.WithError(err).Panic("Failed to setup naffka database")

View file

@ -16,6 +16,7 @@
package cosmosdb
import (
"github.com/matrix-org/dendrite/internal/cosmosdbutil"
"context"
"golang.org/x/crypto/ed25519"
@ -44,6 +45,7 @@ func NewDatabase(
serverKey ed25519.PublicKey,
serverKeyID gomatrixserverlib.KeyID,
) (*Database, error) {
dbProperties.ConnectionString = cosmosdbutil.GetConnectionString(&dbProperties.ConnectionString)
db, err := sqlutil.Open(dbProperties)
if err != nil {
return nil, err

View file

@ -16,6 +16,7 @@
package cosmosdb
import (
"github.com/matrix-org/dendrite/internal/cosmosdbutil"
"database/sql"
// Import the sqlite3 package
@ -40,6 +41,7 @@ type SyncServerDatasource struct {
// NewDatabase creates a new sync server database
// nolint: gocyclo
func NewDatabase(dbProperties *config.DatabaseOptions) (*SyncServerDatasource, error) {
dbProperties.ConnectionString = cosmosdbutil.GetConnectionString(&dbProperties.ConnectionString)
var d SyncServerDatasource
var err error
if d.db, err = sqlutil.Open(dbProperties); err != nil {

View file

@ -15,6 +15,7 @@
package cosmosdb
import (
"github.com/matrix-org/dendrite/internal/cosmosdbutil"
"context"
"database/sql"
"encoding/json"
@ -55,6 +56,7 @@ type Database struct {
// NewDatabase creates a new accounts and profiles database
func NewDatabase(dbProperties *config.DatabaseOptions, serverName gomatrixserverlib.ServerName, bcryptCost int, openIDTokenLifetimeMS int64) (*Database, error) {
dbProperties.ConnectionString = cosmosdbutil.GetConnectionString(&dbProperties.ConnectionString)
db, err := sqlutil.Open(dbProperties)
if err != nil {
return nil, err

View file

@ -15,6 +15,7 @@
package cosmosdb
import (
"github.com/matrix-org/dendrite/internal/cosmosdbutil"
"context"
"crypto/rand"
"database/sql"
@ -41,6 +42,7 @@ type Database struct {
// NewDatabase creates a new device database
func NewDatabase(dbProperties *config.DatabaseOptions, serverName gomatrixserverlib.ServerName) (*Database, error) {
dbProperties.ConnectionString = cosmosdbutil.GetConnectionString(&dbProperties.ConnectionString)
db, err := sqlutil.Open(dbProperties)
if err != nil {
return nil, err