Skip to content

Commit

Permalink
Invalidate all files in the graph when we get a rescan event.
Browse files Browse the repository at this point in the history
[ci skip-build-wheels]
  • Loading branch information
stuhood committed Mar 18, 2021
1 parent 2741e23 commit 1344f08
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
10 changes: 10 additions & 0 deletions src/rust/engine/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,16 @@ impl Invalidatable for InvalidatableGraph {
);
cleared + dirtied
}

fn invalidate_all(&self, caller: &str) -> usize {
let InvalidationResult { cleared, dirtied } =
self.invalidate_from_roots(|node| node.fs_subject().is_some());
info!(
"{} invalidation: cleared {} and dirtied {} nodes for all paths",
caller, cleared, dirtied
);
cleared + dirtied
}
}

impl Deref for InvalidatableGraph {
Expand Down
14 changes: 3 additions & 11 deletions src/rust/engine/src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use crate::nodes::{Select, Visualizer};
use crate::session::{ObservedValueResult, Root, Session};

use futures::{future, FutureExt};
use graph::{InvalidationResult, LastObserved};
use graph::LastObserved;
use hashing::{Digest, EMPTY_DIGEST};
use log::{debug, info, warn};
use log::{debug, warn};
use stdio::TryCloneAsFile;
use tempfile::TempDir;
use tokio::process;
Expand Down Expand Up @@ -109,15 +109,7 @@ impl Scheduler {
/// Invalidate all filesystem dependencies in the graph.
///
pub fn invalidate_all_paths(&self) -> usize {
let InvalidationResult { cleared, dirtied } = self
.core
.graph
.invalidate_from_roots(|node| node.fs_subject().is_some());
info!(
"invalidation: cleared {} and dirtied {} nodes for all paths",
cleared, dirtied
);
cleared + dirtied
self.core.graph.invalidate_all("external")
}

///
Expand Down
10 changes: 8 additions & 2 deletions src/rust/engine/watch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ use std::time::Duration;
use crossbeam_channel::{self, Receiver, RecvTimeoutError, TryRecvError};
use fs::GitignoreStyleExcludes;
use log::{debug, trace, warn};
use notify::event::Flag;
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
use parking_lot::Mutex;
use task_executor::Executor;
Expand Down Expand Up @@ -159,6 +160,7 @@ impl InvalidationWatcher {
};
match event_res {
Ok(Ok(ev)) => {
let flag = ev.flag();
let paths: HashSet<_> = ev
.paths
.into_iter()
Expand Down Expand Up @@ -198,10 +200,13 @@ impl InvalidationWatcher {
.collect();

// Only invalidate stuff if we have paths that weren't filtered out by gitignore.
if !paths.is_empty() {
if flag == Some(Flag::Rescan) {
debug!("notify queue overflowed: invalidating all paths");
invalidatable.invalidate_all("notify");
} else if !paths.is_empty() {
debug!("notify invalidating {:?} because of {:?}", paths, ev.kind);
invalidatable.invalidate(&paths, "notify");
};
}
}
Ok(Err(err)) => {
if let notify::ErrorKind::PathNotFound = err.kind {
Expand Down Expand Up @@ -282,6 +287,7 @@ impl InvalidationWatcher {

pub trait Invalidatable: Send + Sync + 'static {
fn invalidate(&self, paths: &HashSet<PathBuf>, caller: &str) -> usize;
fn invalidate_all(&self, caller: &str) -> usize;
}

///
Expand Down
4 changes: 4 additions & 0 deletions src/rust/engine/watch/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,8 @@ impl Invalidatable for TestInvalidatable {
calls.push(paths.clone());
invalidated
}

fn invalidate_all(&self, _caller: &str) -> usize {
unimplemented!();
}
}

0 comments on commit 1344f08

Please sign in to comment.