Skip to content

Commit 6f6bb8e

Browse files
committed
only hash non-SST files to save compute and processing time
1 parent afb4a3d commit 6f6bb8e

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

rust/kafka-deduplicator/src/checkpoint/planner.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,11 @@ fn build_candidate_file(file_path: &Path) -> Result<LocalCheckpointFile> {
202202
.to_string_lossy()
203203
.to_string();
204204

205-
let mut file =
206-
File::open(file_path).with_context(|| format!("Failed to open file: {file_path:?}"))?;
207-
let mut hasher = Sha256::new();
208-
std::io::copy(&mut file, &mut hasher)
209-
.with_context(|| format!("Failed to read and hash file: {file_path:?}"))?;
210-
211-
let hash = hasher.finalize();
212-
let checksum = format!("{hash:x}");
205+
let checksum = if filename.ends_with(".sst") {
206+
String::default()
207+
} else {
208+
load_and_hash_file(file_path).context("In load_and_hash_file")?
209+
};
213210

214211
Ok(LocalCheckpointFile::new(
215212
filename,
@@ -218,6 +215,19 @@ fn build_candidate_file(file_path: &Path) -> Result<LocalCheckpointFile> {
218215
))
219216
}
220217

218+
fn load_and_hash_file(file_path: &Path) -> Result<String> {
219+
let mut file = File::open(file_path)
220+
.with_context(|| format!("Failed to open file for hashing: {file_path:?}"))?;
221+
222+
let mut hasher = Sha256::new();
223+
std::io::copy(&mut file, &mut hasher)
224+
.with_context(|| format!("Failed to read and hash file: {file_path:?}"))?;
225+
let hash = hasher.finalize();
226+
let checksum = format!("{hash:x}");
227+
228+
Ok(checksum.to_string())
229+
}
230+
221231
#[derive(Debug, Clone, PartialEq, Eq)]
222232
pub struct LocalCheckpointFile {
223233
pub filename: String,

0 commit comments

Comments
 (0)