pub fn rewrite(
store: &dyn Store,
by: Author,
with: &dyn Rewrite,
) -> Result<Rewritten, SessionError>Expand description
Rewrites the session in store through with, as done by by, in
place: every record stays where it is with its stamp, and every value
in it goes through with (see Rewrite). Each log a record of which
changed gets a fresh lineage and {t, by} added to its header’s
rewrites.
Every log is read strictly, and every
changed log is encoded and folded strictly in memory, before anything
is written. Then torn tails
are set aside (as Writer::open does), new
blobs are stored, each changed log is replaced
(Store::replace_log), every file of the store goes through
Rewrite::file (each written atomically), and blobs no record names
any more are removed last.
What a reader sees: each log is the old one or the new one, whole;
across logs a reader during a rewrite may see some rewritten and some
not, and each always reads. A crash midway leaves some logs and files
rewritten; running the same map again finishes it. A conversation
read before the rewrite no longer continues a changed log: save of
it gives SessionError::Changed, and the caller reads it again.
Not for a session a running Writer logs to: no
process may rewrite a running session; rig-memory cannot tell, so a
program rewriting a rig session first checks that no rig runs it.
Files kept outside the store are the program’s to map with the same
with (rewrite_value, rewrite_file).
§Errors
As Session::read (a session of another format, or broken, is
refused, nothing written), or when a rewritten log would not read
(nothing written), or a write fails.