summaryrefslogtreecommitdiff
path: root/tests/functional/custom-prefix/q.go
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2024-10-30 20:26:41 -0300
committerEuAndreh <eu@euandre.org>2024-10-31 19:57:42 -0300
commit5d53704f450788452837b18b26f54d235d883490 (patch)
tree91bb61d6f823523675ae9f93bb8561858bf7be14 /tests/functional/custom-prefix/q.go
parenttests/q.go: Replace ":memory:" with golite.InMemory (diff)
downloadfiinha-5d53704f450788452837b18b26f54d235d883490.tar.gz
fiinha-5d53704f450788452837b18b26f54d235d883490.tar.xz
src/q.go: Fix SQLite ~broken~ transactions
As per expected by SQLite, create new connections so they have independent transaction, and serialize its use via a channel with a single consumer. == Other changes === Remove `db` attribute from `queueT` type Now that `initDB()` can create many database connections (A.K.A. opaque pointers to the `sqlite3*` object), it makes more sense to hand to it the responsability to create and destroy these databases. So now a `queries.close()` includes what previously was `db.Close()`, and needing to do it was the only reason that made us keep the `db` attribute. The arguments to `initDB()` were adjusted to reflect that, as it no longer is given an initialized database handle, but only the database path, and does the creation of the handles by itself. === Shoehorn multi-statement queries into single-statement ones In order to avoid creating one `execSerialized()` function per attribute of the `queryT` queries, we try to leverage SQLite's built-in transactionality per individual statement. So compound queries that were previously done in multiple statements wrapped with a `inTx()` that could be shoe-horned into a single `SELECT` were rewritten to avoid having more of this application-level serialization. The topic/consumer owner validation was also changed: now it is a trigger on the relevant tables that `ABORT` the implicit/invisible transaction and makes the `INSERT` fail. In order to make this possible, the `"%s_owners"` table now has an extra column: `instance_id`. Despite being extra data, this meta-information isn't duplicated from anywhere else, and it is an actual useful information for operators to leverage. So now the trigger is responsible for stopping the transaction from going forward without adding an explicit `inTx()` around it, and the writes can mostly be shrunk to single-statement queries. Fortunately, all this is enough to fix the `new-instance-takeover` functional test.
Diffstat (limited to 'tests/functional/custom-prefix/q.go')
0 files changed, 0 insertions, 0 deletions