Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a39442eac |
@@ -42,9 +42,9 @@ var schemaFS embed.FS
|
||||
// table itself. It is applied before the normal migration loop.
|
||||
const bootstrapVersion = 0
|
||||
|
||||
// busyTimeoutMsec is how long a connection to the index waits for another
|
||||
// busyTimeoutMs is how long a connection to the index waits for another
|
||||
// connection's lock before failing with "database is locked".
|
||||
const busyTimeoutMsec = 10000
|
||||
const busyTimeoutMs = 10000
|
||||
|
||||
// DB represents the Vaultik local index database connection.
|
||||
// It uses SQLite to track file metadata, content-defined chunks, and blob associations.
|
||||
@@ -108,7 +108,7 @@ func indexDSN(path string) string {
|
||||
return fmt.Sprintf(
|
||||
"%s?_pragma=busy_timeout(%d)&_pragma=journal_mode(WAL)"+
|
||||
"&_pragma=synchronous(NORMAL)&_pragma=foreign_keys(1)",
|
||||
path, busyTimeoutMsec)
|
||||
path, busyTimeoutMs)
|
||||
}
|
||||
|
||||
// New creates a new database connection at the specified path.
|
||||
@@ -152,7 +152,7 @@ func New(ctx context.Context, path string) (*DB, error) {
|
||||
}
|
||||
|
||||
// If the first attempt failed, try once more
|
||||
return openWithRecovery(ctx, path)
|
||||
return retryOpen(ctx, path)
|
||||
}
|
||||
|
||||
// configureConnPool serializes all database access through one connection.
|
||||
@@ -179,10 +179,10 @@ func finishOpen(ctx context.Context, conn *sql.DB, path string) (*DB, error) {
|
||||
return db, nil
|
||||
}
|
||||
|
||||
// openWithRecovery makes a second attempt to open the database, with the
|
||||
// same settings, after the first attempt failed, for example because
|
||||
// another process held a lock for longer than the busy timeout.
|
||||
func openWithRecovery(ctx context.Context, path string) (*DB, error) {
|
||||
// retryOpen makes a second attempt to open the database, with the same
|
||||
// settings, after the first attempt failed, for example because another
|
||||
// process held a lock for longer than the busy timeout.
|
||||
func retryOpen(ctx context.Context, path string) (*DB, error) {
|
||||
log.Info("Database appears locked, retrying open", "path", path)
|
||||
|
||||
conn, err := sql.Open("sqlite", indexDSN(path))
|
||||
@@ -202,7 +202,7 @@ func openWithRecovery(ctx context.Context, path string) (*DB, error) {
|
||||
_ = conn.Close()
|
||||
|
||||
return nil, fmt.Errorf(
|
||||
"database still locked after recovery attempt: %w",
|
||||
"database still locked on retry: %w",
|
||||
err,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -153,8 +153,8 @@ func TestNewSetsJournalModeAndBusyTimeout(t *testing.T) {
|
||||
t.Fatalf("reading busy_timeout: %v", err)
|
||||
}
|
||||
|
||||
if busyTimeout != busyTimeoutMsec {
|
||||
t.Errorf("busy_timeout = %d, want %d", busyTimeout, busyTimeoutMsec)
|
||||
if busyTimeout != busyTimeoutMs {
|
||||
t.Errorf("busy_timeout = %d, want %d", busyTimeout, busyTimeoutMs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user