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

Handle duplicate document view insertions #410

Merged
merged 5 commits into from
Jun 21, 2023

Conversation

sandreae
Copy link
Member

@sandreae sandreae commented Jun 20, 2023

Document views have a UNIQUE constraint on their document_view_id which means if double insertion of the same document view occurs then a fatal database error is returned. Although this is the expected behaviour, and there is no reason to want to update a document view (once inserted, no values on a document view should change), it can happen that a document is inserted twice because of two materializer tasks working towards the same document view (see issue and discussion here: #398).

This PR retains the UNIQUE restraint on document view id, and changes the behaviour of insert_document_view on SqlStore checks if a document view has already been materialized in the reduce task before performing any insertion.

Closes #398

📋 Checklist

  • Add tests that cover your changes
  • Add this PR to the Unreleased section in CHANGELOG.md
  • Link this PR to any issues it closes
  • New files contain a SPDX license header

@codecov
Copy link

codecov bot commented Jun 20, 2023

Codecov Report

Patch coverage: 95.00% and project coverage change: -0.02 ⚠️

Comparison is base (2e5a431) 90.32% compared to head (73d881a) 90.30%.

❗ Current head 73d881a differs from pull request most recent head 9590d98. Consider uploading reports for the commit 9590d98 to get more accurate results

Additional details and impacted files
@@               Coverage Diff               @@
##           development     #410      +/-   ##
===============================================
- Coverage        90.32%   90.30%   -0.02%     
===============================================
  Files               87       87              
  Lines             8203     8223      +20     
===============================================
+ Hits              7409     7426      +17     
- Misses             794      797       +3     
Impacted Files Coverage Δ
aquadoggo/src/materializer/tasks/reduce.rs 92.92% <95.00%> (+0.21%) ⬆️

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@adzialocha
Copy link
Member

adzialocha commented Jun 20, 2023

From our meeting today: We like handling the check on a higher level (inside the reduce task logic) better than on the lower level store methods. It's:

  1. Easier to read and follow what's going on (no hidden magic)
  2. Stricter, might help us to find more bugs in other places with our logic

That's especially useful if we're working with the inner parts of aquadoggo.

@sandreae sandreae marked this pull request as ready for review June 21, 2023 06:58
@sandreae
Copy link
Member Author

This is ready, but the ci is failing cos of a crazy compiler error.... don't think it's related to this PR.

@adzialocha adzialocha self-requested a review June 21, 2023 12:25
Copy link
Member

@adzialocha adzialocha left a comment

Choose a reason for hiding this comment

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

Great! I've removed the ON CONFLICT check in our SQL as well, since we handle the case in our code. Will merge now!

@adzialocha adzialocha merged commit e4be12a into development Jun 21, 2023
4 of 6 checks passed
@adzialocha adzialocha deleted the check-document-view-insertion branch June 21, 2023 12:26
adzialocha added a commit that referenced this pull request Jul 14, 2023
* development: (23 commits)
  Implement `dialer` behaviour (#444)
  Sort expected results in strategy tests
  Update CHANGELOG
  Replicate operations in topo order (#442)
  Maintain sorted operation indexes (#438)
  Use fork of `asynchronous-codec`  (#440)
  Ingest check for duplicate entries (#439)
  Reverse lookup for pinned relations in dependency task (#434)
  Remove unnecessary exact version pinning in Cargo.toml
  Make `TaskInput` an enum and other minor clean ups in materialiser (#429)
  Use `libp2p` `v0.52.0` (#425)
  Fix race condition when check for existing view ids was too early (#420)
  Reduce logging verbosity
  CI: Temporary workaround for Rust compiler bug (#417)
  Fix early document view insertion (#413)
  Handle duplicate document view insertions (#410)
  Decouple p2panda's authentication data types from libp2p's (#408)
  Remove dead_code attribute in lib
  Integrate replication manager with networking stack (#387)
  Implement naive replication protocol (#380)
  ...
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.

Double insertion of same view into document_views table during materialization
2 participants