Liking cljdoc? Tell your friends :D

com.blockether.vis.internal.persistance.sqlite.core

SQLite store - V1 schema implementation.

Implements the persistence facade's Store protocol: backend, at the end of this file, hands the facade every op through store-implementation, which clj-kondo cannot expand, so the ns-level config above silences :unused-public-var for the whole file. The call surface is verified through the storage facade tests.

Tables (V1__schema.sql): session_soul, session_state, session_turn_soul, session_turn_state, session_turn_iteration, llm_routing_event, extension_aggregate

Connection lifecycle: (db-open! db-spec) -> {:datasource ds :path ...} (db-close! store) -> idempotent dispose

SQLite store - V1 schema implementation.

Implements the persistence facade's `Store` protocol: `backend`, at the end
of this file, hands the facade every op through `store-implementation`,
which clj-kondo cannot expand, so the ns-level config above silences
`:unused-public-var` for the whole file. The call surface is verified
through the storage facade tests.

Tables (V1__schema.sql):
  session_soul, session_state,
  session_turn_soul, session_turn_state,
  session_turn_iteration, llm_routing_event,
  extension_aggregate

Connection lifecycle:
  (db-open! db-spec)   -> {:datasource ds :path ...}
  (db-close! store)    -> idempotent dispose
raw docstring

com.blockether.vis.internal.persistance.sqlite.maintenance

Space reclamation for a file-backed SQLite store.

SQLite does not give the file back by itself. Pages that a delete or a DROP COLUMN frees go on the FREELIST, and later writes use them again. A one-off bulk reclaim (retiring a column across a whole transcript) can leave hundreds of megabytes in the file.

maybe-vacuum! gives that space back when the freelist is at least vacuum-min-free-bytes. A compact store is never touched, so the usual answer is four PRAGMAs and no I/O.

Writers never wait for the whole file. A store with auto_vacuum=INCREMENTAL frees its freelist with PRAGMA incremental_vacuum(N) in chunks of vacuum-chunk-pages. Each chunk is its own short write transaction, and a pause after each chunk lets waiting writers take the lock. Mozilla storage does the same (mozStorageConnection.cpp AsyncVacuum, application-services maintenance.rs). use-incremental-vacuum! gives each new store this mode. Two processes that reclaim one store at the same time only take turns.

A store with auto_vacuum=NONE (made by an older Vis) has no page map for this. One full VACUUM with auto_vacuum=INCREMENTAL converts it, and it is its last full VACUUM. That rewrite holds the write lock for the whole file (measured: 15 s for 2.4 GB), so it runs only when the store is at most vacuum-max-file-bytes, inside the 30 s busy timeout of core. A larger old store keeps its freelist, and SQLite uses those pages again: on a 17 GB store the rewrite held the lock for many minutes and each turn write failed or waited. The vis.db.vacuum file beside the store is the cross-process lock of this conversion, an exclusive FileLock. The next reclaim of the converted store deletes it.

The work runs off the open path: vacuum-async! gives it to internal.janitor, the one maintenance worker of a process. One pass frees pages for at most vacuum-slice-ms and then queues the next pass, so a long freelist never holds the other chores for more than one slice. Each chunk and each rewrite is a transaction, so a process that stops first leaves a consistent store, and the rest stays due.

Space reclamation for a file-backed SQLite store.

SQLite does not give the file back by itself. Pages that a delete or a `DROP
COLUMN` frees go on the FREELIST, and later writes use them again. A one-off
bulk reclaim (retiring a column across a whole transcript) can leave hundreds
of megabytes in the file.

`maybe-vacuum!` gives that space back when the freelist is at least
`vacuum-min-free-bytes`. A compact store is never touched, so the usual
answer is four PRAGMAs and no I/O.

Writers never wait for the whole file. A store with `auto_vacuum=INCREMENTAL`
frees its freelist with `PRAGMA incremental_vacuum(N)` in chunks of
`vacuum-chunk-pages`. Each chunk is its own short write transaction, and a
pause after each chunk lets waiting writers take the lock. Mozilla storage
does the same (`mozStorageConnection.cpp` AsyncVacuum, application-services
`maintenance.rs`). `use-incremental-vacuum!` gives each new store this mode.
Two processes that reclaim one store at the same time only take turns.

A store with `auto_vacuum=NONE` (made by an older Vis) has no page map for
this. One full VACUUM with `auto_vacuum=INCREMENTAL` converts it, and it is
its last full VACUUM. That rewrite holds the write lock for the whole file
(measured: 15 s for 2.4 GB), so it runs only when the store is at most
`vacuum-max-file-bytes`, inside the 30 s busy timeout of `core`. A larger old
store keeps its freelist, and SQLite uses those pages again: on a 17 GB store
the rewrite held the lock for many minutes and each turn write failed or
waited. The `vis.db.vacuum` file beside the store is the cross-process lock
of this conversion, an exclusive `FileLock`. The next reclaim of the
converted store deletes it.

The work runs off the open path: `vacuum-async!` gives it to
`internal.janitor`, the one maintenance worker of a process. One pass frees
pages for at most `vacuum-slice-ms` and then queues the next pass, so a long
freelist never holds the other chores for more than one slice. Each chunk and
each rewrite is a transaction, so a process that stops first leaves a
consistent store, and the rest stays due.
raw docstring

com.blockether.vis.internal.persistance.sqlite.migration

Flyway-backed schema migration runner.

Lives in the SQLite extension because:

  1. The dialect-specific Flyway driver (flyway-database-nc-sqlite) is required to recognize jdbc:sqlite: URLs - already declared in this extension's deps.edn.
  2. Flyway is the only backend-side concern using flyway-core; making it a per-backend dep keeps the root package free of the migration toolchain.
  3. The previous arrangement shipped a generic migrate! from com.blockether.vis.sdk, but it had exactly one caller
    • this extension. Other backends will ship their own migration entry point in their own jar.

Public API:

(migrate! datasource locations) - apply every Flyway migration found at the given classpath locations to the supplied DataSource. Returns the datasource for thread-style chaining.

:baseline-on-migrate true so existing databases without a flyway_schema_history table get one on first run. :mixed true so SQL files with mixed transactional + DDL statements work under SQLite.

GraalVM native-image note: Flyway discovers migrations by LISTING the classpath location directory, which native-image does not support (it can getResource a specific file but not enumerate a dir). So build.clj writes an _index.edn of filenames next to each migration dir, and here we feed Flyway an explicit ResourceProvider built from those exact paths, paired with an empty Java migration ClassProvider for our SQL-only schema. Both providers are required to bypass scanning. On the JVM (no index) we fall back to Flyway's normal location scanning.

Flyway-backed schema migration runner.

Lives in the SQLite extension because:

  1. The dialect-specific Flyway driver (`flyway-database-nc-sqlite`)
     is required to recognize `jdbc:sqlite:` URLs - already
     declared in this extension's deps.edn.
  2. Flyway is the only backend-side concern using
     `flyway-core`; making it a per-backend dep keeps the root
     package free of the migration toolchain.
  3. The previous arrangement shipped a generic `migrate!` from
     `com.blockether.vis.sdk`, but it had exactly one caller
     - this extension. Other backends will ship their own
     migration entry point in their own jar.

Public API:

  `(migrate! datasource locations)` - apply every Flyway
  migration found at the given classpath `locations` to the
  supplied `DataSource`. Returns the datasource for thread-style
  chaining.

`:baseline-on-migrate true` so existing databases without a
`flyway_schema_history` table get one on first run. `:mixed true`
so SQL files with mixed transactional + DDL statements work under
SQLite.

GraalVM native-image note: Flyway discovers migrations by LISTING the
classpath location directory, which native-image does not support (it can
`getResource` a specific file but not enumerate a dir). So `build.clj` writes
an `_index.edn` of filenames next to each migration dir, and here we feed
Flyway an explicit `ResourceProvider` built from those exact paths, paired
with an empty Java migration `ClassProvider` for our SQL-only schema. Both
providers are required to bypass scanning. On the JVM (no index) we fall
back to Flyway's normal location scanning.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close