bge_m3_embedding_server/embedder/trt_cache/
fsync.rs1use std::path::Path;
18
19#[cfg(target_os = "linux")]
20pub(crate) fn fsync_cache_dir(dir: &Path) {
21 use std::fs::File;
22 let read_dir = match std::fs::read_dir(dir) {
23 Ok(r) => r,
24 Err(e) => {
25 tracing::warn!(
26 cache_path = %dir.display(),
27 error = %e,
28 "trt cache: could not enumerate directory for fsync; \
29 engine plan files may not be durable on the next OOM"
30 );
31 return;
32 }
33 };
34
35 let mut synced = 0usize;
36 for entry in read_dir.flatten() {
37 let Ok(file_type) = entry.file_type() else {
38 continue;
39 };
40 if !file_type.is_file() {
41 continue;
42 }
43 let path = entry.path();
44 match File::open(&path).and_then(|f| f.sync_all()) {
45 Ok(()) => synced += 1,
46 Err(e) => {
47 tracing::warn!(
48 file = %path.display(),
49 error = %e,
50 "trt cache: fsync(file) failed; engine plan may not be durable"
51 );
52 }
53 }
54 }
55
56 match File::open(dir).and_then(|d| d.sync_all()) {
57 Ok(()) => {
58 tracing::debug!(
59 cache_path = %dir.display(),
60 files_synced = synced,
61 "trt cache: directory fsynced"
62 );
63 }
64 Err(e) => {
65 tracing::warn!(
66 cache_path = %dir.display(),
67 error = %e,
68 "trt cache: fsync(directory) failed; name → inode mapping \
69 may not be durable on the next OOM"
70 );
71 }
72 }
73}
74
75#[cfg(not(target_os = "linux"))]
77pub(crate) fn fsync_cache_dir(_dir: &Path) {}