Skip to main content

coven_storage/
memory_faults.rs

1//! Faults the in-memory provider injects into its next calls.
2
3use super::BodyFailure;
4use crate::*;
5use std::collections::{BTreeMap, BTreeSet};
6use std::time::Duration;
7
8/// Faults applied to the next calls, including accepted parts with lost replies.
9#[derive(Clone)]
10pub struct Faults {
11    /// Fail this many calls before doing their work.
12    pub fail_next: usize,
13    /// Refuse this many file uploads as they start, each with `failure`,
14    /// `response` and `retry_after` as `fail_next` fails a call: a file's
15    /// single create, or the call beginning its multipart upload. Nothing is
16    /// stored. Every other call goes through, so a pass beside the upload
17    /// can't take the fault.
18    pub refuse_file_uploads: usize,
19    /// Panic in this many file uploads as they start, as a bug in the
20    /// caller's upload would; every other call goes through.
21    pub panic_file_uploads: usize,
22    /// Panic in exact reads at these paths, as a bug in the reader would.
23    pub read_panics: BTreeSet<ObjectPath>,
24    /// Fail exact reads at these paths, retaining other in-flight responses.
25    pub read_failures: BTreeMap<ObjectPath, StorageFailure>,
26    /// Fail exact status calls at these paths, independently of reads.
27    pub status_failures: BTreeMap<ObjectPath, StorageFailure>,
28    /// Fail exact deletions at these paths; the object stays.
29    pub delete_failures: BTreeMap<ObjectPath, StorageFailure>,
30    /// Refuse creates at these paths with a provider response of this
31    /// HTTP status; nothing is stored.
32    pub create_failures: BTreeMap<ObjectPath, (StorageFailure, u16)>,
33    /// Fail listings of exactly these prefixes.
34    pub list_failures: BTreeMap<ObjectPrefix, StorageFailure>,
35    /// Maximum bytes returned by each body read; nonzero.
36    pub read_chunk_size: usize,
37    /// Failures after metadata, independently of request-start failures.
38    pub body_failures: BTreeMap<ObjectPath, BodyFailure>,
39    /// Change one byte of responses at these paths, each response
40    /// differently, as faults on the way to the device would; the stored
41    /// object stays as it was.
42    pub garbled_reads: BTreeMap<ObjectPath, Garble>,
43    /// The classification of injected failures.
44    pub failure: StorageFailure,
45    /// Injected failures arrive as a provider response with this HTTP
46    /// status (E5). None, without `retry_after`, is a request that received
47    /// no response.
48    pub response: Option<u16>,
49    /// Injected failures arrive as a response, a 429 unless `response`
50    /// names another status, asking every consumer to wait this many
51    /// seconds (`Retry-After`).
52    pub retry_after: Option<u64>,
53    /// Delay each call without blocking its executor.
54    pub delay: Duration,
55    /// Drop the next part before it is stored.
56    pub drop_part: bool,
57    /// Store the next part, but lose the reply before advancing the caller's session.
58    pub lose_part_reply: bool,
59    /// Start the next planned session's upload, but lose the reply: the
60    /// caller never learns the id of the session the provider holds.
61    pub lose_initiation_reply: bool,
62    /// Publish the next upload but lose the completion reply.
63    pub lose_completion_reply: bool,
64    /// Store the next create or replacement at each of these paths, then
65    /// lose its reply, once per path.
66    pub lose_reply_at: BTreeSet<ObjectPath>,
67    /// Refuse this many upload aborts, retaining the pending bytes.
68    pub abort_failures: usize,
69    /// Expire all pending sessions before the next call.
70    pub expire_uploads: bool,
71    /// Accept creates at occupied paths, violating the provider contract.
72    pub overwrite_create: bool,
73    /// Hide published objects from listings while exact reads and status still see them.
74    pub hide_listings: bool,
75    /// Hide objects no older than this lag; exact reads still see publication.
76    pub listing_lag: Option<Duration>,
77    /// Refuse a duplicate create but fail to abort its upload session.
78    pub fail_duplicate_cleanup: bool,
79    /// Store this many creates and replacements, then answer each with a
80    /// 429, as a copy publication does when its temporary's deletion is
81    /// refused after the object is published (ยง20.6).
82    pub refuse_after_storing: usize,
83    /// Refuse this many conditional replacements with `Conflict` although
84    /// they name the current revision, leaving the object unchanged, as
85    /// OneDrive can refuse every writer of one race.
86    pub refuse_replacements: usize,
87    /// Fail every grant of access to an account with this failure, as a
88    /// provider refusing to share the store would.
89    pub grant_failure: Option<StorageFailure>,
90    /// Fail this many acceptances of a join's invite before they change
91    /// anything, as a provider that cannot be reached would.
92    pub accept_failures: usize,
93    /// Fail this many undos of a join's acceptance before they change
94    /// anything, as a provider that cannot be reached would.
95    pub leave_failures: usize,
96}
97/// Faults on the way to the device that change one byte of a response.
98#[derive(Clone, Copy, Debug)]
99pub struct Garble {
100    /// The object offset whose byte changes, in a response that holds it.
101    pub at: u64,
102    /// How many such responses change.
103    pub reads: u8,
104}
105
106impl Faults {
107    /// No failures or delays.
108    pub fn none() -> Self {
109        Self {
110            fail_next: 0,
111            refuse_file_uploads: 0,
112            panic_file_uploads: 0,
113            read_panics: BTreeSet::new(),
114            read_failures: BTreeMap::new(),
115            status_failures: BTreeMap::new(),
116            delete_failures: BTreeMap::new(),
117            create_failures: BTreeMap::new(),
118            list_failures: BTreeMap::new(),
119            read_chunk_size: 64 * 1024,
120            body_failures: BTreeMap::new(),
121            garbled_reads: BTreeMap::new(),
122            failure: StorageFailure::Network,
123            response: None,
124            retry_after: None,
125            delay: Duration::ZERO,
126            drop_part: false,
127            lose_part_reply: false,
128            lose_initiation_reply: false,
129            lose_completion_reply: false,
130            lose_reply_at: BTreeSet::new(),
131            expire_uploads: false,
132            abort_failures: 0,
133            overwrite_create: false,
134            fail_duplicate_cleanup: false,
135            refuse_replacements: 0,
136            refuse_after_storing: 0,
137            grant_failure: None,
138            accept_failures: 0,
139            leave_failures: 0,
140            hide_listings: false,
141            listing_lag: None,
142        }
143    }
144}