Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_o3db_sync/tests/gc_all_old.rs

3.6 KiB, 1 run

created by r1870400018:67599, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1//! A file whose records are all old is deleted without a collection (A3 R3, 2026-10-08). Until
2//! that day its state outlived it, with the old bytes still counted and its sizes still in the
3//! shard's total, so a count of what the store still had to collect included files that were gone.
4
5mod gc_pair;
6
7use gc_pair::*;
8
9use oxedyne_fe2o3_core::prelude::*;
10use oxedyne_fe2o3_iop_db::api::Database;
11use oxedyne_fe2o3_o3db_sync::{
12 base::constant,
13 file::core::FileType,
14 test::setup,
15};
16
17use std::{
18 path::Path,
19 time::Duration,
20};
21
22#[test]
23fn deleted_all_old_file_leaves_no_state() -> Outcome<()> {
24 log_set_level!("error");
25 let dir = "./test_db_gc_all_old";
26 let _ = std::fs::remove_dir_all(dir);
27 res!(std::fs::create_dir_all(dir));
28 let root = res!(Path::new(dir).canonicalize());
29 let probe = res!(probe("./test_db_gc_all_old_probe"));
30 let cfg = res!(config(5 * probe.len + probe.len / 2));
31 let db: TestDb = res!(setup::start_db(root.clone(), Some(cfg.clone()), schemes(), None, true, true));
32 let user = setup::Uid::default();
33 res!(fill(&db));
34 res!(db.api().settle_for_test(Duration::from_secs(10)));
35 let (d1, d2) = (file(&root, &cfg, FileType::Data, 1), file(&root, &cfg, FileType::Data, 2));
36 assert!(d1.is_file() && d2.is_file(), "positive control: files 1 and 2 hold the first records");
37 let states = res!(db.api().collect_file_states(constant::USER_REQUEST_WAIT));
38 let mut counted = 0;
39 for (_wind, fmap) in &states {
40 if let Some(fstat) = fmap.map().get(&1) {
41 counted = fstat.get_data_file_size();
42 }
43 }
44 assert_eq!(counted as u64, 5 * probe.len, "positive control: file 1's state holds its five records");
45
46 // Overwriting every key makes files 1 and 2 all old, and they are sealed.
47 for i in 0..NKEYS {
48 res!(db.insert(key(i), value(i, 2), user, None));
49 }
50 res!(db.api().settle_for_test(Duration::from_secs(60)));
51 assert!(
52 wait_until(Duration::from_secs(30), || !d1.is_file() && !d2.is_file()),
53 "files 1 and 2 hold only old records and were not deleted",
54 );
55 res!(db.api().settle_for_test(Duration::from_secs(60)));
56 std::thread::sleep(Duration::from_millis(1500));
57
58 let states = res!(db.api().collect_file_states(constant::USER_REQUEST_WAIT));
59 let (mut accounted, mut seen) = (0usize, 0usize);
60 for (_wind, fmap) in &states {
61 accounted += fmap.get_size();
62 for (fnum, fstat) in fmap.map() {
63 seen += 1;
64 if !file(&root, &cfg, FileType::Data, *fnum).is_file() {
65 assert_eq!(fstat.get_old_sum(), 0, "file {} is gone but its state counts old bytes", fnum);
66 assert_eq!(fstat.get_old_count(), 0, "file {} is gone but its state counts old records", fnum);
67 assert!(fstat.data_map_empty(), "file {} is gone but its state maps records", fnum);
68 assert_eq!(fstat.get_data_file_size() + fstat.get_index_file_size(), 0,
69 "file {} is gone but its state has a size", fnum);
70 }
71 }
72 }
73 assert!(seen >= 3, "positive control: the shards hold the states of the files still there");
74 let mut physical = 0u64;
75 for n in 1..40 {
76 physical += size(&file(&root, &cfg, FileType::Data, n));
77 physical += size(&file(&root, &cfg, FileType::Index, n));
78 }
79 msg!("Shard sizes total {}, files hold {}.", accounted, physical);
80 assert_eq!(accounted as u64, physical, "the shards' total includes files that are gone");
81 assert_eq!(judge(&db, &vec![2u8; NKEYS], "after the deletions"), 0);
82 res!(db.close());
83 Ok(())
84}