Skip to content

Commit

Permalink
[chore] Exit on misconfigured journal mode
Browse files Browse the repository at this point in the history
Adds documentation and a configuration validation check to ensure that
when folks run with the WASM SQLite build on anything other than Linux
we don't allow them to run with journaling set to WAL. That will result
in abysmal performance until ncruces/go-sqlite3#85 is resolved.

Fixes #2962
  • Loading branch information
daenney committed Jun 4, 2024
1 parent 45fe295 commit 937b282
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/configuration/database.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ To configure GoToSocial to use SQLite, change `db-type` to `sqlite`. The `addres

Note that the `:memory:` setting will use an *in-memory database* which will be wiped when your GoToSocial instance stops running. This is for testing only and is absolutely not suitable for running a proper instance, so *don't do this*.

!!! warning "WASM SQLite build"
When running the experimental WASM SQLite build on anything other than Linux, you have to set `db-sqlite-journal-mode` to `TRUNCATE` instead of `WAL`. You'll experience abysmal performance otherwise.

## Postgres

Postgres is a heavier database format, which is useful for larger instances where you need to scale performance, or where you need to run your database on a dedicated machine separate from your GoToSocial instance (or do funky stuff like run a database cluster).
Expand Down Expand Up @@ -143,6 +146,11 @@ db-max-open-conns-multiplier: 8
# SQLite only -- unused otherwise.
# If set to empty string, the sqlite default will be used.
# See: https://www.sqlite.org/pragma.html#pragma_journal_mode
#
# WARNING: when running the experimental WASM SQLite build on
# anything other than Linux, set this to "TRUNCATE" instead.
# The server will complain about this on startup.
#
# Examples: ["DELETE", "TRUNCATE", "PERSIST", "MEMORY", "WAL", "OFF"]
# Default: "WAL"
db-sqlite-journal-mode: "WAL"
Expand Down
5 changes: 5 additions & 0 deletions example/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ db-max-open-conns-multiplier: 8
# SQLite only -- unused otherwise.
# If set to empty string, the sqlite default will be used.
# See: https://www.sqlite.org/pragma.html#pragma_journal_mode
#
# WARNING: when running the experimental WASM SQLite build on
# anything other than Linux, set this to "TRUNCATE" instead.
# The server will complain about this on startup.
#
# Examples: ["DELETE", "TRUNCATE", "PERSIST", "MEMORY", "WAL", "OFF"]
# Default: "WAL"
db-sqlite-journal-mode: "WAL"
Expand Down
41 changes: 41 additions & 0 deletions internal/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ package config

import (
"fmt"
"runtime"
"runtime/debug"
"slices"
"strings"

"github.com/miekg/dns"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
Expand Down Expand Up @@ -144,5 +148,42 @@ func Validate() error {
)
}

if err := checkSQLiteJournalMode(); err != nil {
errf("%s", err)
}

return errs.Combine()
}

func checkSQLiteJournalMode() error {
// check if we're running SQLite
if GetDbDatabase() != "sqlite" {
return nil
}

// check if this uses the WASM build
info, _ := debug.ReadBuildInfo()
isWasm := false
for _, s := range info.Settings {
// check the build tags
if s.Key == "-tags" {
vals := strings.Split(s.Value, ",")
if slices.Contains(vals, "wasmsqlite3") {
isWasm = true
break
}
// we don't need to process other build setting keys
break
}
}

if !isWasm {
return nil
}

if runtime.GOOS != "linux" && GetDbSqliteJournalMode() == "WAL" {
return fmt.Errorf("when using the WASM SQLite build on a non-Linux platform the %s configuration value must be set to TRUNCATE", DbSqliteJournalModeFlag())
}

return nil
}

0 comments on commit 937b282

Please sign in to comment.