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

Method open

nodedb-wal/src/segmented.rs:101–134  ·  view source on GitHub ↗

Open or create a segmented WAL in the given directory. On first startup, creates the directory and the first segment. On subsequent startups, discovers existing segments and opens the last one for continued appending.

(config: SegmentedWalConfig)

Source from the content-addressed store, hash-verified

99 /// On subsequent startups, discovers existing segments and opens the
100 /// last one for continued appending.
101 pub fn open(config: SegmentedWalConfig) -> Result<Self> {
102 fs::create_dir_all(&config.wal_dir).map_err(WalError::Io)?;
103
104 let segments = discover_segments(&config.wal_dir)?;
105
106 let (writer, active_first_lsn) = if segments.is_empty() {
107 // Fresh WAL — create the first segment starting at LSN 1.
108 let path = segment_path(&config.wal_dir, 1);
109 let writer = WalWriter::open(&path, config.writer_config.clone())?;
110 (writer, 1u64)
111 } else {
112 // Resume from the last segment.
113 let last = &segments[segments.len() - 1];
114 let writer = WalWriter::open(&last.path, config.writer_config.clone())?;
115 (writer, last.first_lsn)
116 };
117
118 info!(
119 wal_dir = %config.wal_dir.display(),
120 segments = segments.len().max(1),
121 active_first_lsn,
122 next_lsn = writer.next_lsn(),
123 "segmented WAL opened"
124 );
125
126 Ok(Self {
127 wal_dir: config.wal_dir,
128 writer,
129 active_first_lsn,
130 segment_target_size: config.segment_target_size,
131 writer_config: config.writer_config,
132 encryption_ring: None,
133 })
134 }
135
136 /// Set the encryption key ring. All subsequent records will be encrypted.
137 ///

Callers

nothing calls this directly

Calls 6

discover_segmentsFunction · 0.85
segment_pathFunction · 0.50
openFunction · 0.50
is_emptyMethod · 0.45
cloneMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected