From 3daa2327edc90e1ff70bcbc578b793ae5ba5b69f Mon Sep 17 00:00:00 2001 From: Kegsay Date: Fri, 22 May 2020 12:28:48 +0100 Subject: [PATCH] dendritejs tweaks for persisting sqlite DBs (#1058) * Use uri.path so we don't have file: in the filename * New go-sqlite-js version --- appservice/storage/storage_wasm.go | 2 +- .../auth/storage/accounts/storage_wasm.go | 2 +- .../auth/storage/devices/storage_wasm.go | 2 +- cmd/dendritejs/main.go | 20 +++++++++---------- federationsender/storage/storage_wasm.go | 2 +- go.mod | 2 +- go.sum | 2 ++ internal/basecomponent/base.go | 2 +- internal/keydb/keydb_wasm.go | 2 +- mediaapi/storage/storage_wasm.go | 2 +- publicroomsapi/storage/storage_wasm.go | 2 +- 11 files changed, 21 insertions(+), 19 deletions(-) diff --git a/appservice/storage/storage_wasm.go b/appservice/storage/storage_wasm.go index a6144b43..de1acf92 100644 --- a/appservice/storage/storage_wasm.go +++ b/appservice/storage/storage_wasm.go @@ -34,7 +34,7 @@ func NewDatabase( case "postgres": return nil, fmt.Errorf("Cannot use postgres implementation") case "file": - return sqlite3.NewDatabase(dataSourceName) + return sqlite3.NewDatabase(uri.Path) default: return nil, fmt.Errorf("Cannot use postgres implementation") } diff --git a/clientapi/auth/storage/accounts/storage_wasm.go b/clientapi/auth/storage/accounts/storage_wasm.go index 81e77cf7..7cf50de7 100644 --- a/clientapi/auth/storage/accounts/storage_wasm.go +++ b/clientapi/auth/storage/accounts/storage_wasm.go @@ -36,7 +36,7 @@ func NewDatabase( case "postgres": return nil, fmt.Errorf("Cannot use postgres implementation") case "file": - return sqlite3.NewDatabase(dataSourceName, serverName) + return sqlite3.NewDatabase(uri.Path, serverName) default: return nil, fmt.Errorf("Cannot use postgres implementation") } diff --git a/clientapi/auth/storage/devices/storage_wasm.go b/clientapi/auth/storage/devices/storage_wasm.go index 14c19e74..c89ad887 100644 --- a/clientapi/auth/storage/devices/storage_wasm.go +++ b/clientapi/auth/storage/devices/storage_wasm.go @@ -36,7 +36,7 @@ func NewDatabase( case "postgres": return nil, fmt.Errorf("Cannot use postgres implementation") case "file": - return sqlite3.NewDatabase(dataSourceName, serverName) + return sqlite3.NewDatabase(uri.Path, serverName) default: return nil, fmt.Errorf("Cannot use postgres implementation") } diff --git a/cmd/dendritejs/main.go b/cmd/dendritejs/main.go index 1398bc6d..73d38149 100644 --- a/cmd/dendritejs/main.go +++ b/cmd/dendritejs/main.go @@ -163,16 +163,16 @@ func main() { cfg := &config.Dendrite{} cfg.SetDefaults() cfg.Kafka.UseNaffka = true - cfg.Database.Account = "file:dendritejs_account.db" - cfg.Database.AppService = "file:dendritejs_appservice.db" - cfg.Database.Device = "file:dendritejs_device.db" - cfg.Database.FederationSender = "file:dendritejs_fedsender.db" - cfg.Database.MediaAPI = "file:dendritejs_mediaapi.db" - cfg.Database.Naffka = "file:dendritejs_naffka.db" - cfg.Database.PublicRoomsAPI = "file:dendritejs_publicrooms.db" - cfg.Database.RoomServer = "file:dendritejs_roomserver.db" - cfg.Database.ServerKey = "file:dendritejs_serverkey.db" - cfg.Database.SyncAPI = "file:dendritejs_syncapi.db" + cfg.Database.Account = "file:/idb/dendritejs_account.db" + cfg.Database.AppService = "file:/idb/dendritejs_appservice.db" + cfg.Database.Device = "file:/idb/dendritejs_device.db" + cfg.Database.FederationSender = "file:/idb/dendritejs_fedsender.db" + cfg.Database.MediaAPI = "file:/idb/dendritejs_mediaapi.db" + cfg.Database.Naffka = "file:/idb/dendritejs_naffka.db" + cfg.Database.PublicRoomsAPI = "file:/idb/dendritejs_publicrooms.db" + cfg.Database.RoomServer = "file:/idb/dendritejs_roomserver.db" + cfg.Database.ServerKey = "file:/idb/dendritejs_serverkey.db" + cfg.Database.SyncAPI = "file:/idb/dendritejs_syncapi.db" cfg.Kafka.Topics.UserUpdates = "user_updates" cfg.Kafka.Topics.OutputTypingEvent = "output_typing_event" cfg.Kafka.Topics.OutputClientData = "output_client_data" diff --git a/federationsender/storage/storage_wasm.go b/federationsender/storage/storage_wasm.go index f593fd44..3d071bfe 100644 --- a/federationsender/storage/storage_wasm.go +++ b/federationsender/storage/storage_wasm.go @@ -33,7 +33,7 @@ func NewDatabase( } switch uri.Scheme { case "file": - return sqlite3.NewDatabase(dataSourceName) + return sqlite3.NewDatabase(uri.Path) case "postgres": return nil, fmt.Errorf("Cannot use postgres implementation") default: diff --git a/go.mod b/go.mod index bbac53ec..151fee27 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/libp2p/go-libp2p-record v0.1.2 github.com/matrix-org/dugong v0.0.0-20171220115018-ea0a4690a0d5 github.com/matrix-org/go-http-js-libp2p v0.0.0-20200518170932-783164aeeda4 - github.com/matrix-org/go-sqlite3-js v0.0.0-20200326102434-98eda28055bd + github.com/matrix-org/go-sqlite3-js v0.0.0-20200522092705-bc8506ccbcf3 github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 github.com/matrix-org/gomatrixserverlib v0.0.0-20200511154227-5cc71d36632b github.com/matrix-org/naffka v0.0.0-20200422140631-181f1ee7401f diff --git a/go.sum b/go.sum index d487f42a..15822b53 100644 --- a/go.sum +++ b/go.sum @@ -354,6 +354,8 @@ github.com/matrix-org/go-http-js-libp2p v0.0.0-20200518170932-783164aeeda4 h1:eq github.com/matrix-org/go-http-js-libp2p v0.0.0-20200518170932-783164aeeda4/go.mod h1:3WluEZ9QXSwU30tWYqktnpC1x9mwZKx1r8uAv8Iq+a4= github.com/matrix-org/go-sqlite3-js v0.0.0-20200326102434-98eda28055bd h1:C1FV4dRKF1uuGK8UH01+IoW6zZpfsTV1MvQimZvt418= github.com/matrix-org/go-sqlite3-js v0.0.0-20200326102434-98eda28055bd/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo= +github.com/matrix-org/go-sqlite3-js v0.0.0-20200522092705-bc8506ccbcf3 h1:Yb+Wlf/iHhWlLWd+kCgG+Fsg4Dc+xBl7hptfK7lD0zY= +github.com/matrix-org/go-sqlite3-js v0.0.0-20200522092705-bc8506ccbcf3/go.mod h1:e+cg2q7C7yE5QnAXgzo512tgFh1RbQLC0+jozuegKgo= github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 h1:Hr3zjRsq2bhrnp3Ky1qgx/fzCtCALOoGYylh2tpS9K4= github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0= github.com/matrix-org/gomatrixserverlib v0.0.0-20200511154227-5cc71d36632b h1:nAmSc1KvQOumoRTz/LD68KyrB6Q5/6q7CmQ5Bswc2nM= diff --git a/internal/basecomponent/base.go b/internal/basecomponent/base.go index 0682ae0e..45aa454a 100644 --- a/internal/basecomponent/base.go +++ b/internal/basecomponent/base.go @@ -264,7 +264,7 @@ func setupNaffka(cfg *config.Dendrite) (sarama.Consumer, sarama.SyncProducer) { uri, err := url.Parse(string(cfg.Database.Naffka)) if err != nil || uri.Scheme == "file" { - db, err = sqlutil.Open(internal.SQLiteDriverName(), string(cfg.Database.Naffka), nil) + db, err = sqlutil.Open(internal.SQLiteDriverName(), string(uri.Path), nil) if err != nil { logrus.WithError(err).Panic("Failed to open naffka database") } diff --git a/internal/keydb/keydb_wasm.go b/internal/keydb/keydb_wasm.go index 349381ee..c8032902 100644 --- a/internal/keydb/keydb_wasm.go +++ b/internal/keydb/keydb_wasm.go @@ -41,7 +41,7 @@ func NewDatabase( case "postgres": return nil, fmt.Errorf("Cannot use postgres implementation") case "file": - return sqlite3.NewDatabase(dataSourceName, serverName, serverKey, serverKeyID) + return sqlite3.NewDatabase(uri.Path, serverName, serverKey, serverKeyID) default: return nil, fmt.Errorf("Cannot use postgres implementation") } diff --git a/mediaapi/storage/storage_wasm.go b/mediaapi/storage/storage_wasm.go index 78de2cb8..aa188997 100644 --- a/mediaapi/storage/storage_wasm.go +++ b/mediaapi/storage/storage_wasm.go @@ -35,7 +35,7 @@ func Open( case "postgres": return nil, fmt.Errorf("Cannot use postgres implementation") case "file": - return sqlite3.Open(dataSourceName) + return sqlite3.Open(uri.Path) default: return nil, fmt.Errorf("Cannot use postgres implementation") } diff --git a/publicroomsapi/storage/storage_wasm.go b/publicroomsapi/storage/storage_wasm.go index d00c339d..2157ce11 100644 --- a/publicroomsapi/storage/storage_wasm.go +++ b/publicroomsapi/storage/storage_wasm.go @@ -31,7 +31,7 @@ func NewPublicRoomsServerDatabase(dataSourceName string) (Database, error) { case "postgres": return nil, fmt.Errorf("Cannot use postgres implementation") case "file": - return sqlite3.NewPublicRoomsServerDatabase(dataSourceName) + return sqlite3.NewPublicRoomsServerDatabase(uri.Path) default: return nil, fmt.Errorf("Cannot use postgres implementation") }