返回 DeepSeek-Reasonix
integrity.go
根目录 / internal / projectiondb / integrity.go
1 package projectiondb
2
3 import (
4 "context"
5 "database/sql"
6 "fmt"
7 )
8
9 // CheckIntegrity performs the full SQLite audit, including index consistency.
10 // It is separate from advisory metadata opening, never replaced by quick_check.
11 func CheckIntegrity(ctx context.Context, db *sql.DB) error {
12 return checkDatabaseIntegrity(ctx, db, false)
13 }
14
15 func checkDatabaseIntegrity(ctx context.Context, db *sql.DB, quick bool) error {
16 query := `PRAGMA integrity_check`
17 if quick {
18 query = `PRAGMA quick_check(1)`
19 }
20 var result string
21 if err := db.QueryRowContext(ctx, query).Scan(&result); err != nil {
22 return err
23 }
24 if result != "ok" {
25 return fmt.Errorf("projection integrity check: %s", result)
26 }
27 return nil
28 }
29
30 // IsCorruptionError distinguishes a damaged cache from contention or cancelled
31 // I/O. Only proven corruption may revoke a generation and quarantine its file.
32 func IsCorruptionError(err error) bool { return isCorruptionError(err) }
33
33 lines GO