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

Method open

nodedb-wal/src/writer.rs:139–174  ·  view source on GitHub ↗

Open or create a WAL file at the given path.

(path: &Path, config: WalWriterConfig)

Source from the content-addressed store, hash-verified

137impl WalWriter {
138 /// Open or create a WAL file at the given path.
139 pub fn open(path: &Path, config: WalWriterConfig) -> Result<Self> {
140 let mut opts = OpenOptions::new();
141 opts.create(true).write(true).append(false);
142
143 #[cfg(not(target_arch = "wasm32"))]
144 if config.use_direct_io {
145 // O_DIRECT: bypass page cache.
146 opts.custom_flags(libc::O_DIRECT);
147 }
148
149 let file = opts.open(path)?;
150
151 let buffer = AlignedBuf::new(config.write_buffer_size, config.alignment)?;
152
153 // Scan existing WAL for recovery if the file has data.
154 let (file_offset, next_lsn) = if path.exists() && std::fs::metadata(path)?.len() > 0 {
155 let info = crate::recovery::recover(path)?;
156 (info.end_offset, info.next_lsn())
157 } else {
158 (0, 1)
159 };
160
161 let double_write = open_dwb_for(&config, path);
162
163 Ok(Self {
164 file,
165 buffer,
166 file_offset,
167 next_lsn: AtomicU64::new(next_lsn),
168 sealed: false,
169 config,
170 encryption_ring: None,
171 segment_preamble: None,
172 double_write,
173 })
174 }
175
176 /// Set the encryption key. When set, all subsequent records will have
177 /// their payloads encrypted with AES-256-GCM.

Calls 9

metadataFunction · 0.85
recoverFunction · 0.85
open_dwb_forFunction · 0.85
appendMethod · 0.45
writeMethod · 0.45
createMethod · 0.45
existsMethod · 0.45
lenMethod · 0.45
next_lsnMethod · 0.45

Tested by 6

recover_truncated_walFunction · 0.36
torn_write_mid_headerFunction · 0.36
torn_write_mid_payloadFunction · 0.36