Skip to content

Fix rollback edge case - #530

Merged
DZakh merged 5 commits into
mainfrom
jp/fix-reorg-bug
May 16, 2025
Merged

Fix rollback edge case#530
DZakh merged 5 commits into
mainfrom
jp/fix-reorg-bug

Conversation

@JonoPrest

Copy link
Copy Markdown
Collaborator

No description provided.

Comment on lines -162 to -163
->Belt.Array.map(row => {
self.insertFn(sql, row, ~shouldCopyCurrentEntity)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The bug creeps in because all entities in a rollback batch are treated as if they are part of the diff with the shouldCopyCurrentEntity flag.

This only makes a difference if

  1. The entity update was a new one (not in the diff but maybe a new event emitted after the reorg)
  2. Within the reorg threshold of the current reorg, a second reorg takes place, rolling back to the same block or before
  3. The entity then appears in the diff as if it should be deleted (so to the framework looks like it doesn't exist in the db)
  4. The handler has some conditional logic on the previous state of the entity (the conditional logic won't work as expected) OR the handler does not make any updates to the entity after the reorg in which case the entity would be unexpectedly deleted


fn aggregated_selection(cfg: &system_config::SystemConfig) -> Self {
let mut transaction_fields: HashSet<_> = cfg
let mut transaction_fields: BTreeSet<_> = cfg

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This had non deterministic ordering, just changed to a BTreeSet to keep ordering consistent.

Comment on lines +167 to +168
// For new entities, apply "containsRollbackDiffChange" from param
containsRollbackDiffChange,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We now keep track in the in memory store if the entity update contains changes from a rollback diff

| Set(entity) => Set(entity)
| Delete => Delete({id: entityId})
},
containsRollbackDiffChange,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The history row gets the "containsRollbackDiffChange" flag

@DZakh DZakh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice 💪

@DZakh
DZakh merged commit 1596b0c into main May 16, 2025
@DZakh
DZakh deleted the jp/fix-reorg-bug branch May 16, 2025 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants