Skip to content

Commit e68fb1d

Browse files
committed
graph: Check that BATCH_TIMEOUT is big enough
A value that's too small will just needlessly cause timeouts and slow down copies.
1 parent feac392 commit e68fb1d

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

graph/src/env/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ pub struct EnvVars {
250250
}
251251

252252
impl EnvVars {
253-
pub fn from_env() -> Result<Self, envconfig::Error> {
253+
pub fn from_env() -> Result<Self, anyhow::Error> {
254254
let inner = Inner::init_from_env()?;
255255
let graphql = InnerGraphQl::init_from_env()?.into();
256256
let mapping_handlers = InnerMappingHandlers::init_from_env()?.into();
257-
let store = InnerStore::init_from_env()?.into();
257+
let store = InnerStore::init_from_env()?.try_into()?;
258258

259259
// The default reorganization (reorg) threshold is set to 250.
260260
// For testing purposes, we need to set this threshold to 0 because:

graph/src/env/store.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,11 @@ impl fmt::Debug for EnvVarsStore {
142142
}
143143
}
144144

145-
impl From<InnerStore> for EnvVarsStore {
146-
fn from(x: InnerStore) -> Self {
147-
Self {
145+
impl TryFrom<InnerStore> for EnvVarsStore {
146+
type Error = anyhow::Error;
147+
148+
fn try_from(x: InnerStore) -> Result<Self, Self::Error> {
149+
let vars = Self {
148150
chain_head_watcher_timeout: Duration::from_secs(x.chain_head_watcher_timeout_in_secs),
149151
query_stats_refresh_interval: Duration::from_secs(
150152
x.query_stats_refresh_interval_in_secs,
@@ -184,7 +186,15 @@ impl From<InnerStore> for EnvVarsStore {
184186
last_rollup_from_poi: x.last_rollup_from_poi,
185187
insert_extra_cols: x.insert_extra_cols,
186188
fdw_fetch_size: x.fdw_fetch_size,
189+
};
190+
if let Some(timeout) = vars.batch_timeout {
191+
if timeout < 2 * vars.batch_target_duration {
192+
bail!(
193+
"GRAPH_STORE_BATCH_TIMEOUT must be greater than 2*GRAPH_STORE_BATCH_TARGET_DURATION"
194+
);
195+
}
187196
}
197+
Ok(vars)
188198
}
189199
}
190200

0 commit comments

Comments
 (0)