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/channel/channel.go +16−3

@@ -20,7 +20,7 @@ import (
20 20 "strings"
21 21 "time"
22 22
23 _ "modernc.org/sqlite"
23 "rodent.software/vole/internal/sqlstore"
24 24 )
25 25
26 26 const (
@@ -106,11 +106,10 @@ func Open(path string) (*Store, error) {
106 106 if _, err := os.Stat(path); err != nil {
107 107 return nil, fmt.Errorf("channel: %s is missing; run vole admin init", path)
108 108 }
109 db, err := sql.Open("sqlite", path+"?_busy_timeout=5000&_journal_mode=WAL")
109 db, err := sqlstore.Open(path, sqlstore.Options{MaxConns: 4})
110 110 if err != nil {
111 111 return nil, err
112 112 }
113 db.SetMaxOpenConns(4)
114 113 s := &Store{db: db}
115 114 if _, err := db.Exec(`
116 115 CREATE TABLE IF NOT EXISTS release_channels (
@@ -132,6 +131,20 @@ CREATE INDEX IF NOT EXISTS release_channels_tag ON release_channels(repo_id, tag
132 131 }
133 132
134 133 // Close releases the database.
134 // OpenReader opens the channel table for a caller that only reads. The push
135 // hook decides whether a release may change, and a push must not be the reason a
136 // schema is written.
137 func OpenReader(path string) (*Store, error) {
138 if _, err := os.Stat(path); err != nil {
139 return nil, fmt.Errorf("channel: %s is missing; run vole admin init", path)
140 }
141 d, err := sqlstore.Open(path, sqlstore.Options{MaxConns: 4, ReadOnly: true})
142 if err != nil {
143 return nil, err
144 }
145 return &Store{db: d}, nil
146 }
147
135 148 func (s *Store) Close() error {
136 149 if s == nil || s.db == nil {
137 150 return nil