Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mercury/src/internal/pack/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ impl _Cache for Caches {
self.complete_signal.clone(),
Some(self.pool.clone()),
);
a_obj.set_store_path(Caches::generate_temp_path(&self.tmp_path, hash));
if self.mem_size.is_some() {
a_obj.set_store_path(Caches::generate_temp_path(&self.tmp_path, hash));
}
let _ = map.insert(hash, a_obj);
}
//order maters as for reading in 'get_by_offset()'
Expand Down
18 changes: 16 additions & 2 deletions mercury/src/internal/pack/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl Pack {
pool: Arc::new(ThreadPool::new(thread_num)),
waitlist: Arc::new(Waitlist::new()),
caches: Arc::new(Caches::new(cache_mem_size, temp_path, thread_num)),
mem_limit: mem_limit.unwrap_or(usize::MAX),
mem_limit,
cache_objs_mem: Arc::new(AtomicUsize::default()),
clean_tmp,
}
Expand Down Expand Up @@ -363,7 +363,8 @@ impl Pack {
}
// 3 parts: Waitlist + TheadPool + Caches
// hardcode the limit of the tasks of threads_pool queue, to limit memory
while self.memory_used() > self.mem_limit || self.pool.queued_count() > 2000 {
while self.pool.queued_count() > 2000
|| self.mem_limit.map(|limit| self.memory_used() > limit).unwrap_or(false) {
thread::yield_now();
}
let r: Result<CacheObject, GitError> = self.decode_pack_object(&mut reader, &mut offset);
Expand Down Expand Up @@ -709,6 +710,19 @@ mod tests {
p.decode(&mut buffered,|_,_|{}).unwrap();
}

#[test]
fn test_pack_decode_no_mem_limit() {
let mut source = PathBuf::from(env::current_dir().unwrap().parent().unwrap());
source.push("tests/data/packs/pack-1d0e6c14760c956c173ede71cb28f33d921e232f.pack");

let tmp = PathBuf::from("/tmp/.cache_temp");

let f = fs::File::open(source).unwrap();
let mut buffered = BufReader::new(f);
let mut p = Pack::new(None, None, Some(tmp), true);
p.decode(&mut buffered, |_,_|{}).unwrap();
}

#[test]
fn test_pack_decode_with_large_file_with_delta_without_ref() {
init_logger();
Expand Down
2 changes: 1 addition & 1 deletion mercury/src/internal/pack/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct Pack {
pub pool: Arc<ThreadPool>,
pub waitlist: Arc<Waitlist>,
pub caches: Arc<Caches>,
pub mem_limit: usize,
pub mem_limit: Option<usize>,
pub cache_objs_mem: Arc<AtomicUsize>, // the memory size of CacheObjects in this Pack
pub clean_tmp: bool,
}
Expand Down