Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Give the instance database one write policy

8f6548a6249e86bfb4741a85cc6ca7efe8b3a064 · Keenan Nemetz · 3d ago · parent 1eac8552

Give the instance database one write policy

instance.db has one writer per file, and the server, the push hook, and
sshd's key command all open it. Each store picked its own pragmas, so a
transaction that read and then wrote could be refused with SQLITE_BUSY
without the busy timeout applying. And the push hook opened every store
with the writer open, which ran each schema inside a push: runs.Open
dropped and rebuilt the runs_once index on every call, over a run table
that is never pruned, while the server might be committing a lease.

Open every file through internal/sqlstore instead: WAL, synchronous=NORMAL,
and immediate write transactions, with a read-only mode for the processes
that only read. The hook and sshd's key lookup use that read-only mode, so a
push can no longer write a schema.

The queue's shape is applied once per database and recorded in a
schema_versions row, so reopening it does no DDL and an old unversioned
queue still upgrades. Write transactions that only touch the database retry
a lock conflict instead of failing the operation.

Refs #398

forge/access/store.go +13−5

@@ -17,9 +17,8 @@ import (
17 17 "fmt"
18 18 "time"
19 19
20 _ "modernc.org/sqlite"
21
22 20 "rodent.software/vole/internal/audit"
21 "rodent.software/vole/internal/sqlstore"
23 22 )
24 23
25 24 type Store struct {
@@ -50,12 +49,10 @@ var ErrConflict = errors.New("access: the rules changed since they were read; re
50 49 // file as the roster: access rules are keyed by account name, so the two have to be
51 50 // backed up and restored together or the ids stop resolving.
52 51 func Open(path string) (*Store, error) {
53 dsn := path + "?_busy_timeout=5000&_journal_mode=WAL"
54 db, err := sql.Open("sqlite", dsn)
52 db, err := sqlstore.Open(path, sqlstore.Options{MaxConns: 2})
55 53 if err != nil {
56 54 return nil, err
57 55 }
58 db.SetMaxOpenConns(2)
59 56 if _, err := db.Exec(`
60 57 CREATE TABLE IF NOT EXISTS repo_acl (
61 58 repo_id TEXT PRIMARY KEY,
@@ -77,6 +74,17 @@ CREATE TABLE IF NOT EXISTS repo_acl (
77 74 return &Store{db: db}, nil
78 75 }
79 76
77 // OpenReader opens the rules for a caller that only reads. The push hook asks
78 // whether an account may write a path; it never changes the rules, and a push
79 // must not be the reason a schema is written.
80 func OpenReader(path string) (*Store, error) {
81 d, err := sqlstore.Open(path, sqlstore.Options{MaxConns: 2, ReadOnly: true})
82 if err != nil {
83 return nil, err
84 }
85 return &Store{db: d}, nil
86 }
87
80 88 // addRevisionColumn adds repo_acl.revision to a table that predates it. SQLite has
81 89 // no ADD COLUMN IF NOT EXISTS, so the column list is read first.
82 90 func addRevisionColumn(db *sql.DB) error {