in progress_tracking/src/upload_tracking.rs [246:317]
fn register_xorb_upload_completion(&mut self, xorb_hash: MerkleHash) -> ProgressUpdate {
let (file_indices, byte_completion_increment) = {
// Should have been registered above with register_xorb
debug_assert!(self.xorbs.contains_key(&xorb_hash));
// Mark as completed, return the list of files to mark as completed.
let entry = self.xorbs.entry(xorb_hash).or_default();
// How many new bytes uploaded do we have to write out to the total_completed_bytes?
let new_byte_increment = entry.xorb_size - entry.completed_bytes;
// This should be present but not completed.
debug_assert!(!entry.is_completed);
entry.is_completed = true;
(take(&mut entry.file_indices), new_byte_increment)
};
// Mark all the relevant files as completed
let mut item_updates = Vec::with_capacity(file_indices.len());
let mut file_bytes_processed = 0;
// For each file that depends on this xorb, remove the relevant
// part from `remaining_xorbs_parts` and add to `completed_bytes`.
for file_id in file_indices {
let file_entry = &mut self.files[file_id];
debug_assert!(file_entry.remaining_xorbs_parts.contains_key(&xorb_hash));
// This xorb is completed, so remove the number of bytes in that file needed by that xorb.
let xorb_part = file_entry.remaining_xorbs_parts.remove(&xorb_hash).unwrap_or_default();
debug_assert_le!(xorb_part.completed_bytes, xorb_part.n_bytes);
let n_bytes_remaining = xorb_part.n_bytes - xorb_part.completed_bytes;
if n_bytes_remaining > 0 {
file_entry.completed_bytes += n_bytes_remaining;
let progress_update = ItemProgressUpdate {
item_name: file_entry.name.clone(),
total_bytes: file_entry.total_bytes,
bytes_completed: file_entry.completed_bytes,
bytes_completion_increment: n_bytes_remaining,
};
file_bytes_processed += n_bytes_remaining;
item_updates.push(progress_update);
}
}
debug_assert_le!(self.total_upload_bytes_completed + byte_completion_increment, self.total_upload_bytes);
self.total_upload_bytes_completed += byte_completion_increment;
self.total_bytes_completed += file_bytes_processed;
debug_assert_le!(self.total_bytes_completed, self.total_bytes);
ProgressUpdate {
item_updates,
total_bytes: self.total_bytes,
total_bytes_increment: 0,
total_bytes_completed: self.total_bytes_completed,
total_bytes_completion_increment: file_bytes_processed,
total_transfer_bytes: self.total_upload_bytes,
total_transfer_bytes_completed: self.total_upload_bytes_completed,
total_transfer_bytes_completion_increment: byte_completion_increment,
total_transfer_bytes_increment: 0,
..Default::default()
}
}