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
server/hook/hook.go +10−6
| @@ -94,7 +94,7 @@ func PreReceive(cfg Config) int { | |||
| 94 | 94 | err error | |
| 95 | 95 | ) | |
| 96 | 96 | if cfg.InstanceDB != "" { | |
| 97 | acls, err = access.Open(cfg.InstanceDB) | ||
| 97 | acls, err = access.OpenReader(cfg.InstanceDB) | ||
| 98 | 98 | if err != nil { | |
| 99 | 99 | reject(cfg.Out, "cannot open the access rules: %v", err) | |
| 100 | 100 | return 1 | |
| @@ -103,8 +103,9 @@ func PreReceive(cfg Config) int { | |||
| 103 | 103 | // The push gate runs as a separate process, so it opens the instance | |
| 104 | 104 | // database itself to learn the actor's instance-wide role. Without this the | |
| 105 | 105 | // hook would enforce only repository entries and silently ignore an | |
| 106 | // invitation that granted contribute everywhere. | ||
| 107 | ident, err := identity.Open(cfg.InstanceDB) | ||
| 106 | // invitation that granted contribute everywhere. Every handle the hook opens | ||
| 107 | // is read-only: a push is a check, never a schema change. | ||
| 108 | ident, err := identity.OpenReader(cfg.InstanceDB) | ||
| 108 | 109 | if err != nil { | |
| 109 | 110 | reject(cfg.Out, "cannot open the roster: %v", err) | |
| 110 | 111 | return 1 | |
| @@ -116,7 +117,7 @@ func PreReceive(cfg Config) int { | |||
| 116 | 117 | acls.Active = ident.Active | |
| 117 | 118 | // The lock table shares that database, so the push path learns what is held | |
| 118 | 119 | // without a second endpoint and without the client's cooperation. | |
| 119 | lockTable, err = lfs.OpenLocks(cfg.InstanceDB) | ||
| 120 | lockTable, err = lfs.OpenLocksReader(cfg.InstanceDB) | ||
| 120 | 121 | if err != nil { | |
| 121 | 122 | reject(cfg.Out, "cannot open the lock table: %v", err) | |
| 122 | 123 | return 1 | |
| @@ -124,7 +125,7 @@ func PreReceive(cfg Config) int { | |||
| 124 | 125 | defer lockTable.Close() | |
| 125 | 126 | // Channels share that database and decide whether a release may change, so | |
| 126 | 127 | // the push path reads them at the same single point as the rest of the gate. | |
| 127 | chanStore, err = channel.Open(cfg.InstanceDB) | ||
| 128 | chanStore, err = channel.OpenReader(cfg.InstanceDB) | ||
| 128 | 129 | if err != nil { | |
| 129 | 130 | reject(cfg.Out, "cannot open the channel table: %v", err) | |
| 130 | 131 | return 1 | |
| @@ -889,9 +890,12 @@ func shortOrNone(sha string) string { | |||
| 889 | 890 | // process that answers one push and exits, so the store is opened per check and not | |
| 890 | 891 | // closed: the close would come after the answer, and the process ends there anyway. | |
| 891 | 892 | // The server, which is long-lived, passes its own open handle instead. | |
| 893 | // | ||
| 894 | // The handle is read-only. A push asks the queue which checks passed; it must not | ||
| 895 | // create a schema or rebuild an index inside the push it is deciding. | ||
| 892 | 896 | func openRuns(path string) func() (*runs.Store, error) { | |
| 893 | 897 | if path == "" { | |
| 894 | 898 | return nil | |
| 895 | 899 | } | |
| 896 | return func() (*runs.Store, error) { return runs.Open(path) } | ||
| 900 | return func() (*runs.Store, error) { return runs.OpenReader(path) } | ||
| 897 | 901 | } | |