feat(enterprise): add auth TLS and recovery hardening
This commit is contained in:
@@ -187,6 +187,27 @@ impl CollectionState {
|
||||
}
|
||||
}
|
||||
|
||||
fn truncate_invalid_tail(
|
||||
data_path: &PathBuf,
|
||||
stats: &crate::keydir::BuildStats,
|
||||
) -> StorageResult<()> {
|
||||
if stats.invalid_tail_bytes == 0 {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
tracing::warn!(
|
||||
path = %data_path.display(),
|
||||
valid_data_end = stats.valid_data_end,
|
||||
invalid_tail_bytes = stats.invalid_tail_bytes,
|
||||
"truncating invalid data file tail"
|
||||
);
|
||||
|
||||
let file = std::fs::OpenOptions::new().write(true).open(data_path)?;
|
||||
file.set_len(stats.valid_data_end)?;
|
||||
file.sync_all()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Collection cache key: "db\0coll"
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -279,7 +300,8 @@ impl FileStorageAdapter {
|
||||
hint_path, stored_size, actual_size
|
||||
);
|
||||
}
|
||||
let (kd, dead, _stats) = KeyDir::build_from_data_file(&data_path)?;
|
||||
let (kd, dead, stats) = KeyDir::build_from_data_file(&data_path)?;
|
||||
truncate_invalid_tail(&data_path, &stats)?;
|
||||
(kd, dead, false)
|
||||
} else {
|
||||
// Size matches — validate entry integrity with spot-checks
|
||||
@@ -296,19 +318,22 @@ impl FileStorageAdapter {
|
||||
(kd, dead, true)
|
||||
} else {
|
||||
tracing::warn!("hint file {:?} failed validation, rebuilding from data file", hint_path);
|
||||
let (kd, dead, _stats) = KeyDir::build_from_data_file(&data_path)?;
|
||||
let (kd, dead, stats) = KeyDir::build_from_data_file(&data_path)?;
|
||||
truncate_invalid_tail(&data_path, &stats)?;
|
||||
(kd, dead, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
debug!("hint file invalid, rebuilding KeyDir from data file");
|
||||
let (kd, dead, _stats) = KeyDir::build_from_data_file(&data_path)?;
|
||||
let (kd, dead, stats) = KeyDir::build_from_data_file(&data_path)?;
|
||||
truncate_invalid_tail(&data_path, &stats)?;
|
||||
(kd, dead, false)
|
||||
}
|
||||
}
|
||||
} else if data_path.exists() {
|
||||
let (kd, dead, _stats) = KeyDir::build_from_data_file(&data_path)?;
|
||||
let (kd, dead, stats) = KeyDir::build_from_data_file(&data_path)?;
|
||||
truncate_invalid_tail(&data_path, &stats)?;
|
||||
(kd, dead, false)
|
||||
} else {
|
||||
(KeyDir::new(), 0, false)
|
||||
|
||||
Reference in New Issue
Block a user