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

Method open

nodedb/src/control/array_sync/op_log.rs:74–102  ·  view source on GitHub ↗

Open or create the op-log database at `{data_dir}/array_sync/op_log.redb`.

(data_dir: &Path)

Source from the content-addressed store, hash-verified

72impl OriginOpLog {
73 /// Open or create the op-log database at `{data_dir}/array_sync/op_log.redb`.
74 pub fn open(data_dir: &Path) -> crate::Result<Self> {
75 let dir = data_dir.join("array_sync");
76 std::fs::create_dir_all(&dir).map_err(|e| crate::Error::Storage {
77 engine: "array_sync".into(),
78 detail: format!("create dir {}: {e}", dir.display()),
79 })?;
80 let path = dir.join("op_log.redb");
81 let db = Database::create(&path).map_err(|e| crate::Error::Storage {
82 engine: "array_sync".into(),
83 detail: format!("open op_log db {}: {e}", path.display()),
84 })?;
85 // Ensure the table exists.
86 {
87 let txn = db.begin_write().map_err(|e| crate::Error::Storage {
88 engine: "array_sync".into(),
89 detail: format!("begin_write init: {e}"),
90 })?;
91 txn.open_table(ARRAY_OP_LOG)
92 .map_err(|e| crate::Error::Storage {
93 engine: "array_sync".into(),
94 detail: format!("open_table init: {e}"),
95 })?;
96 txn.commit().map_err(|e| crate::Error::Storage {
97 engine: "array_sync".into(),
98 detail: format!("commit init: {e}"),
99 })?;
100 }
101 Ok(Self { db: Arc::new(db) })
102 }
103
104 /// Create an in-memory op-log (for tests and development setups).
105 pub fn open_in_memory() -> crate::Result<Self> {

Callers

nothing calls this directly

Calls 4

joinMethod · 0.80
begin_writeMethod · 0.80
createFunction · 0.50
commitMethod · 0.45

Tested by

no test coverage detected