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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
//! Errors arising from memory tracking
use crate::internal_prelude::*;
/// An error occurring when tracking memory usage
#[derive(Debug, Clone, Error)]
#[non_exhaustive]
pub enum Error {
/// The memory quota tracker has been torn down
#[error("attempted to use shut down memory tracker")]
TrackerShutdown,
/// The Account has been torn down
///
/// This can happen if the account or participant has Collapsed due to reclamation
#[error("memory pressure (attempted to use closed memory tracking account)")]
AccountClosed,
/// The Participant has been torn down
///
/// This can happen if the account or participant has Collapsed due to reclamation
#[error("memory pressure (attempt to allocate by torn-down memory tracking participant)")]
ParticipantShutdown,
/// Previous bug, memory quota tracker is corrupted
#[error("memory tracker is corrupted due to previous bug")]
TrackerCorrupted,
/// Bug
#[error("internal error")]
Bug(#[from] Bug),
}
/// Memory pressure means this data structure (or other facility) was torn down
///
/// Error type suitable for use by data structures and facilities
/// which participate in memory tracking.
///
/// Convertible from a [`tor_memtrack::Error`](enum@Error),
/// or constructible via `Default` or [`new`](MemoryReclaimedError::new).
#[derive(Debug, Clone, Error, Default)]
#[non_exhaustive]
#[error("{0}")]
pub struct MemoryReclaimedError(ReclaimedErrorInner);
/// Content of a [`MemoryReclaimedError`]
// Separate struct so we don't expose the variants
#[derive(Debug, Clone, Error, Default)]
enum ReclaimedErrorInner {
/// Collapsed, from `ReclaimedError::new`
#[error("data structure discarded due to memory pressure")]
#[default]
Collapsed,
/// Othere error from tracker
#[error("{0}")]
TrackerError(#[from] Error),
}
/// An error occurring when setting up a memory quota tracker
#[derive(Debug, Clone, Error)]
#[non_exhaustive]
pub enum StartupError {
/// Task spawn failed
#[error("couldn't spawn reclamation task")]
Spawn(#[source] Arc<SpawnError>),
}
impl From<SpawnError> for StartupError {
fn from(e: SpawnError) -> StartupError {
StartupError::Spawn(Arc::new(e))
}
}
/// Tracker corrupted
///
/// Separate type so we don't expose `PoisonError -> crate::Error` conversion
#[derive(Debug, Clone, Error)]
#[error("poisoned (corrupted)")]
pub(crate) struct TrackerCorrupted;
impl<T> From<PoisonError<T>> for TrackerCorrupted {
fn from(_: PoisonError<T>) -> TrackerCorrupted {
TrackerCorrupted
}
}
impl From<TrackerCorrupted> for Error {
fn from(_: TrackerCorrupted) -> Error {
Error::TrackerCorrupted
}
}
/// Error returned when reclaim task crashes
///
/// Does not escape the crate; is used for logging.
#[derive(Debug, Clone, Error)]
pub(crate) enum ReclaimCrashed {
/// Previous bug, memory quota tracker is corrupted
#[error("memory tracker corrupted due to previous bug")]
TrackerCorrupted(#[from] TrackerCorrupted),
/// Bug
#[error("internal error")]
Bug(#[from] Bug),
}
impl MemoryReclaimedError {
/// Create a new `MemoryReclaimedError` (with no additional information)
pub fn new() -> Self {
MemoryReclaimedError::default()
}
}
impl From<Error> for MemoryReclaimedError {
fn from(e: Error) -> MemoryReclaimedError {
MemoryReclaimedError(e.into())
}
}
impl HasKind for MemoryReclaimedError {
fn kind(&self) -> ErrorKind {
use ErrorKind as EK;
use ReclaimedErrorInner as REI;
match &self.0 {
REI::Collapsed => EK::LocalResourceExhausted,
REI::TrackerError(e) => e.kind(),
}
}
}
impl HasKind for Error {
fn kind(&self) -> ErrorKind {
use Error as E;
use ErrorKind as EK;
match self {
E::TrackerShutdown => EK::ArtiShuttingDown,
E::AccountClosed => EK::LocalResourceExhausted,
E::ParticipantShutdown => EK::LocalResourceExhausted,
E::TrackerCorrupted => EK::Internal,
E::Bug(e) => e.kind(),
}
}
}
|