MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / trim_garbage

Function trim_garbage

crates/commitlog/tests/streaming/mod.rs:105–159  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

103
104#[tokio::test]
105async fn trim_garbage() {
106 enable_logging();
107
108 let root = tempdir().unwrap();
109 let (src, dst) = create_dirs(root.path()).await;
110 fill_log(src.clone()).await;
111
112 {
113 let writer = create_writer(dst.clone())
114 .await
115 .expect("failed to create stream writer");
116 let reader = create_reader(&src, ..);
117 pin!(reader);
118 writer.append_all(reader, |_| ()).await.unwrap();
119 assert_equal_dirs(&src, &dst).await
120 }
121
122 // Truncate the destination log so the last commit is broken.
123 spawn_blocking({
124 let repo = repo(&dst);
125 move || {
126 let last_segment_offset = repo.existing_offsets().unwrap().pop().unwrap();
127 let mut segment = repo.open_segment_writer(last_segment_offset).unwrap();
128 let len = segment.segment_len().unwrap();
129 segment.set_len(len - 128).unwrap();
130 }
131 })
132 .await
133 .unwrap();
134 // The default is to return an error.
135 pretty_assertions::assert_matches!(
136 create_writer(dst.clone()).await.map(drop),
137 Err(e) if e.kind() == io::ErrorKind::InvalidData
138 );
139
140 // With `Trim`, we can retry from commit 99.
141 let writer = spawn_blocking({
142 let path = dst.clone();
143 move || StreamWriter::create(repo(&path), default_options(), OnTrailingData::Trim)
144 })
145 .await
146 .unwrap()
147 .expect("failed to create stream writer");
148 let reader = create_reader(&src, 99..);
149 pin!(reader);
150 writer
151 .append_all(reader, |_| ())
152 .await
153 .unwrap()
154 .sync_all()
155 .await
156 .unwrap();
157
158 assert_equal_dirs(&src, &dst).await
159}
160
161async fn assert_equal_dirs(src: &Path, dst: &Path) {
162 let mut src_dir = fs::read_dir(src).await.map(ReadDirStream::new).unwrap();

Callers

nothing calls this directly

Calls 15

create_dirsFunction · 0.85
create_writerFunction · 0.85
create_readerFunction · 0.85
assert_equal_dirsFunction · 0.85
repoFunction · 0.85
default_optionsFunction · 0.85
append_allMethod · 0.80
set_lenMethod · 0.80
fill_logFunction · 0.70
enable_loggingFunction · 0.50
unwrapMethod · 0.45
pathMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…