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
//! Poison-recovering accessors for the locks held inside [`ServerState`].
//!
//! Engram runs as a single-user, per-project daemon: one server process owns
//! one database, one index set, and one router. When a thread panics while
//! holding one of these locks, the standard-library lock becomes *poisoned*
//! and every subsequent `.lock()/.read()/.write()` returns `Err`. A raw
//! `.unwrap()` on that result turns a single recoverable hiccup into a
//! cascading crash that takes down the whole daemon and every in-flight
//! client request.
//!
//! For this deployment model recovery is strictly preferable to a cascading
//! panic: the protected state is plain in-memory data, and a poisoned guard
//! still references fully-formed (if possibly partially-updated) state that
//! later operations can read and overwrite. These helpers therefore recover
//! unconditionally via [`PoisonError::into_inner`], returning the *bare*
//! guard. Recovery is total — there is no error path a caller could meaningfully
//! handle — so the helpers deliberately do not wrap the guard in `Result`.
use ;
use Router;
use Database;
use crateIndexSet;
use crateServerState;
/// Locks the database mutex, recovering the guard if the lock was poisoned.
/// Locks the router mutex, recovering the guard if the lock was poisoned.
/// Acquires a shared read guard on the index set, recovering if poisoned.
/// Acquires an exclusive write guard on the index set, recovering if poisoned.