feat(sync-service): Scale SQLite connection pool to 0#3908
feat(sync-service): Scale SQLite connection pool to 0#3908magnetised wants to merge 9 commits intomainfrom
Conversation
❌ 1 Tests Failed:
View the top 2 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
72269af to
0c0a256
Compare
0c0a256 to
023caa8
Compare
Claude Code ReviewSummaryRound 16: Four new commits since round 15 — "refactor statistics module", "change supervisor strategy", "don't crash stats task", and a merge. This is a substantial refactor: Statistics no longer initialises via CI is still showing consistent failures that need attention before merging. What's Working Well
Issues FoundCritical (Must Fix)None. Important (Should Fix)1. File: The SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'dbstat'
The current CI failure "statistics only exports disk usage by default" is consistent with this: the test now calls Suggested fix: probe by querying the table directly: dbstat_available? =
case Connection.fetch_one(conn, "SELECT 1 FROM dbstat LIMIT 1", []) do
{:ok, _} -> true # row returned
:error -> true # table exists but db is empty (0 rows ≠ table missing)
{:error, _} ->
if first_run?,
do: Logger.warning("SQLite disk size statistics will not be available.")
false
endOnly a query error ("no such table: dbstat") means the extension is absent. 2. File: Blacksmith CI shows this test failing across 4 concurrent jobs in the latest run, with:
The test sends The test has no explicit timeout, so the 400 ms in the error is the ExUnit default. Adding a longer timeout is a quick fix: assert_receive {:DOWN, ^buffer_ref, :process, ^write_buffer_pid, :some_reason}, 5000
assert_receive {:DOWN, ^super_ref, :process, ^supervisor_pid, _}, 5000Alternatively, pre-flush the buffer before the 3. File: defp wait_statistics(_ctx, 0), do: :error
defp wait_statistics(ctx, remaining_attempts) do
case ShapeDb.statistics(ctx.stack_id) do
{:ok, %{updated_at: %DateTime{}} = stats} -> {:ok, stats}
{:ok, _} ->
Process.sleep(10)
wait_statistics(ctx, remaining_attempts - 1)
end
end10 retries × 10 ms = 100 ms total. The probe runs a defp wait_statistics(_ctx, 0), do: :error
defp wait_statistics(ctx, remaining_attempts) do
case ShapeDb.statistics(ctx.stack_id) do
{:ok, %{updated_at: %DateTime{}} = stats} -> {:ok, stats}
{:ok, _} ->
Process.sleep(50)
wait_statistics(ctx, remaining_attempts - 1)
end
end50 ms × 10 = 500 ms should cover any reasonable CI latency. Or just use Suggestions (Nice to Have)4. File: Still present. In practice the underlying esqlite3 implementation is a no-op that always returns 5. File: The comment says "should not normally be reached", but given issue #1 above ( Issue ConformanceNo linked issue — unchanged from all previous rounds. Previous Review Status
Review iteration: 16 | 2026-03-05 |
|
@magnetised I've looked through the issues Claude flagged up, all for them look legit. Please ping me when ready for another review round. |
023caa8 to
90029c5
Compare
This comment has been minimized.
This comment has been minimized.
90029c5 to
f8fa293
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
df9efb8 to
292b144
Compare
|
@alco think we can ignore claude's suggestions. ready for another look pls |
9772e20 to
3d410a6
Compare
This comment has been minimized.
This comment has been minimized.
packages/sync-service/lib/electric/shape_cache/shape_status/shape_db/connection.ex
Outdated
Show resolved
Hide resolved
packages/sync-service/lib/electric/shape_cache/shape_status/shape_db/connection.ex
Outdated
Show resolved
Hide resolved
packages/sync-service/lib/electric/shape_cache/shape_status/shape_db/connection.ex
Outdated
Show resolved
Hide resolved
812f743 to
e95c5ae
Compare
524f5f8 to
b316a68
Compare
d31116a to
872c8bd
Compare
|
Found 2 test failures on Blacksmith runners: Failures
|
872c8bd to
b281e9b
Compare
so stats retrieval is not blocked by concurrent reading of stats
because now we're maybe shutting the write connection when idle, this will log all the time
b281e9b to
9b362c9
Compare
9b362c9 to
e463c12
Compare
NimblePool allows for lazy initialization and scale down of SQLite connections. This PR adds support for that.
The scaling is disabled for exclusive_mode as an exclusive_mode db could be in-memory, and closing that would be catastrophic.
I've added the number of active connections to the exported data. Will be interesting to see what goes on there, in both the larger instances and the many less-active ones.
This disables sqlite statistics collection by default as the usefulness of the exported numbers is low without memory statistics enabled, and enabling memory stats is potentially causing issues in some deployments.