Skip to content

Commit 697b89a

Browse files
committed
all: Use a HashSet to store banned/jailed queries in the LoadManager
1 parent f336570 commit 697b89a

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

graph/src/data/graphql/effort.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Utilities to keep moving statistics about queries
22
33
use rand::{prelude::Rng, thread_rng};
4-
use std::collections::HashMap;
4+
use std::collections::{HashMap, HashSet};
55
use std::env;
66
use std::str::FromStr;
77
use std::sync::{Arc, RwLock};
@@ -142,22 +142,22 @@ pub struct LoadManager {
142142
store_wait_stats: PoolWaitStats,
143143
/// List of query shapes that have been statically blocked through
144144
/// configuration
145-
blocked_queries: Vec<u64>,
145+
blocked_queries: HashSet<u64>,
146146
/// List of query shapes that have caused more than `JAIL_THRESHOLD`
147147
/// proportion of the work while the system was overloaded. Currently,
148148
/// there is no way for a query to get out of jail other than
149149
/// restarting the process
150-
jailed_queries: RwLock<Vec<u64>>,
150+
jailed_queries: RwLock<HashSet<u64>>,
151151
kill_state: RwLock<KillState>,
152152
}
153153

154154
impl LoadManager {
155-
pub fn new(store_wait_stats: PoolWaitStats, blocked_queries: Vec<u64>) -> Self {
155+
pub fn new(store_wait_stats: PoolWaitStats, blocked_queries: HashSet<u64>) -> Self {
156156
Self {
157157
effort: QueryEffort::default(),
158158
store_wait_stats,
159159
blocked_queries,
160-
jailed_queries: RwLock::new(Vec::new()),
160+
jailed_queries: RwLock::new(HashSet::new()),
161161
kill_state: RwLock::new(KillState::new()),
162162
}
163163
}
@@ -250,7 +250,7 @@ impl LoadManager {
250250
if known_query && query_effort / total_effort > *JAIL_THRESHOLD {
251251
// Any single query that causes at least JAIL_THRESHOLD of the
252252
// effort in an overload situation gets killed
253-
self.jailed_queries.write().unwrap().push(shape_hash);
253+
self.jailed_queries.write().unwrap().insert(shape_hash);
254254
return true;
255255
}
256256

graphql/src/runner.rs

Lines changed: 2 additions & 2 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;
3+
use std::collections::{BTreeMap, HashSet};
44
use std::env;
55
use std::str::FromStr;
66
use std::sync::Arc;
@@ -65,7 +65,7 @@ where
6565
let expensive = expensive
6666
.into_iter()
6767
.map(|doc| shape_hash(&doc))
68-
.collect::<Vec<_>>();
68+
.collect::<HashSet<_>>();
6969
GraphQlRunner {
7070
logger: logger.new(o!("component" => "GraphQlRunner")),
7171
store,

store/test-store/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use graph_store_postgres::{ChainHeadUpdateListener, Store, StoreConfig, Subscrip
1414
use graphql_parser::query as q;
1515
use hex_literal::hex;
1616
use lazy_static::lazy_static;
17+
use std::collections::HashSet;
1718
use std::env;
1819
use std::sync::{Mutex, RwLock};
1920
use std::time::Instant;
@@ -39,7 +40,7 @@ lazy_static! {
3940

4041
pub static ref POOL_WAIT_STATS: PoolWaitStats = Arc::new(RwLock::new(MovingStats::default()));
4142

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

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

0 commit comments

Comments
 (0)