MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / open

Method open

nodedb-cluster/src/raft_storage.rs:43–79  ·  view source on GitHub ↗

Open or create storage at the given path.

(path: &Path)

Source from the content-addressed store, hash-verified

41impl RedbLogStorage {
42 /// Open or create storage at the given path.
43 pub fn open(path: &Path) -> crate::Result<Self> {
44 if let Some(parent) = path.parent() {
45 std::fs::create_dir_all(parent).map_err(|e| crate::ClusterError::Storage {
46 detail: format!("create raft storage dir: {e}"),
47 })?;
48 }
49
50 let db = Database::create(path).map_err(|e| crate::ClusterError::Storage {
51 detail: format!("open raft storage: {e}"),
52 })?;
53
54 // Ensure tables exist.
55 let write_txn = db.begin_write().map_err(|e| crate::ClusterError::Storage {
56 detail: format!("init raft tables: {e}"),
57 })?;
58 {
59 write_txn
60 .open_table(ENTRIES)
61 .map_err(|e| crate::ClusterError::Storage {
62 detail: format!("create entries table: {e}"),
63 })?;
64 write_txn
65 .open_table(META)
66 .map_err(|e| crate::ClusterError::Storage {
67 detail: format!("create meta table: {e}"),
68 })?;
69 }
70 write_txn
71 .commit()
72 .map_err(|e| crate::ClusterError::Storage {
73 detail: format!("commit raft init: {e}"),
74 })?;
75
76 info!(path = %path.display(), "raft log storage opened");
77
78 Ok(Self { db })
79 }
80}
81
82fn index_key(index: u64) -> [u8; 8] {

Callers

nothing calls this directly

Calls 3

begin_writeMethod · 0.80
createFunction · 0.50
commitMethod · 0.45

Tested by

no test coverage detected