A DurableStore on konserve.
konserve.core/append writes the element and a pointer and nothing else,
which is what a write-ahead log wants: the cost of landing a record does not
grow with the number of records already landed. reduce-log folds it back on
restart. Both views the protocol owes a restarting node come from that one
log -- the ordered records directly, and the merged map as a fold -- so there
is no second key to keep in step with it.
append is a read-modify-write on the list pointer, so two in flight against
the same key interleave. The runtime issues writes from its event loop
without awaiting the non-durable ones, so two CAN be in flight. Every write
therefore goes through a single go-loop, one at a time.
Measured rather than assumed. Removing the writer and appending directly, forty writes issued without awaiting came back in the order
4 2 9 10 11 7 14 13 15 16 18 19 17 21 22 24 3 25 23 5 0 6 1 30 ...
All forty records were still there -- this is not, at least against the
in-memory store, a loss bug. It is an ORDERING bug, and that is bad enough
twice over. truncate-from replay depends on log order being issue order:
records applied out of order resurrect entries a later truncation dropped.
And the merged view is a fold over the log, so it takes its value from
whichever write happens to land last -- in that run {:n 35} where the node
had written {:n 39}. A restarting Raft would come back with a stale term
it never held.
This wraps a store you have already connected rather than connecting one, so
it works against a filestore on the JVM and IndexedDB in the browser without
this namespace knowing which. connect-fs-store! below is a JVM convenience,
not the seam.
Note that konserve.filestore fsyncs every blob by default
(:sync-blob? true), so a record marked :durable? false is still written
through to disk here. That is stronger than asked for, never weaker, and the
distinction that survives is the one the runtime acts on: a durable write's
gated effects wait for the disk and a buffered one's do not.
A `DurableStore` on konserve.
## Why konserve's append log rather than a key per write
`konserve.core/append` writes the element and a pointer and nothing else,
which is what a write-ahead log wants: the cost of landing a record does not
grow with the number of records already landed. `reduce-log` folds it back on
restart. Both views the protocol owes a restarting node come from that one
log -- the ordered records directly, and the merged map as a fold -- so there
is no second key to keep in step with it.
## Writes are serialized, and this is not paranoia
`append` is a read-modify-write on the list pointer, so two in flight against
the same key interleave. The runtime issues writes from its event loop
without awaiting the non-durable ones, so two CAN be in flight. Every write
therefore goes through a single go-loop, one at a time.
Measured rather than assumed. Removing the writer and appending directly,
forty writes issued without awaiting came back in the order
4 2 9 10 11 7 14 13 15 16 18 19 17 21 22 24 3 25 23 5 0 6 1 30 ...
All forty records were still there -- this is not, at least against the
in-memory store, a loss bug. It is an ORDERING bug, and that is bad enough
twice over. `truncate-from` replay depends on log order being issue order:
records applied out of order resurrect entries a later truncation dropped.
And the merged view is a fold over the log, so it takes its value from
whichever write happens to land last -- in that run `{:n 35}` where the node
had written `{:n 39}`. A restarting Raft would come back with a stale term
it never held.
## Portability
This wraps a store you have already connected rather than connecting one, so
it works against a filestore on the JVM and IndexedDB in the browser without
this namespace knowing which. `connect-fs-store!` below is a JVM convenience,
not the seam.
Note that `konserve.filestore` fsyncs every blob by default
(`:sync-blob? true`), so a record marked `:durable? false` is still written
through to disk here. That is stronger than asked for, never weaker, and the
distinction that survives is the one the runtime acts on: a durable write's
gated effects wait for the disk and a buffered one's do not.(connect-fs-store! path)(connect-fs-store! path opts)Connect a filestore at path and wrap it. JVM convenience.
Synchronous, because it belongs in start-up rather than in a go block.
Connect a filestore at `path` and wrap it. JVM convenience. Synchronous, because it belongs in start-up rather than in a go block.
Where the write log lives. Namespaced so a store shared with an application -- datahike on the same konserve, say -- cannot collide with it.
Where the write log lives. Namespaced so a store shared with an application -- datahike on the same konserve, say -- cannot collide with it.
(konserve-store ks)(konserve-store ks {:keys [log-key] :or {log-key default-log-key}})Wrap a connected konserve store ks.
Options: :log-key to place the write log somewhere other than the default.
The konserve store is NOT closed by close-store! -- it may be shared with
an application, and closing something you were lent is not yours to do.
Wrap a connected konserve store `ks`. Options: `:log-key` to place the write log somewhere other than the default. The konserve store is NOT closed by `close-store!` -- it may be shared with an application, and closing something you were lent is not yours to do.
Legacy shared checkpoint manifest. Its :log-key identifies a physical log, but older releases did not record which configured log owned it.
Legacy shared checkpoint manifest. Its :log-key identifies a physical log, but older releases did not record which configured log owned it.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |