Skip to content

Commit 289343c

Browse files
Merge branch 'graphprotocol:master' into shuaib/handle-max-endblock
2 parents e6cf737 + e2e6925 commit 289343c

File tree

12 files changed

+98
-25
lines changed

12 files changed

+98
-25
lines changed

graph/src/data/subgraph/schema.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Entity types that contain the graph-node state.
22
33
use anyhow::{anyhow, bail, Error};
4+
use chrono::{DateTime, Utc};
45
use hex;
56
use rand::rngs::OsRng;
67
use rand::Rng;
@@ -159,7 +160,7 @@ pub struct SubgraphDeploymentEntity {
159160
pub manifest: SubgraphManifestEntity,
160161
pub failed: bool,
161162
pub health: SubgraphHealth,
162-
pub synced: bool,
163+
pub synced_at: Option<DateTime<Utc>>,
163164
pub fatal_error: Option<SubgraphError>,
164165
pub non_fatal_errors: Vec<SubgraphError>,
165166
/// The earliest block for which we have data

graph/src/data/value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl<'a> IntoIterator for &'a Object {
276276
impl std::fmt::Debug for Object {
277277
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
278278
f.debug_map()
279-
.entries(self.0.into_iter().map(|e| {
279+
.entries(self.0.iter().map(|e| {
280280
(
281281
e.key.as_ref().map(|w| w.as_str()).unwrap_or("---"),
282282
&e.value,

graph/src/schema/input/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -929,7 +929,7 @@ impl Aggregation {
929929

930930
pub fn dimensions(&self) -> impl Iterator<Item = &Field> {
931931
self.fields
932-
.into_iter()
932+
.iter()
933933
.filter(|field| &field.name != &*ID && field.name != kw::TIMESTAMP)
934934
}
935935

@@ -1240,7 +1240,7 @@ impl InputSchema {
12401240
};
12411241
Ok(obj_type
12421242
.shared_interfaces
1243-
.into_iter()
1243+
.iter()
12441244
.map(|atom| EntityType::new(self.cheap_clone(), *atom))
12451245
.collect())
12461246
}

graph/src/util/intern.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct Atom(AtomInt);
3333

3434
/// An atom and the underlying pool. A `FatAtom` can be used in place of a
3535
/// `String` or `Word`
36+
#[allow(dead_code)]
3637
pub struct FatAtom {
3738
pool: Arc<AtomPool>,
3839
atom: Atom,

server/index-node/src/schema.graphql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,12 @@ type SubgraphIndexingStatus {
7070
nonFatalErrors: [SubgraphError!]!
7171
chains: [ChainIndexingStatus!]!
7272
entityCount: BigInt!
73+
74+
"null if deployment is not assigned to an indexing node"
7375
node: String
74-
paused: Boolean!
76+
"null if deployment is not assigned to an indexing node"
77+
paused: Boolean
78+
7579
historyBlocks: Int!
7680
}
7781

server/json-rpc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<R: SubgraphRegistrar> ServerState<R> {
204204

205205
/// Handler for the `subgraph_resume` endpoint.
206206
async fn resume_handler(&self, params: SubgraphPauseParams) -> JsonRpcResult<GraphValue> {
207-
info!(&self.logger, "Received subgraph_pause request"; "params" => format!("{:?}", params));
207+
info!(&self.logger, "Received subgraph_resume request"; "params" => format!("{:?}", params));
208208

209209
match self.registrar.resume_subgraph(&params.deployment).await {
210210
Ok(_) => Ok(Value::Null),
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
DROP VIEW info.subgraph_info;
2+
3+
ALTER TABLE subgraphs.subgraph_deployment ADD COLUMN synced BOOLEAN NOT NULL DEFAULT false;
4+
ALTER TABLE unused_deployments ADD COLUMN synced BOOLEAN NOT NULL DEFAULT false;
5+
6+
UPDATE subgraphs.subgraph_deployment SET synced = synced_at IS NOT NULL;
7+
UPDATE unused_deployments SET synced = synced_at IS NOT NULL;
8+
9+
-- NB: We keep the default on unused_deployment, as it was there before.
10+
ALTER TABLE subgraphs.subgraph_deployment ALTER COLUMN synced DROP DEFAULT;
11+
12+
ALTER TABLE subgraphs.subgraph_deployment DROP COLUMN synced_at;
13+
ALTER TABLE unused_deployments DROP COLUMN synced_at;
14+
15+
CREATE VIEW info.subgraph_info AS
16+
SELECT ds.id AS schema_id,
17+
ds.name AS schema_name,
18+
ds.subgraph,
19+
ds.version,
20+
s.name,
21+
CASE
22+
WHEN s.pending_version = v.id THEN 'pending'::text
23+
WHEN s.current_version = v.id THEN 'current'::text
24+
ELSE 'unused'::text
25+
END AS status,
26+
d.failed,
27+
d.synced
28+
FROM deployment_schemas ds,
29+
subgraphs.subgraph_deployment d,
30+
subgraphs.subgraph_version v,
31+
subgraphs.subgraph s
32+
WHERE d.deployment = ds.subgraph::text AND v.deployment = d.deployment AND v.subgraph = s.id;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
DROP VIEW info.subgraph_info;
2+
3+
ALTER TABLE subgraphs.subgraph_deployment ADD COLUMN synced_at TIMESTAMPTZ;
4+
ALTER TABLE unused_deployments ADD COLUMN synced_at TIMESTAMPTZ;
5+
6+
UPDATE subgraphs.subgraph_deployment SET synced_at = '1970-01-01 00:00:00 UTC' WHERE synced;
7+
UPDATE unused_deployments SET synced_at = '1970-01-01 00:00:00 UTC' WHERE synced;
8+
9+
ALTER TABLE subgraphs.subgraph_deployment DROP COLUMN synced;
10+
ALTER TABLE unused_deployments DROP COLUMN synced;
11+
12+
CREATE VIEW info.subgraph_info AS
13+
SELECT ds.id AS schema_id,
14+
ds.name AS schema_name,
15+
ds.subgraph,
16+
ds.version,
17+
s.name,
18+
CASE
19+
WHEN s.pending_version = v.id THEN 'pending'::text
20+
WHEN s.current_version = v.id THEN 'current'::text
21+
ELSE 'unused'::text
22+
END AS status,
23+
d.failed,
24+
d.synced_at
25+
FROM deployment_schemas ds,
26+
subgraphs.subgraph_deployment d,
27+
subgraphs.subgraph_version v,
28+
subgraphs.subgraph s
29+
WHERE d.deployment = ds.subgraph::text AND v.deployment = d.deployment AND v.subgraph = s.id;

store/postgres/src/deployment.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use crate::{advisory_lock, detail::GraphNodeVersion, primary::DeploymentId};
55
use diesel::{
66
connection::SimpleConnection,
7-
dsl::{count, delete, insert_into, select, sql, update},
7+
dsl::{count, delete, insert_into, now, select, sql, update},
88
sql_types::{Bool, Integer},
99
};
1010
use diesel::{expression::SqlLiteral, pg::PgConnection, sql_types::Numeric};
@@ -132,7 +132,7 @@ table! {
132132
deployment -> Text,
133133
failed -> Bool,
134134
health -> crate::deployment::SubgraphHealthMapping,
135-
synced -> Bool,
135+
synced_at -> Nullable<Timestamptz>,
136136
fatal_error -> Nullable<Text>,
137137
non_fatal_errors -> Array<Text>,
138138
earliest_block_number -> Integer,
@@ -737,9 +737,9 @@ pub fn set_synced(conn: &mut PgConnection, id: &DeploymentHash) -> Result<(), St
737737
update(
738738
d::table
739739
.filter(d::deployment.eq(id.as_str()))
740-
.filter(d::synced.eq(false)),
740+
.filter(d::synced_at.is_null()),
741741
)
742-
.set(d::synced.eq(true))
742+
.set(d::synced_at.eq(now))
743743
.execute(conn)?;
744744
Ok(())
745745
}
@@ -762,7 +762,7 @@ pub fn exists_and_synced(conn: &mut PgConnection, id: &str) -> Result<bool, Stor
762762

763763
let synced = d::table
764764
.filter(d::deployment.eq(id))
765-
.select(d::synced)
765+
.select(d::synced_at.is_not_null())
766766
.first(conn)
767767
.optional()?
768768
.unwrap_or(false);
@@ -1142,7 +1142,6 @@ pub fn create_deployment(
11421142
d::id.eq(site.id),
11431143
d::deployment.eq(site.deployment.as_str()),
11441144
d::failed.eq(false),
1145-
d::synced.eq(false),
11461145
d::health.eq(SubgraphHealth::Healthy),
11471146
d::fatal_error.eq::<Option<String>>(None),
11481147
d::non_fatal_errors.eq::<Vec<String>>(vec![]),

store/postgres/src/detail.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use git_testament::{git_testament, git_testament_macros};
1212
use graph::blockchain::BlockHash;
1313
use graph::data::store::scalar::ToPrimitive;
1414
use graph::data::subgraph::schema::{SubgraphError, SubgraphManifestEntity};
15-
use graph::prelude::{BigDecimal, BlockPtr, DeploymentHash, StoreError, SubgraphDeploymentEntity};
15+
use graph::prelude::{
16+
chrono::{DateTime, Utc},
17+
BigDecimal, BlockPtr, DeploymentHash, StoreError, SubgraphDeploymentEntity,
18+
};
1619
use graph::schema::InputSchema;
1720
use graph::{constraint_violation, data::subgraph::status, prelude::web3::types::H256};
1821
use itertools::Itertools;
@@ -46,7 +49,7 @@ pub struct DeploymentDetail {
4649
pub deployment: String,
4750
pub failed: bool,
4851
health: HealthType,
49-
pub synced: bool,
52+
pub synced_at: Option<DateTime<Utc>>,
5053
fatal_error: Option<String>,
5154
non_fatal_errors: Vec<String>,
5255
/// The earliest block for which we have history
@@ -188,7 +191,7 @@ pub(crate) fn info_from_details(
188191
deployment,
189192
failed: _,
190193
health,
191-
synced,
194+
synced_at,
192195
fatal_error: _,
193196
non_fatal_errors: _,
194197
earliest_block_number,
@@ -238,7 +241,7 @@ pub(crate) fn info_from_details(
238241
Ok(status::Info {
239242
id: id.into(),
240243
subgraph: deployment,
241-
synced,
244+
synced: synced_at.is_some(),
242245
health,
243246
paused: None,
244247
fatal_error,
@@ -446,7 +449,7 @@ impl StoredDeploymentEntity {
446449
manifest: manifest.as_manifest(schema),
447450
failed: detail.failed,
448451
health: detail.health.into(),
449-
synced: detail.synced,
452+
synced_at: detail.synced_at,
450453
fatal_error: None,
451454
non_fatal_errors: vec![],
452455
earliest_block_number: detail.earliest_block_number,

0 commit comments

Comments
 (0)