use std::sync::{Arc, Mutex};
use std::collections::{HashMap, HashSet};
+use ::serde::{Serialize};
use serde_json::{json, Value};
use proxmox::tools::digest_to_hex;
use crate::server::formatter::*;
use hyper::{Body, Response};
+#[derive(Copy, Clone, Serialize)]
struct UploadStatistic {
count: u64,
size: u64,
}
}
+impl std::ops::Add for UploadStatistic {
+ type Output = Self;
+
+ fn add(self, other: Self) -> Self {
+ Self {
+ count: self.count + other.count,
+ size: self.size + other.size,
+ compressed_size: self.compressed_size + other.compressed_size,
+ duplicates: self.duplicates + other.duplicates,
+ }
+ }
+}
+
struct DynamicWriterState {
name: String,
index: DynamicIndexWriter,
fixed_writers: HashMap<usize, FixedWriterState>,
known_chunks: HashMap<[u8;32], u32>,
base_snapshots: HashSet<BackupDir>,
+ backup_size: u64, // sums up size of all files
+ backup_stat: UploadStatistic,
}
impl SharedBackupState {
fixed_writers: HashMap::new(),
known_chunks: HashMap::new(),
base_snapshots: HashSet::new(),
+ backup_size: 0,
+ backup_stat: UploadStatistic::new(),
};
Self {
self.log_upload_stat(&data.name, &csum, &uuid, size, chunk_count, &data.upload_stat);
state.file_counter += 1;
+ state.backup_size += size;
+ state.backup_stat = state.backup_stat + data.upload_stat;
Ok(())
}
self.log_upload_stat(&data.name, &expected_csum, &uuid, size, chunk_count, &data.upload_stat);
state.file_counter += 1;
+ state.backup_size += size;
+ state.backup_stat = state.backup_stat + data.upload_stat;
Ok(())
}
let mut state = self.state.lock().unwrap();
state.file_counter += 1;
+ state.backup_size += orig_len as u64;
+ state.backup_stat.size += blob_len as u64;
Ok(())
}
state.finished = true;
// check manifest
- let _manifest = self.datastore.load_manifest(&self.backup_dir)
+ let mut manifest = self.datastore.load_manifest_json(&self.backup_dir)
.map_err(|err| format_err!("unable to load manifest blob - {}", err))?;
+ let stats = serde_json::to_value(state.backup_stat)?;
+
+ manifest["unprotected"]["chunk_upload_stats"] = stats;
+
+ self.datastore.store_manifest(&self.backup_dir, manifest)
+ .map_err(|err| format_err!("unable to store manifest blob - {}", err))?;
for snap in &state.base_snapshots {
let path = self.datastore.snapshot_path(snap);