Closed MadLittleMods closed 3 years ago
I have switched to using Postgresql with my Dendrite dev setup on macOS 10.15.7
$ brew install postgresql
$ brew services start postgresql
$ brew services info postgresql
$ less +G /usr/local/var/log/postgres.log
$ postgres --version
postgres (PostgreSQL) 13.1
$ createdb dendrite
$ psql dendrite
Why can't the same database file be used for each run?
Because that's not how SQLite works unfortunately. It's single process, single writer. Sharing the .db
file across multiple components will cause failures at best, data loss at worst.
@Kegsay How does it work across computer restarts? I have to keep my SQLite process running forever for it to work as expected?
@MadLittleMods SQLite isn't a separate process, it's embedded into the Dendrite process itself. However, SQLite only allows one writer (irrespective of whether its multiple writers from the same process, or different processes) to a database file at a time. In Dendrite, each component expects to be able to write exclusively to its own database, therefore each component needs to have its own .db
file.
Can we by default split the .db
file to it's own pieces so they won't conflict? And re-use it on multiple startups?
I feel like I shouldn't be running into readonly database issues from trying out and starting up Dendrite a couple times.
This was chatted about a bit more in https://matrix.to/#/!JfeKJVJwCKQNbodoaF:matrix.org/$qPBv5RiIBJ8lzvvLxvxRP44kmWsfo-HvL_5oK0foSDI?via=matrix.org&via=dendrite.neilalexander.dev&via=vector.modular.im
It seems like what I am experiencing isn't expected. "With the more recent dendrite versions with the proper shutdown stuff, that shouldn’t happen". And possibly the lockfile isn't being cleaned up. Where is the lockfile stored so I can check?
Can you please confirm that each of the Dendrite components in the dendrite.yaml
is connecting to a different SQLite DB file?
Here is what my dendrite.yaml
looks like. I think it's just copied from dendrite-config.yaml
. It's switched over to postgres now but still has the comments from SQLite.
Looking through all of the Nevermind, they just looked similar on my first glance. I don't see any duplicates.connection_string
entries, it looks like account_database
and device_database
have the same name. But this is the same as dendrite-config.yaml
It seems like what I am experiencing isn't expected. "With the more recent dendrite versions with the proper shutdown stuff, that shouldn’t happen". And possibly the lockfile isn't being cleaned up.
This is expected. There is no lockfile for SQLite - it uses actual file locks which are controlled by the underlying OS, which has its lifetime tied to the process which opened the lock: no need for graceful shutdowns to "clean up". Dying in the middle of a transaction will automatically restore based on the contents of the .db
file alone (and the WAL journal if WAL is enabled).
I can reproduce your issue by doing the following:
sudo
sudo
NewInternalAPI
failed to connect to room server db error="attempt to write a readonly database"
panic: (*logrus.Entry) (0x4f06000,0xc0003304d0)
The first time will result in .db
files being created with root permissions, meaning you would then need to keep using sudo
to run the server.
Please re-open if you can reproduce this in some other way which you believe is in error.
Thanks @Kegsay! I think your break down nailed it. I probably initially ran sudo
to get around the log issue in https://github.com/matrix-org/dendrite/issues/1644
I deleted all of the existing *.db
files (rm *.db
) and switched my config back to using SQLite. Now starting up multiple times works as expected!
$ ./build.sh && ./bin/dendrite-monolith-server --tls-cert server.crt --tls-key server.key --config dendrite.yaml
INFO[2021-03-16T23:46:01.090646000Z] [github.com/matrix-org/dendrite/setup/base.go:110] NewBaseDendrite
Dendrite version 0.3.11+3c419be6
INFO[2021-03-16T23:46:01.092996000Z] [github.com/matrix-org/dendrite/signingkeyserver/signingkeyserver.go:103] NewInternalAPI
Enabled perspective key fetcher num_public_keys=2 server_name=matrix.org
INFO[2021-03-16T23:46:01.105965000Z] [github.com/matrix-org/dendrite/setup/base.go:394] func2
Starting external Monolith listener on :8008
INFO[2021-03-16T23:46:01.105958000Z] [github.com/matrix-org/dendrite/setup/base.go:394] func2
Starting external Monolith listener on :8448
Next steps is to work on a solution for https://github.com/matrix-org/dendrite/issues/1644 so logs work out of the box and no one is tempted like me to use sudo
here.
Related to https://github.com/matrix-org/dendrite/issues/1644
When trying to get started and run the monolith, it throws an error.
Running with
sudo
does make it run. But after a follow-up call with @Kegsay and @neilalexander:sudo
is not required to run dendrite. The database file needs to be different every time it runs. Ifsudo
works, it's only because it overrides the readonly setting and we are probably losing data.Potential solutions
Why can't the same database file be used for each run?