Skip to content

Commit

Permalink
Exit early when all known hosts rejected the download
Browse files Browse the repository at this point in the history
  • Loading branch information
tailhook committed May 26, 2018
1 parent f306db5 commit 4bbc1c5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 2 additions & 0 deletions doc/changelog.rst
Expand Up @@ -12,3 +12,5 @@ Ciruela 0.6.7
* Feature: add old image identifier support in ``ciruela sync --replace``
(and rust API) which means we can do (limited version of) atomic updates to
the directory.
* Bugfix: when all discovered hosts have no config ciruela finishes with
rejection instead of waiting indefinitely
6 changes: 4 additions & 2 deletions src/cluster/set.rs
Expand Up @@ -614,7 +614,8 @@ impl<R, I, B> ConnectionSet<R, I, B>
up.stats.total_responses());
if up.futures.len() == 0 && up.stats.total_responses() > 0 {
let check = upload::check(&up.stats, &self.config,
&self.initial_addr, early_timeout);
&self.initial_addr, early_timeout,
up.candidate_hosts.is_empty());
match check {
Some(Ok(result)) => {
up.resolve.send(Ok(result)).ok();
Expand All @@ -632,7 +633,8 @@ impl<R, I, B> ConnectionSet<R, I, B>

if up.deadline.poll().expect("timeout is infallible").is_ready() {
let check = upload::check(&up.stats, &self.config,
&self.initial_addr, early_timeout);
&self.initial_addr, early_timeout,
up.candidate_hosts.is_empty());
match check {
Some(Ok(result)) => {
up.resolve.send(Ok(result)).ok();
Expand Down
15 changes: 10 additions & 5 deletions src/cluster/upload.rs
Expand Up @@ -121,7 +121,9 @@ impl Stats {
}
(false, Some("no_config")) => {
warn!("Info {} rejects directory", source);
book.rejected_no_config.insert(source);
if book.rejected_no_config.insert(source) {
self.total_responses.fetch_add(1, Ordering::Relaxed);
}
}
(false, _) => {
warn!("Rejected because of {:?} try {:?}",
Expand Down Expand Up @@ -209,19 +211,22 @@ fn is_superset(done: &HashMap<MachineId, String>,
}

pub(in cluster) fn check(stats: &Arc<Stats>, config: &Config,
initial_addr: &AddrCell, early_timeout_timed_out: bool)
initial_addr: &AddrCell, early_timeout_timed_out: bool,
no_candidates: bool)
-> Option<Result<UploadOk, ErrorKind>>
{
let book = stats.book.read()
.expect("bookkeeping is not poisoned");
trace!("Current state {:?}{}", book,
if early_timeout_timed_out { "" } else { " early" });
if book.accepted_ips.len() == 0 && book.rejected_ips.len() > 0
&& initial_addr.is_done()
if book.accepted_ips.is_empty() &&
initial_addr.is_done() && no_candidates &&
(!book.rejected_ips.is_empty() || !book.rejected_no_config.is_empty())
{
let all_rejected = initial_addr.get().addresses_at(0)
.all(|a| book.rejected_ips.contains_key(&a) ||
book.aborted_ips.contains_key(&a));
book.aborted_ips.contains_key(&a) ||
book.rejected_no_config.contains(&a));
if all_rejected {
return Some(Err(ErrorKind::Rejected));
}
Expand Down

0 comments on commit 4bbc1c5

Please sign in to comment.