Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,24 @@ import (
// Returns true if we need to wait for other nodes to catch up to our version.
func (db *DqliteDB) Open(ext types.Extensions, bootstrap bool) error {
// Allow dqlite up to 2 minutes to become ready when starting up.
// This is to allow for unready/dead nodes to time out.
ctx, cancel := context.WithTimeout(db.ctx, 120*time.Second)
// This is to allow for unready/dead nodes to time out. The timeout can be
// raised via the DQLITE_READY_TIMEOUT environment variable, which helps when
// a joining node must sync a large dqlite database over a slow link or disk
// and would otherwise exceed the default.
readyTimeout := 120 * time.Second
if v := os.Getenv(sys.DqliteReadyTimeout); v != "" {
parsed, err := time.ParseDuration(v)
switch {
case err != nil:
Comment on lines +34 to +38
db.log().Warn("Ignoring invalid DQLITE_READY_TIMEOUT", slog.String("value", v), slog.String("error", err.Error()))
case parsed <= 0:
db.log().Warn("Ignoring non-positive DQLITE_READY_TIMEOUT", slog.String("value", v))
Comment on lines +39 to +41
default:
readyTimeout = parsed
}
}

ctx, cancel := context.WithTimeout(db.ctx, readyTimeout)
defer cancel()

db.statusLock.Lock()
Expand Down
6 changes: 6 additions & 0 deletions internal/sys/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ const (
// DqliteSocket is the configurable location of the dqlite socket.
DqliteSocket = "DQLITE_SOCKET"

// DqliteReadyTimeout overrides how long to wait for dqlite to become ready
// when opening the database (a Go duration string, e.g. "30m"). Defaults to
// 2 minutes. Useful when a joining node must sync a large dqlite database
// over a slow link or disk and would otherwise exceed the default timeout.
DqliteReadyTimeout = "DQLITE_READY_TIMEOUT"

// StateDir is the location of the daemon state directory.
StateDir = "STATE_DIR"

Expand Down