Skip to content

Commit bee495c

Browse files
Split housekeeping; use structured tracing for it (#1530)
* Split housekeeping; use structured tracing for it * small fixes
1 parent 7e2474f commit bee495c

File tree

4 files changed

+272
-111
lines changed

4 files changed

+272
-111
lines changed

josh-core/src/housekeeping.rs

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::*;
22
use itertools::Itertools;
33
use std::collections::{BTreeSet, HashMap};
4-
use std::path::Path;
54
use tracing::{Level, info, span};
65

76
pub type KnownViews = HashMap<String, (git2::Oid, BTreeSet<String>)>;
@@ -118,25 +117,6 @@ pub fn memorize_from_to(
118117
Ok(((from, oid), to_ref))
119118
}
120119

121-
fn run_command(path: &Path, cmd: &[&str]) -> String {
122-
let shell = shell::Shell {
123-
cwd: path.to_owned(),
124-
};
125-
126-
let output = "";
127-
128-
let (stdout, stderr, _) = shell.command(cmd);
129-
let output = format!(
130-
"{}\n\n{}:\nstdout:\n{}\n\nstderr:{}\n",
131-
output,
132-
cmd.join(" "),
133-
stdout,
134-
stderr
135-
);
136-
137-
output
138-
}
139-
140120
regex_parsed!(UpstreamRef, r"refs/josh/upstream/(?P<ns>.*[.]git)/.*", [ns]);
141121

142122
regex_parsed!(
@@ -321,93 +301,3 @@ pub fn get_known_filters() -> JoshResult<std::collections::BTreeMap<String, BTre
321301
.map(|(repo, (_, filters))| (repo.clone(), filters.clone()))
322302
.collect())
323303
}
324-
325-
pub fn run(repo_path: &std::path::Path, do_gc: bool) -> JoshResult<()> {
326-
const CRUFT_PACK_SIZE: usize = 1024 * 1024 * 64;
327-
328-
let transaction_mirror = cache::Transaction::open(&repo_path.join("mirror"), None)?;
329-
let transaction_overlay = cache::Transaction::open(&repo_path.join("overlay"), None)?;
330-
331-
transaction_overlay
332-
.repo()
333-
.odb()?
334-
.add_disk_alternate(repo_path.join("mirror").join("objects").to_str().unwrap())?;
335-
336-
info!(
337-
"{}",
338-
run_command(
339-
transaction_mirror.repo().path(),
340-
&["git", "count-objects", "-v"]
341-
)
342-
.replace('\n', " ")
343-
);
344-
info!(
345-
"{}",
346-
run_command(
347-
transaction_overlay.repo().path(),
348-
&["git", "count-objects", "-v"]
349-
)
350-
.replace('\n', " ")
351-
);
352-
if std::env::var("JOSH_NO_DISCOVER").is_err() {
353-
housekeeping::discover_filter_candidates(&transaction_mirror)?;
354-
}
355-
if std::env::var("JOSH_NO_REFRESH").is_err() {
356-
refresh_known_filters(&transaction_mirror, &transaction_overlay)?;
357-
}
358-
if do_gc {
359-
info!(
360-
"\n----------\n{}\n----------",
361-
run_command(
362-
transaction_mirror.repo().path(),
363-
&[
364-
"git",
365-
"repack",
366-
"-adn",
367-
"--keep-unreachable",
368-
"--pack-kept-objects",
369-
"--no-write-bitmap-index",
370-
"--threads=4"
371-
]
372-
)
373-
);
374-
info!(
375-
"\n----------\n{}\n----------",
376-
run_command(
377-
transaction_mirror.repo().path(),
378-
&["git", "multi-pack-index", "write", "--bitmap"]
379-
)
380-
);
381-
info!(
382-
"\n----------\n{}\n----------",
383-
run_command(
384-
transaction_overlay.repo().path(),
385-
&[
386-
"git",
387-
"repack",
388-
"-dn",
389-
"--cruft",
390-
&format!("--max-cruft-size={}", CRUFT_PACK_SIZE),
391-
"--no-write-bitmap-index",
392-
"--window-memory=128m",
393-
"--threads=4",
394-
]
395-
)
396-
);
397-
info!(
398-
"\n----------\n{}\n----------",
399-
run_command(
400-
transaction_overlay.repo().path(),
401-
&["git", "multi-pack-index", "write", "--bitmap"]
402-
)
403-
);
404-
info!(
405-
"\n----------\n{}\n----------",
406-
run_command(
407-
transaction_mirror.repo().path(),
408-
&["git", "count-objects", "-vH"]
409-
)
410-
);
411-
}
412-
Ok(())
413-
}

josh-proxy/src/bin/josh-proxy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,7 @@ async fn run_housekeeping(local: std::path::PathBuf) -> josh::JoshResult<()> {
17551755
loop {
17561756
let local = local.clone();
17571757
tokio::task::spawn_blocking(move || {
1758-
josh::housekeeping::run(&local, (i % 60 == 0) && ARGS.gc)
1758+
josh_proxy::housekeeping::run(&local, (i % 60 == 0) && ARGS.gc)
17591759
})
17601760
.await??;
17611761
tokio::time::sleep(tokio::time::Duration::from_secs(60)).await;

0 commit comments

Comments
 (0)