team-ljyzipelo

공개

ZIP 합계 압축률과 빈 항목 진행 판정을 고친다

작성자
시로사키 하나
작성 시각
커밋
4e0ec558336423cca5ca7da2fae4fd92c740fe29
부모
505eb1b
이 시점의 파일 보기

변경된 파일 5개

+192-6
수정experiments/rust-archive-worker/src/runtime.rs+4-0
@@ -350,6 +350,9 @@ impl<W: Write> Job<W> {
350350 if let Some(error) = p.error {
351351 return Err(error);
352352 }
353추가: if p.created {
354추가: self.activity()?;
355추가: }
353356 Ok(())
354357 }
355358 fn run(&mut self, start: Start) -> Result<()> {
@@ -582,6 +585,7 @@ impl<W: Write> Job<W> {
582585 if let Some(error) = sync_error {
583586 return Err(error);
584587 }
588추가: self.activity()?;
585589 }
586590 }
587591 for (index, m) in files.iter().enumerate() {
수정experiments/rust-archive-worker/src/streaming.rs+15-2
@@ -498,6 +498,7 @@ fn zip(
498498 }
499499 let mut cursor = central;
500500 let mut total = 0u64;
501추가: let mut compressed_total = 0u64;
501502 let mut metadata = MetadataBudget::default();
502503 let mut members = Vec::new();
503504 let mut packed = Vec::new();
@@ -555,9 +556,10 @@ fn zip(
555556 } else {
556557 12
557558 };
558삭제: compressed
559추가: let payload = compressed
559560 .checked_sub(overhead)
560561 .ok_or(ErrorCode::Integrity)?;
562추가: compressed_total = add(compressed_total, payload)?;
561563 total = total
562564 .checked_add(size)
563565 .filter(|n| *n <= limits.output)
@@ -566,7 +568,7 @@ fn zip(
566568 ResourceUsage {
567569 estimated_bytes: Some(total),
568570 estimated_entries: Some(count as u32),
569삭제: compressed_bytes: Some(compressed - overhead),
571추가: compressed_bytes: Some(payload),
570572 ratio_output_bytes: Some(size),
571573 ..ResourceUsage::default()
572574 },
@@ -689,6 +691,17 @@ fn zip(
689691 return Err(ErrorCode::Integrity);
690692 }
691693 archive::validate_members(&members)?;
694추가: // 작은 항목으로 나뉜 고압축 입력도 디코딩 전에 합계로 확인함.
695추가: check.observe(
696추가: ResourceUsage {
697추가: estimated_bytes: Some(total),
698추가: estimated_entries: Some(count as u32),
699추가: compressed_bytes: Some(compressed_total),
700추가: ratio_output_bytes: Some(total),
701추가: ..ResourceUsage::default()
702추가: },
703추가: Some(source),
704추가: )?;
692705 let mut data = spool::temporary()?;
693706 if decode {
694707 crate::space::ensure(&data, total)?;
수정tests/rust-archive-worker/guarded.rs+133-4
@@ -28,10 +28,13 @@ fn run_fault(
2828 assert!(
2929 Command::new("cc")
3030 .args(["-shared", "-fPIC", "-O2", "-Wall", "-Wextra", "-Werror"])
31삭제: .arg(
32삭제: PathBuf::from(env!("CARGO_MANIFEST_DIR"))
33삭제: .join("../../tests/rust-archive-worker/io_fault.c")
34삭제: )
31추가: .arg(PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(
32추가: if fault.starts_with("clock-") {
33추가: "../../tests/rust-archive-worker/progress_clock.c"
34추가: } else {
35추가: "../../tests/rust-archive-worker/io_fault.c"
36추가: }
37추가: ))
3538 .args(["-ldl", "-o"])
3639 .arg(&shim)
3740 .status()
@@ -552,3 +555,129 @@ fn disk_space_and_write_failures_remain_enforced_after_permission() {
552555 }));
553556 }
554557}
558추가:
559추가: #[test]
560추가: fn split_zip_ratio_requires_permission_before_decoding() {
561추가: let s = setup();
562추가: generate(&s, "split-zip");
563추가: assert!(fs::metadata(s.0.join("input")).unwrap().len() < 300_000);
564추가: let mut start = request(&s, Limits::default().output, Limits::default().output);
565추가: start.ceiling.entries = Limits::default().entries;
566추가: for mode in 0..3 {
567추가: let outcome = if mode == 2 {
568추가: Outcome::Completed
569추가: } else {
570추가: Outcome::Cancelled
571추가: };
572추가: let mut asked = false;
573추가: let events = run(&s, start.clone(), |event| {
574추가: if let Message::ResourceRequired {
575추가: challenge_id,
576추가: scope,
577추가: usage,
578추가: ..
579추가: } = event
580추가: {
581추가: assert!(!asked);
582추가: asked = true;
583추가: assert_eq!(
584추가: *scope,
585추가: ResourceScope {
586추가: ratio: true,
587추가: ..ResourceScope::default()
588추가: }
589추가: );
590추가: assert_eq!(usage.estimated_bytes, Some(258 * 1024 * 1024));
591추가: assert_eq!(usage.ratio_output_bytes, usage.estimated_bytes);
592추가: assert_eq!(usage.actual_bytes, None);
593추가: assert!(usage.compressed_bytes.unwrap() < 300_000);
594추가: assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0);
595추가: if mode == 0 {
596추가: return Some(vec![Message::Cancel]);
597추가: }
598추가: return Some(vec![Message::ResourceReply {
599추가: challenge_id: *challenge_id,
600추가: scope: *scope,
601추가: allow: outcome == Outcome::Completed,
602추가: }]);
603추가: }
604추가: None
605추가: });
606추가: assert!(asked);
607추가: assert_eq!(terminal(&events).outcome, outcome, "{events:?}");
608추가: assert_eq!(
609추가: terminal(&events).created_count,
610추가: if outcome == Outcome::Completed { 2 } else { 0 }
611추가: );
612추가: }
613추가: for name in ["first.bin", "second.bin"] {
614추가: let mut file = fs::File::open(s.0.join("output").join(name)).unwrap();
615추가: assert_eq!(file.metadata().unwrap().len(), 129 * 1024 * 1024);
616추가: let mut block = [0; 65536];
617추가: loop {
618추가: let n = file.read(&mut block).unwrap();
619추가: if n == 0 {
620추가: break;
621추가: }
622추가: assert!(block[..n].iter().all(|b| *b == 0));
623추가: }
624추가: }
625추가: }
626추가:
627추가: #[cfg(target_os = "linux")]
628추가: fn progress_archive(s: &Scratch, kind: EntryKind, size: u64) {
629추가: if kind == EntryKind::Directory {
630추가: generate(s, "empty-directories");
631추가: return;
632추가: }
633추가: let members = (0..36)
634추가: .map(|entry_id| archive::Member {
635추가: entry: Entry {
636추가: entry_id,
637추가: name: format!("entry-{entry_id}"),
638추가: kind,
639추가: size,
640추가: compressed_size: size,
641추가: encrypted: false,
642추가: },
643추가: data: vec![0; size as usize],
644추가: })
645추가: .collect::<Vec<_>>();
646추가: let zip =
647추가: archive::create_zip(&members, Method::Store, Limits::default(), &mut || Ok(())).unwrap();
648추가: fs::write(s.0.join("input"), zip).unwrap();
649추가: }
650추가:
651추가: #[cfg(target_os = "linux")]
652추가: #[test]
653추가: fn completed_empty_files_and_directories_refresh_idle_deadline() {
654추가: for (kind, size) in [
655추가: (EntryKind::File, 0),
656추가: (EntryKind::File, 1),
657추가: (EntryKind::Directory, 0),
658추가: ] {
659추가: let s = setup();
660추가: progress_archive(&s, kind, size);
661추가: let events = run_fault(&s, request(&s, 64, 128), Some("clock-progress"), approve);
662추가: assert_eq!(
663추가: terminal(&events).outcome,
664추가: Outcome::Completed,
665추가: "{kind:?}: {events:?}"
666추가: );
667추가: assert_eq!(terminal(&events).created_count, 36);
668추가: assert_eq!(terminal(&events).durability, Durability::Synced);
669추가: assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 36);
670추가: }
671추가: }
672추가:
673추가: #[cfg(target_os = "linux")]
674추가: #[test]
675추가: fn publication_still_stops_after_sixty_seconds_without_progress() {
676추가: let s = setup();
677추가: progress_archive(&s, EntryKind::File, 0);
678추가: let events = run_fault(&s, request(&s, 64, 128), Some("clock-stall"), approve);
679추가: assert_eq!(terminal(&events).outcome, Outcome::Failed, "{events:?}");
680추가: assert_eq!(terminal(&events).error, ErrorCode::Limit);
681추가: assert_eq!(terminal(&events).created_count, 0);
682추가: assert_eq!(fs::read_dir(s.0.join("output")).unwrap().count(), 0);
683추가: }
수정tests/rust-archive-worker/guarded_cases.py+12-0
@@ -3,6 +3,7 @@ import gzip
33import lzma
44from pathlib import Path
55import sys
6추가: import zipfile
67
78
89root = Path(sys.argv[1])
@@ -12,6 +13,17 @@ if case == "bomb":
1213 block = bytes(1024 * 1024)
1314 for _ in range(257):
1415 output.write(block)
16추가: elif case == "empty-directories":
17추가: with zipfile.ZipFile(root / "input", "w") as archive:
18추가: for entry_id in range(36):
19추가: archive.writestr(f"entry-{entry_id}/", b"")
20추가: elif case == "split-zip":
21추가: with zipfile.ZipFile(root / "input", "w", compression=zipfile.ZIP_DEFLATED) as archive:
22추가: block = bytes(1024 * 1024)
23추가: for name in ["first.bin", "second.bin"]:
24추가: with archive.open(name, "w") as output:
25추가: for _ in range(129):
26추가: output.write(block)
1527elif case in {"bz2", "xz"}:
1628 source = Path(__file__).with_name("fixtures").joinpath("sample.tar").read_bytes()
1729 encode = bz2.compress if case == "bz2" else lzma.compress
추가tests/rust-archive-worker/progress_clock.c+28-0
@@ -0,0 +1,28 @@
1추가: #define _GNU_SOURCE
2추가: #include <dlfcn.h>
3추가: #include <stdatomic.h>
4추가: #include <stdlib.h>
5추가: #include <string.h>
6추가: #include <time.h>
7추가: #include <unistd.h>
8추가:
9추가: static atomic_long elapsed;
10추가:
11추가: int clock_gettime(clockid_t id, struct timespec *value) {
12추가: int (*original)(clockid_t, struct timespec *) = dlsym(RTLD_NEXT, "clock_gettime");
13추가: int result = original(id, value);
14추가: if (result == 0 && id == CLOCK_MONOTONIC) {
15추가: value->tv_sec += atomic_load(&elapsed);
16추가: }
17추가: return result;
18추가: }
19추가:
20추가: int fsync(int fd) {
21추가: int (*original)(int) = dlsym(RTLD_NEXT, "fsync");
22추가: int result = original(fd);
23추가: if (result == 0) {
24추가: const char *mode = getenv("ZIPELO_TEST_FAULT");
25추가: atomic_fetch_add(&elapsed, mode && !strcmp(mode, "clock-stall") ? 60 : 10);
26추가: }
27추가: return result;
28추가: }