Skip to content

Commit 642ac19

Browse files
committed
all: Move blocking of expensive queries into the LoadManager
1 parent a14587a commit 642ac19

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

graph/src/data/graphql/effort.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,25 @@ impl QueryEffortInner {
6666
pub struct LoadManager {
6767
effort: QueryEffort,
6868
store_wait_stats: PoolWaitStats,
69+
blocked_queries: Vec<u64>,
6970
}
7071

7172
impl LoadManager {
72-
pub fn new(store_wait_stats: PoolWaitStats) -> Self {
73+
pub fn new(store_wait_stats: PoolWaitStats, blocked_queries: Vec<u64>) -> Self {
7374
Self {
7475
effort: QueryEffort::default(),
7576
store_wait_stats,
77+
blocked_queries,
7678
}
7779
}
7880

7981
pub fn add_query(&self, shape_hash: u64, duration: Duration) {
8082
self.effort.add(shape_hash, duration);
8183
}
84+
85+
/// Return `true` if we should decline running the query with this
86+
/// `ShapeHash`
87+
pub fn decline(&self, shape_hash: u64) -> bool {
88+
self.blocked_queries.contains(&shape_hash)
89+
}
8290
}

graphql/src/runner.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use futures01::future;
22
use graphql_parser::query as q;
3-
use std::collections::{BTreeMap, HashMap};
3+
use std::collections::BTreeMap;
44
use std::env;
55
use std::str::FromStr;
66
use std::sync::Arc;
@@ -25,7 +25,6 @@ use lazy_static::lazy_static;
2525
pub struct GraphQlRunner<S> {
2626
logger: Logger,
2727
store: Arc<S>,
28-
expensive: HashMap<u64, Arc<q::Document>>,
2928
load_manager: Arc<LoadManager>,
3029
}
3130

@@ -65,13 +64,12 @@ where
6564
) -> Self {
6665
let expensive = expensive
6766
.into_iter()
68-
.map(|doc| (shape_hash(&doc), doc.clone()))
69-
.collect::<HashMap<_, _>>();
67+
.map(|doc| shape_hash(&doc))
68+
.collect::<Vec<_>>();
7069
GraphQlRunner {
7170
logger: logger.new(o!("component" => "GraphQlRunner")),
7271
store,
73-
expensive,
74-
load_manager: Arc::new(LoadManager::new(store_wait_stats)),
72+
load_manager: Arc::new(LoadManager::new(store_wait_stats, expensive)),
7573
}
7674
}
7775

@@ -156,7 +154,7 @@ where
156154
}
157155

158156
pub fn check_too_expensive(&self, query: &Query) -> Result<(), Vec<QueryExecutionError>> {
159-
if self.expensive.contains_key(&query.shape_hash) {
157+
if self.load_manager.decline(query.shape_hash) {
160158
Err(vec![QueryExecutionError::TooExpensive])
161159
} else {
162160
Ok(())

store/test-store/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ lazy_static! {
3939

4040
pub static ref POOL_WAIT_STATS: PoolWaitStats = Arc::new(RwLock::new(MovingStats::default()));
4141

42-
pub static ref LOAD_MANAGER: Arc<LoadManager> = Arc::new(LoadManager::new(POOL_WAIT_STATS.clone()));
42+
pub static ref LOAD_MANAGER: Arc<LoadManager> = Arc::new(LoadManager::new(POOL_WAIT_STATS.clone(), vec![]));
4343

4444
// Create Store instance once for use with each of the tests.
4545
pub static ref STORE: Arc<Store> = {

0 commit comments

Comments
 (0)