Files
base/core/base_backup_engine_test.go
zeekayandHanzo Dev 43e315f18c a backup that cannot hold the database refuses, and a deadlock is retried
Three things, all the same shape: SQLite's guarantees were being assumed on
an engine that does not make them.

A backup archives the data directory, which is where the database lives on
SQLite and not on Postgres. There it returned 204 and produced an archive
with no database in it, and restore then failed inside a goroutine after the
204 had gone out — so an operator saw successful backups, a populated list,
plausible sizes, and had nothing recoverable. It refuses on an engine whose
database is not in that directory, before extracting anything, and says where
to take the backup instead. Refusing beats shelling out to pg_dump: that adds
a binary that has to out-version the server, and its output cannot be restored
by the path we have, so it would be a second restore mechanism.

What stopped a restore is now retrievable. It is recorded in core, so a CLI
or a hook caller sees it too, and GET on the restore address renders it: 202
while running, 200 and the reason when stopped, 404 when this process has not
tried. POST still answers 204, because the admin client reads a body on any
other 2xx.

A serialization failure or a deadlock is a transient and is retried at the
transaction boundary, which is the only place a retry means anything — the
second statement of a deadlocked transaction reports 25P02, so retrying a
statement spends the attempt and loses the evidence. The transaction watches
its own statements for the two SQLSTATEs rather than reading the returned
error, which by then has been wrapped down to a message string. Batch had to
become re-runnable for this: it accumulated results outside the transaction.

Retrying turns a transient into a success and does not pretend to fix a
convoy: with a few concurrent opposing batches the loss goes to zero, and
with thirty pairs over six rows every pair collides and no budget clears it.

SQLite keeps the same executions at the same intervals.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-13 13:09:18 -07:00

30 lines
782 B
Go

package core
import (
"strings"
"testing"
"github.com/hanzoai/orm/dialect"
)
// A backup is an archive of the data directory, so it is a backup of the
// database only while the engine keeps the database there. An engine that keeps
// it in the server says so, and names itself, rather than writing an archive
// that would restore nothing.
func TestCheckLocalDatabase(t *testing.T) {
t.Parallel()
if err := checkLocalDatabase(dialect.SQLite{}); err != nil {
t.Fatalf("Expected sqlite to archive its own database, got %v", err)
}
err := checkLocalDatabase(dialect.Postgres{})
if err == nil {
t.Fatal("Expected postgres to refuse, got nil")
}
if !strings.Contains(err.Error(), "postgres") {
t.Fatalf("Expected the refusal to name the engine, got %q", err)
}
}