Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 905e76f

Browse files
committed
core: Unfail subgraph only after successful processing
1 parent d3d3dc6 commit 905e76f

File tree

7 files changed

+42
-11
lines changed

7 files changed

+42
-11
lines changed

core/src/subgraph/instance_manager.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ where
455455
let store_for_err = ctx.inputs.store.cheap_clone();
456456
let logger = ctx.state.logger.cheap_clone();
457457
let id_for_err = ctx.inputs.deployment_id.clone();
458+
let mut first_run = true;
458459

459460
loop {
460461
debug!(logger, "Starting or restarting subgraph");
@@ -596,6 +597,18 @@ where
596597
match res {
597598
Ok((c, needs_restart)) => {
598599
ctx = c;
600+
601+
// Unfail the subgraph if it was previously failed.
602+
// As an optimization we check this only on the first run.
603+
if first_run {
604+
first_run = false;
605+
606+
ctx.inputs
607+
.store
608+
.unfail(&ctx.inputs.deployment_id)
609+
.map_err(|_| ())?;
610+
}
611+
599612
if needs_restart {
600613
// Cancel the stream for real
601614
ctx.state

graph/src/components/store.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,16 +1080,16 @@ pub trait SubgraphStore: Send + Sync + 'static {
10801080

10811081
fn unassign_subgraph(&self, id: &SubgraphDeploymentId) -> Result<(), StoreError>;
10821082

1083-
/// Start an existing subgraph deployment. This will reset the state of
1084-
/// the subgraph to a known good state. `ops` needs to contain all the
1085-
/// operations on the subgraph of subgraphs to reset the metadata of the
1086-
/// subgraph
1083+
/// Start an existing subgraph deployment.
10871084
fn start_subgraph_deployment(
10881085
&self,
10891086
logger: &Logger,
10901087
subgraph_id: &SubgraphDeploymentId,
10911088
) -> Result<(), StoreError>;
10921089

1090+
/// Remove the fatal error from a subgraph and check if it is healthy or unhealthy.
1091+
fn unfail(&self, subgraph_id: &SubgraphDeploymentId) -> Result<(), StoreError>;
1092+
10931093
/// Load the dynamic data sources for the given deployment
10941094
async fn load_dynamic_data_sources(
10951095
&self,
@@ -1278,6 +1278,10 @@ impl SubgraphStore for MockStore {
12781278
unimplemented!()
12791279
}
12801280

1281+
fn unfail(&self, _: &SubgraphDeploymentId) -> Result<(), StoreError> {
1282+
unimplemented!()
1283+
}
1284+
12811285
fn is_deployment_synced(&self, _: &SubgraphDeploymentId) -> Result<bool, Error> {
12821286
unimplemented!()
12831287
}

mock/src/store.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ impl SubgraphStore for MockStore {
185185
unimplemented!()
186186
}
187187

188+
fn unfail(&self, _: &SubgraphDeploymentId) -> Result<(), StoreError> {
189+
unimplemented!()
190+
}
191+
188192
fn is_deployment_synced(&self, _: &SubgraphDeploymentId) -> Result<bool, Error> {
189193
unimplemented!()
190194
}

store/postgres/src/deployment_store.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,10 +1071,12 @@ impl DeploymentStore {
10711071
graft_base: Option<(Site, EthereumBlockPointer)>,
10721072
) -> Result<(), StoreError> {
10731073
let econn = self.get_entity_conn(&site, ReplicaId::Main)?;
1074-
econn.transaction(|| {
1075-
deployment::unfail(&econn.conn, &site.deployment)?;
1076-
econn.start_subgraph(logger, graft_base)
1077-
})
1074+
econn.transaction(|| econn.start_subgraph(logger, graft_base))
1075+
}
1076+
1077+
pub(crate) fn unfail(&self, site: Arc<Site>) -> Result<(), StoreError> {
1078+
let econn = self.get_entity_conn(&site, ReplicaId::Main)?;
1079+
econn.transaction(|| deployment::unfail(&econn.conn, &site.deployment))
10781080
}
10791081

10801082
#[cfg(debug_assertions)]

store/postgres/src/store.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ impl SubgraphStoreTrait for Store {
195195
self.store.start_subgraph_deployment(logger, subgraph_id)
196196
}
197197

198+
fn unfail(&self, id: &SubgraphDeploymentId) -> Result<(), StoreError> {
199+
self.store.unfail(id)
200+
}
201+
198202
fn is_deployment_synced(&self, id: &SubgraphDeploymentId) -> Result<bool, Error> {
199203
self.store.is_deployment_synced(id)
200204
}

store/postgres/src/subgraph_store.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,6 +745,11 @@ impl SubgraphStoreTrait for SubgraphStore {
745745
store.start_subgraph(logger, site, graft_base)
746746
}
747747

748+
fn unfail(&self, id: &SubgraphDeploymentId) -> Result<(), StoreError> {
749+
let (store, site) = self.store(id)?;
750+
store.unfail(site)
751+
}
752+
748753
fn is_deployment_synced(&self, id: &SubgraphDeploymentId) -> Result<bool, Error> {
749754
let (store, _) = self.store(&id)?;
750755
Ok(store.exists_and_synced(&id)?)

store/postgres/tests/subgraph.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use graph::{
1212
prelude::SubgraphManifest,
1313
prelude::SubgraphName,
1414
prelude::SubgraphVersionSwitchingMode,
15-
prelude::{o, slog, CheapClone, Logger, NodeId, SubgraphDeploymentId, SubgraphStore as _},
15+
prelude::{CheapClone, NodeId, SubgraphDeploymentId, SubgraphStore as _},
1616
};
1717
use graph_store_postgres::layout_for_tests::Connection as Primary;
1818
use graph_store_postgres::Store;
@@ -554,7 +554,6 @@ fn fail_unfail() {
554554
}
555555

556556
run_test_sequentially(setup, |store, id| async move {
557-
let logger = Logger::root(slog::Discard, o!());
558557
let query_store = store
559558
.query_store(id.cheap_clone().into(), false)
560559
.await
@@ -576,7 +575,7 @@ fn fail_unfail() {
576575
.unwrap());
577576

578577
// This will unfail the subgraph and delete the fatal error.
579-
store.start_subgraph_deployment(&logger, &id).unwrap();
578+
store.unfail(&id).unwrap();
580579

581580
// Advance the block ptr to the block of the deleted error.
582581
transact_entity_operations(&store, id.cheap_clone(), BLOCKS[1], vec![]).unwrap();

0 commit comments

Comments
 (0)