Open or create the op-log database at `{data_dir}/array_sync/op_log.redb`.
(data_dir: &Path)
| 72 | impl 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> { |
nothing calls this directly
no test coverage detected