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.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 |