Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework generation of the VID #5737

Open
wants to merge 1 commit into
base: zoran/rename-structs
Choose a base branch
from

Conversation

zorancv
Copy link
Contributor

@zorancv zorancv commented Dec 18, 2024

This PR changes the generation of the VID in such a way that entities have an order determined by the order of the blockchain transactions from which they originate, rather than to be ordered by the current implementation of the graph-node and the VID autogenerated by the database. This in turn will ensure that the dependant subgraphs would have a deterministic order of their input entities and it would be consistent across different graph-node deployments producing the same POI.

@zorancv zorancv force-pushed the zoran/subgraph-composition-rework-vid-wrap2 branch from 1bbef27 to 5910d01 Compare December 18, 2024 15:47
@zorancv zorancv self-assigned this Dec 18, 2024
@zorancv zorancv added this to the Subgraph Composition milestone Dec 18, 2024
@zorancv zorancv force-pushed the zoran/rename-structs branch from 632ef9f to 9658d8c Compare December 18, 2024 18:40
@zorancv zorancv force-pushed the zoran/subgraph-composition-rework-vid-wrap2 branch from 9e6aa6d to 02ce854 Compare December 18, 2024 18:41
@zorancv zorancv force-pushed the zoran/subgraph-composition-rework-vid-wrap2 branch from 02ce854 to 62d1e2b Compare January 3, 2025 14:25
@zorancv zorancv requested a review from lutter January 3, 2025 14:46
@@ -116,19 +116,26 @@ impl Table {
Ok(cols)
}

let vid_type = if self.object.is_poi() || !self.object.is_object_type() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lutter I am not sure which types could have the VIDs still autogenerated as before. Here I choose POI, interface and aggregate types. Is this correct?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking, for POI it doesn't matter, and there's never instances of interfaces (only objects that implement an interface), but I think for simplicity, it might be best to autogenerate a vid for every kind of entity we deal with.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you would prefer that all is generated by us rather than from the database? Is there inconsistency concern regarding the aggregation (that one is more involved)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a PR #5770 that disables aggregations entities as source entities for now.

Copy link
Collaborator

@lutter lutter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A general question: we already require that every Entity has an id, if it doesn't, things will fail in funky ways. Wouldn't it be simpler to just treat the vid as another attribute of Entity, i.e., require that entity.get("vid") always returns something instead of keeping it separate from the entity?

graph/src/components/store/entity_cache.rs Outdated Show resolved Hide resolved
@@ -116,19 +116,26 @@ impl Table {
Ok(cols)
}

let vid_type = if self.object.is_poi() || !self.object.is_object_type() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strictly speaking, for POI it doesn't matter, and there's never instances of interfaces (only objects that implement an interface), but I think for simplicity, it might be best to autogenerate a vid for every kind of entity we deal with.

@zorancv zorancv force-pushed the zoran/subgraph-composition-rework-vid-wrap2 branch 3 times, most recently from 70a0f32 to 6e5b0bc Compare January 16, 2025 16:28
@zorancv zorancv marked this pull request as draft January 16, 2025 16:42
@zorancv zorancv force-pushed the zoran/subgraph-composition-rework-vid-wrap2 branch 10 times, most recently from b6f7492 to 640e7d1 Compare January 19, 2025 17:34
@zorancv zorancv changed the base branch from zoran/rename-structs to master January 19, 2025 17:36
@zorancv zorancv changed the base branch from master to zoran/rename-structs January 19, 2025 17:37
@zorancv
Copy link
Contributor Author

zorancv commented Jan 20, 2025

A general question: we already require that every Entity has an id, if it doesn't, things will fail in funky ways. Wouldn't it be simpler to just treat the vid as another attribute of Entity, i.e., require that entity.get("vid") always returns something instead of keeping it separate from the entity?

@lutter I've decided to go that route. It simplifies the code a lot. Also I've added a check in the EntityCache set() that there was no VID previously set.

Finally when deserializing the entities from the database, I added deserialization of the the VID in addition to the list of fields from InputSchema, in order to keep the presence of the VID consistent in the Entity struct.

Those are two major changes since your last review.

@zorancv zorancv marked this pull request as ready for review January 20, 2025 16:20
@zorancv zorancv changed the base branch from zoran/rename-structs to zoran/subgraph-composition-rework-vid-wrap January 20, 2025 22:56
@zorancv zorancv changed the base branch from zoran/subgraph-composition-rework-vid-wrap to zoran/subgraph-composition-rework-vid-wrap5 January 20, 2025 22:56
@zorancv zorancv force-pushed the zoran/subgraph-composition-rework-vid-wrap2 branch 3 times, most recently from 6feee8e to 14671db Compare January 21, 2025 14:34
@zorancv zorancv changed the base branch from zoran/rename-structs to zoran/subgraph-composition-rework-vid-wrap5 January 21, 2025 15:12
@zorancv zorancv closed this Jan 21, 2025
@zorancv zorancv force-pushed the zoran/subgraph-composition-rework-vid-wrap2 branch from 14671db to 640e7d1 Compare January 21, 2025 15:24
@zorancv zorancv reopened this Jan 21, 2025
@zorancv zorancv changed the base branch from zoran/subgraph-composition-rework-vid-wrap5 to zoran/rename-structs January 21, 2025 15:47
@zorancv zorancv force-pushed the zoran/subgraph-composition-rework-vid-wrap2 branch from 14671db to 640e7d1 Compare January 21, 2025 15:48
@zorancv zorancv requested a review from lutter January 21, 2025 15:54
Copy link
Collaborator

@lutter lutter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. I'd mostly just like to understand better what is happening with the explicit block number for the PoI.

Also, I don't think there are any tests that ensure that the vid's are indeed set by insertion order. It would be good to have a test for the EntityCache that ensures that.

graph/src/data/store/mod.rs Outdated Show resolved Hide resolved
graph/src/data/subgraph/api_version.rs Outdated Show resolved Hide resolved
graph/src/schema/input/mod.rs Outdated Show resolved Hide resolved
store/postgres/src/relational/ddl.rs Outdated Show resolved Hide resolved
store/postgres/src/relational/prune.rs Show resolved Hide resolved
store/postgres/src/relational_queries.rs Outdated Show resolved Hide resolved
graph/src/components/store/entity_cache.rs Outdated Show resolved Hide resolved
core/src/subgraph/runner.rs Show resolved Hide resolved
/// Sets the VID of the entity. The previous one is returned.
pub fn set_vid(&mut self, value: i64) -> Result<Option<Value>, InternError> {
self.0.insert("vid", value.into())
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One additional thought: it would be great if we could guarantee that an entity is always constructed with the vid set, similar to how that's done for the id. I haven't checked how much work that is, but it would make the various expects sprinkled around here easier to accept.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the suggestion but would like to postpone it together with the testing request above for a later stage. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test for the VID order is implemented now: 166c909

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with postponing the enforcement of having a vid

@zorancv zorancv force-pushed the zoran/subgraph-composition-rework-vid-wrap2 branch 5 times, most recently from 961556b to a49edb8 Compare January 29, 2025 16:35
Copy link
Collaborator

@lutter lutter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I left some minor stylistic comments, would be great to address them, but I am totally fine with merging this.

graph/src/components/store/entity_cache.rs Outdated Show resolved Hide resolved
graph/src/data/subgraph/api_version.rs Outdated Show resolved Hide resolved
store/postgres/src/relational/prune.rs Show resolved Hide resolved
store/postgres/src/relational/prune.rs Show resolved Hide resolved
store/postgres/src/relational_queries.rs Show resolved Hide resolved
@incrypto32 incrypto32 force-pushed the zoran/rename-structs branch from 9658d8c to cca4d6f Compare January 31, 2025 13:44
@incrypto32 incrypto32 force-pushed the zoran/subgraph-composition-rework-vid-wrap2 branch 2 times, most recently from e61452f to 1cb3401 Compare January 31, 2025 15:22
@zorancv zorancv force-pushed the zoran/subgraph-composition-rework-vid-wrap2 branch 5 times, most recently from 7173051 to 46fa0f4 Compare February 2, 2025 09:28
@incrypto32 incrypto32 force-pushed the zoran/subgraph-composition-rework-vid-wrap2 branch from 46fa0f4 to 061b9c7 Compare February 3, 2025 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants