-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathmod.rs
More file actions
85 lines (65 loc) · 2.69 KB
/
mod.rs
File metadata and controls
85 lines (65 loc) · 2.69 KB
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
// Copyright (c) 2017-present, PingCAP, Inc. Licensed under Apache-2.0.
use std::io::{Read, Result, Seek, Write};
use std::path::Path;
use std::sync::Arc;
mod default;
mod obfuscated;
pub use default::DefaultFileSystem;
pub use obfuscated::ObfuscatedFileSystem;
use crate::pipe_log::FileBlockHandle;
/// FileSystem
pub trait FileSystem: Send + Sync {
type Handle: Send + Sync + Handle;
type Reader: Seek + Read + Send;
type Writer: Seek + Write + Send + WriteExt;
type MultiReadContext;
fn multi_read(
&self,
ctx: &mut Self::MultiReadContext,
handle: Arc<Self::Handle>,
block: &FileBlockHandle,
) -> Result<()>;
fn async_finish(&self, ctx: Self::MultiReadContext) -> Result<Vec<Vec<u8>>>;
fn create<P: AsRef<Path>>(&self, path: P) -> Result<Self::Handle>;
fn open<P: AsRef<Path>>(&self, path: P) -> Result<Self::Handle>;
fn delete<P: AsRef<Path>>(&self, path: P) -> Result<()>;
fn rename<P: AsRef<Path>>(&self, src_path: P, dst_path: P) -> Result<()>;
/// Reuses file at `src_path` as a new file at `dst_path`. The default
/// implementation simply renames the file.
fn reuse<P: AsRef<Path>>(&self, src_path: P, dst_path: P) -> Result<()> {
self.rename(src_path, dst_path)
}
#[inline]
fn reuse_and_open<P: AsRef<Path>>(&self, src_path: P, dst_path: P) -> Result<Self::Handle> {
self.reuse(src_path.as_ref(), dst_path.as_ref())?;
self.open(dst_path)
}
/// Deletes user implemented metadata associated with `path`. Returns
/// `true` if any metadata is deleted.
///
/// In older versions of Raft Engine, physical files are deleted without
/// going through user implemented cleanup procedure. This method is used to
/// detect and cleanup the user metadata that is no longer mapped to a
/// physical file.
fn delete_metadata<P: AsRef<Path>>(&self, _path: P) -> Result<()> {
Ok(())
}
/// Returns whether there is any user metadata associated with given `path`.
fn exists_metadata<P: AsRef<Path>>(&self, _path: P) -> bool {
false
}
fn new_reader(&self, handle: Arc<Self::Handle>) -> Result<Self::Reader>;
fn new_writer(&self, handle: Arc<Self::Handle>) -> Result<Self::Writer>;
fn new_async_io_context(&self) -> Result<Self::MultiReadContext>;
}
pub trait Handle {
fn truncate(&self, offset: usize) -> Result<()>;
/// Returns the current size of this file.
fn file_size(&self) -> Result<usize>;
fn sync(&self) -> Result<()>;
}
/// WriteExt is writer extension api
pub trait WriteExt {
fn truncate(&mut self, offset: usize) -> Result<()>;
fn allocate(&mut self, offset: usize, size: usize) -> Result<()>;
}