tape: improve PoolWriter logging

Log reason why we allocate a new media set.
This commit is contained in:
Dietmar Maurer 2021-03-05 09:58:36 +01:00
parent cf90a369e2
commit 90e16be3ae
3 changed files with 31 additions and 18 deletions

View File

@ -295,7 +295,7 @@ fn backup_worker(
let pool = MediaPool::with_config(status_path, &pool_config, changer_name)?; let pool = MediaPool::with_config(status_path, &pool_config, changer_name)?;
let mut pool_writer = PoolWriter::new(pool, &setup.drive)?; let mut pool_writer = PoolWriter::new(pool, &setup.drive, worker)?;
let mut group_list = BackupInfo::list_backup_groups(&datastore.base_path())?; let mut group_list = BackupInfo::list_backup_groups(&datastore.base_path())?;

View File

@ -99,6 +99,11 @@ impl MediaPool {
self.force_media_availability = true; self.force_media_availability = true;
} }
/// Returns the Uuid of the current media set
pub fn current_media_set(&self) -> &Uuid {
self.current_media_set.uuid()
}
/// Creates a new instance using the media pool configuration /// Creates a new instance using the media pool configuration
pub fn with_config( pub fn with_config(
state_path: &Path, state_path: &Path,
@ -230,27 +235,27 @@ impl MediaPool {
/// ///
/// Note: We also call this in list_media to compute correct media /// Note: We also call this in list_media to compute correct media
/// status, so this must not change persistent/saved state. /// status, so this must not change persistent/saved state.
pub fn start_write_session(&mut self, current_time: i64) -> Result<(), Error> { ///
/// Returns the reason why we started a new media set (if we do)
pub fn start_write_session(&mut self, current_time: i64) -> Result<Option<String>, Error> {
let mut create_new_set = match self.current_set_usable() { let mut create_new_set = match self.current_set_usable() {
Err(err) => { Err(err) => {
eprintln!("unable to use current media set - {}", err); Some(err.to_string())
true
} }
Ok(usable) => !usable, Ok(_) => None,
}; };
if !create_new_set { if create_new_set.is_none() {
match &self.media_set_policy { match &self.media_set_policy {
MediaSetPolicy::AlwaysCreate => { MediaSetPolicy::AlwaysCreate => {
create_new_set = true; create_new_set = Some(String::from("policy is AlwaysCreate"));
} }
MediaSetPolicy::CreateAt(event) => { MediaSetPolicy::CreateAt(event) => {
if let Some(set_start_time) = self.inventory.media_set_start_time(&self.current_media_set.uuid()) { if let Some(set_start_time) = self.inventory.media_set_start_time(&self.current_media_set.uuid()) {
if let Ok(Some(alloc_time)) = compute_next_event(event, set_start_time as i64, false) { if let Ok(Some(alloc_time)) = compute_next_event(event, set_start_time as i64, false) {
if current_time >= alloc_time { if current_time >= alloc_time {
create_new_set = true; create_new_set = Some(String::from("policy CreateAt event triggered"));
} }
} }
} }
@ -259,13 +264,12 @@ impl MediaPool {
} }
} }
if create_new_set { if create_new_set.is_some() {
let media_set = MediaSet::new(); let media_set = MediaSet::new();
eprintln!("starting new media set {}", media_set.uuid());
self.current_media_set = media_set; self.current_media_set = media_set;
} }
Ok(()) Ok(create_new_set)
} }
/// List media in current media set /// List media in current media set

View File

@ -68,11 +68,20 @@ pub struct PoolWriter {
impl PoolWriter { impl PoolWriter {
pub fn new(mut pool: MediaPool, drive_name: &str) -> Result<Self, Error> { pub fn new(mut pool: MediaPool, drive_name: &str, worker: &WorkerTask) -> Result<Self, Error> {
let current_time = proxmox::tools::time::epoch_i64(); let current_time = proxmox::tools::time::epoch_i64();
pool.start_write_session(current_time)?; let new_media_set_reason = pool.start_write_session(current_time)?;
if let Some(reason) = new_media_set_reason {
task_log!(
worker,
"starting new media set - reason: {}",
reason,
);
}
task_log!(worker, "media set uuid: {}", pool.current_media_set());
let mut media_set_catalog = MediaSetCatalog::new(); let mut media_set_catalog = MediaSetCatalog::new();