tape: improve MediaPool allocation by sorting tapes by ctime and label_text

This commit is contained in:
Dietmar Maurer 2021-03-09 08:33:21 +01:00
parent 1825c1a9b7
commit af76234112
3 changed files with 26 additions and 4 deletions

View File

@ -1012,7 +1012,10 @@ fn barcode_label_media_worker(
) -> Result<(), Error> {
let (mut changer, changer_name) = required_media_changer(drive_config, &drive)?;
let label_text_list = changer.online_media_label_texts()?;
let mut label_text_list = changer.online_media_label_texts()?;
// make sure we label them in the right order
label_text_list.sort();
let state_path = Path::new(TAPE_STATUS_DIR);

View File

@ -276,7 +276,7 @@ impl Inventory {
continue; // belong to another pool
}
if set.uuid.as_ref() == [0u8;16] { // should we do this??
if set.uuid.as_ref() == [0u8;16] {
list.push(MediaId {
label: entry.id.label.clone(),
media_set_label: None,

View File

@ -386,7 +386,13 @@ impl MediaPool {
}
// sort empty_media, newest first -> oldest last
empty_media.sort_unstable_by(|a, b| b.label().ctime.cmp(&a.label().ctime));
empty_media.sort_unstable_by(|a, b| {
let mut res = b.label().ctime.cmp(&a.label().ctime);
if res == std::cmp::Ordering::Equal {
res = b.label().label_text.cmp(&a.label().label_text);
}
res
});
if let Some(media) = empty_media.pop() {
// found empty media, add to media set an use it
@ -416,7 +422,11 @@ impl MediaPool {
// sort expired_media, newest first -> oldest last
expired_media.sort_unstable_by(|a, b| {
b.media_set_label().unwrap().ctime.cmp(&a.media_set_label().unwrap().ctime)
let mut res = b.media_set_label().unwrap().ctime.cmp(&a.media_set_label().unwrap().ctime);
if res == std::cmp::Ordering::Equal {
res = b.label().label_text.cmp(&a.label().label_text);
}
res
});
if let Some(media) = expired_media.pop() {
@ -447,6 +457,15 @@ impl MediaPool {
free_media.push(media_id);
}
// sort free_media, newest first -> oldest last
free_media.sort_unstable_by(|a, b| {
let mut res = b.label.ctime.cmp(&a.label.ctime);
if res == std::cmp::Ordering::Equal {
res = b.label.label_text.cmp(&a.label.label_text);
}
res
});
if let Some(media_id) = free_media.pop() {
println!("use free media '{}'", media_id.label.label_text);
let uuid = media_id.label.uuid.clone();