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

Method open

nodedb-wal/src/uring_writer.rs:79–111  ·  view source on GitHub ↗

Open or create a WAL file with io_uring support.

(path: &Path, config: UringWriterConfig)

Source from the content-addressed store, hash-verified

77impl UringWriter {
78 /// Open or create a WAL file with io_uring support.
79 pub fn open(path: &Path, config: UringWriterConfig) -> Result<Self> {
80 let mut opts = OpenOptions::new();
81 opts.create(true).write(true).read(true);
82
83 if config.use_direct_io {
84 opts.custom_flags(libc::O_DIRECT);
85 }
86
87 let file = opts.open(path)?;
88 let buffer = AlignedBuf::new(config.write_buffer_size, config.alignment)?;
89
90 // Recovery: scan existing WAL for last LSN.
91 let (file_offset, next_lsn) = if path.exists() && std::fs::metadata(path)?.len() > 0 {
92 let info = crate::recovery::recover(path)?;
93 (info.end_offset, info.next_lsn())
94 } else {
95 (0, 1)
96 };
97
98 let ring = IoUring::new(config.ring_depth).map_err(WalError::Io)?;
99
100 Ok(Self {
101 file,
102 buffer,
103 file_offset,
104 next_lsn: AtomicU64::new(next_lsn),
105 ring,
106 sealed: false,
107 config,
108 encryption_key: None,
109 segment_preamble: None,
110 })
111 }
112
113 /// Open without O_DIRECT (for testing on tmpfs).
114 pub fn open_without_direct_io(path: &Path) -> Result<Self> {

Callers

nothing calls this directly

Calls 8

metadataFunction · 0.85
recoverFunction · 0.85
readMethod · 0.45
writeMethod · 0.45
createMethod · 0.45
existsMethod · 0.45
lenMethod · 0.45
next_lsnMethod · 0.45

Tested by

no test coverage detected