fix: replace named locks with Galera-compatible row locks
Test / test (push) Successful in 25m39s
Build and publish image / image (push) Successful in 16m16s

This commit is contained in:
bryanpedini committed 2026-11-20 16:27:15 +01:00
1 parent ee07866d1c
commit 65d16c2fc6
22 files changed
+314 -365

No files matched your search

+3 -2
View File
@@ -161,7 +161,7 @@ The connection is built with `mysql.Config` from `github.com/go-sql-driver/mysql
2. Initialize the logger and log version and commit.
3. Open the pool and ping MySQL, retrying with backoff for up to 30 seconds.
4. Verify the records table contract (section 3).
5. Apply the application's migrations (section 6) while holding the MySQL named lock `<prefix>webui_migrate` (`GET_LOCK`, 30 s timeout), so several instances starting together never race.
5. Bootstrap the InnoDB lock table and apply the migrations while holding a row lock on its migration key (30 s acquisition timeout). DDL runs on a separate connection because it commits implicitly. During migrations, Galera application connections use the same writer.
6. Start a background task that deletes expired sessions every 10 minutes.
7. Register the routes and listen on `${HTTP_ADDR}:${HTTP_PORT}` with `ReadHeaderTimeout` 10 s, `ReadTimeout` 30 s, `WriteTimeout` 60 s, `IdleTimeout` 120 s and `MaxHeaderBytes` 64 KiB.
8. On `SIGINT` or `SIGTERM`, stop accepting connections, wait up to 25 seconds for running requests, stop the background task and close the pool.
@@ -293,6 +293,7 @@ MySQL allows table-level grants on tables that do not exist yet when `CREATE` is
```sql
CREATE USER 'coredns_webui'@'%' IDENTIFIED BY '<password>';
GRANT SELECT, INSERT, UPDATE, DELETE ON `coredns`.`coredns_records` TO 'coredns_webui'@'%';
GRANT SELECT, INSERT, UPDATE, CREATE ON `coredns`.`coredns_webui_locks` TO 'coredns_webui'@'%';
GRANT SELECT, INSERT, UPDATE, CREATE, ALTER, INDEX, REFERENCES ON `coredns`.`coredns_webui_schema` TO 'coredns_webui'@'%';
GRANT SELECT, INSERT, UPDATE, CREATE, ALTER, INDEX, REFERENCES ON `coredns`.`coredns_webui_users` TO 'coredns_webui'@'%';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, INDEX, REFERENCES ON `coredns`.`coredns_webui_sessions` TO 'coredns_webui'@'%';
@@ -351,7 +352,7 @@ Warnings:
### Concurrency
Every write runs on a dedicated connection: take the named lock `<prefix>webui:<first 16 hex chars of sha256(zone)>` with `GET_LOCK` (10 s timeout, HTTP 503 "zone busy" on timeout), begin the transaction, check again that the actor may operate on the zone (the user row and, for role `user`, the delegation row read with `LOCK IN SHARE MODE`, so a concurrent revocation, demotion or deletion waits for the write or wins before it), read the zone's rows, apply the rules, write records, SOA serial and audit row, commit, release the lock. The lock serializes writers of this application; other writers of the table are detected through ETags.
Every write starts a transaction and updates its zone key in `<prefix>webui_locks` (10 s acquisition timeout, HTTP 503 "zone busy" on timeout or deadlock). Changing this row supplies a Galera certification key. The application then checks again that the actor may operate on the zone (the user row and, for role `user`, the delegation row read with `LOCK IN SHARE MODE`, so a concurrent revocation, demotion or deletion waits for the write or wins before it), reads the zone's rows, applies the rules, writes the records, SOA serial and audit row, and commits, releasing the lock. The lock serializes writers of this application; other writers of the table are detected through ETags.
Every record carries an ETag: the hex SHA-256 of `id`, `zone`, `name`, `ttl`, `record_type` and the raw `content`, with explicit markers for `NULL`. Updates and deletes require `If-Match`; inside the transaction the row is read with `SELECT ... FOR UPDATE` and compared. A missing `If-Match` is HTTP 428, a mismatch or a missing row is HTTP 412 and the UI offers to reload.