1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//! The [`Commit`] trait: finalizing one storage session.
use Error;
use Future;
use crateRetryableStorageError;
use crate;
/// Finalizes the writes performed through a mutable storage handle.
///
/// `Commit` is deliberately **separate from [`KvStore`]**. A read-only handle
/// and a write handle can both be `KvStore`s; only the write handle is a
/// *session* that has to be closed out. Keeping the two apart lets a caller
/// accept `KV: KvStore` where it only reads, and `KV: KvStore + Commit` where
/// it owns the session, and have the compiler enforce the difference.
///
/// # The atomicity rule
///
/// **One state-transition invocation = one storage session = one atomic
/// commit.** Everything a transition writes lands together or not at all.
/// Dropping a session before invoking `commit` is the rollback. Once `commit`
/// has been invoked, however, a non-retryable error may leave the caller unable
/// to tell whether the atomic commit happened.
///
/// `commit` **consumes `self`**, which is the whole point. A session cannot be
/// committed twice, cannot be written to after commit, and cannot be
/// accidentally shared across two transitions — the type system says so rather
/// than the documentation.
///
/// # In-memory backends
///
/// The in-memory `fasm-storage-btreemap` backend provides the same buffering
/// and rollback as the durable backends: `commit` applies the buffered writes
/// to the in-process base map, and dropping the transaction rolls them back.
/// It provides no crash atomicity — the base map is memory, so a crash loses
/// it — and it belongs in tests and simulations only.
///
/// [`KvStore`]: crate::KvStore