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
// Authors: Robert Lopez
use super::{
error::Error,
util::map_data_file::{map_data_file, map_data_files},
BlockDB,
};
impl BlockDB {
/// Recovers a specific `DataFile` to a known good state.
///
/// During recovery, the `DataFile` will replay its WAL,
/// truncate the binary file to the correct length,
/// and update in-memory state accordingly.
///
/// ---
/// - **Atomic**
/// - **Non-corruptible**
///
/// ---
/// Example
/// ``` let block_db = BlockDB::open("./data", None).await?;
///
/// block_db.recover_data_file("3f-6hf").await?;
/// ```
/// ---
pub async fn recover_data_file<S: AsRef<str>>(&self, data_file_id: S) -> Result<(), Error> {
map_data_file!(self, data_file_id.as_ref(), recover);
Ok(())
}
/// Recovers all `DataFile`s to a known good state.
///
/// During recovery, each `DataFile` will replay its WAL and truncate the
/// binary file to the correct length. This process restores the in-memory
/// state to match the persistent state on disk.
///
/// ---
/// - **Atomic**
/// - **Non-corruptible**
///
/// ---
/// Example
/// ``` let block_db = BlockDB::open("./data", None).await?;
///
/// block_db.recover_data_files().await?;
/// ```
/// ---
pub async fn recover_data_files(&self) -> Result<(), Error> {
map_data_files!(self, recover);
Ok(())
}
}