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

Fix early document view insertion #413

Merged
merged 10 commits into from
Jun 21, 2023

Conversation

sandreae
Copy link
Member

@sandreae sandreae commented Jun 21, 2023

Solution for #407 which implements checking a document has been materialized in a reduce task before inserting a document view into the store. If the document does not exist yet, the task is re-issued, assuming that the document reduce task is already in the queue somewhere.

For safety, and for assisting in identifying potential future bugs, I also introduced a foreign relation constraint onto the document_id column in document_views table. We don't rely on this being hit in our code though.

📋 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

@sandreae sandreae marked this pull request as draft June 21, 2023 01:17
@sandreae
Copy link
Member Author

sandreae commented Jun 21, 2023

This is compiling (cargo build & cargo run) and seems to fix the issue, but when I run cargo test locally i get this fairly awesome error:

➜  aquadoggo git:(fix-early-document-view-insertion) cargo test
   Compiling aquadoggo v0.4.0 (/home/sandreae/Code/aquadoggo/aquadoggo)
   Compiling aquadoggo_cli v0.2.0 (/home/sandreae/Code/aquadoggo/aquadoggo_cli)
thread 'rustc' panicked at 'forcing query with already existing `DepNode`
- query-key: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All, constness: NotConst }, value: [closure@aquadoggo/src/materializer/tasks/dependency.rs:334:21: 334:42] }
- dep-node: layout_of(c7b17c32ceccf64a-de29268184dcb812)', /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/compiler/rustc_query_system/src/dep_graph/graph.rs:319:9
stack backtrace:
   0:     0x7f25269d831a - std::backtrace_rs::backtrace::libunwind::trace::ha9053a9a07ca49cb
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f25269d831a - std::backtrace_rs::backtrace::trace_unsynchronized::h9c2852a457ad564e
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f25269d831a - std::sys_common::backtrace::_print_fmt::h457936fbfaa0070f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f25269d831a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5779d7bf7f70cb0c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f2526a3bb6e - core::fmt::write::h5a4baaff1bcd3eb5
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/fmt/mod.rs:1232:17
   5:     0x7f25269cb2c5 - std::io::Write::write_fmt::h4bc1f301cb9e9cce
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/io/mod.rs:1684:15
   6:     0x7f25269d80e5 - std::sys_common::backtrace::_print::h5fcdc36060f177e8
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f25269d80e5 - std::sys_common::backtrace::print::h54ca9458b876c8bf
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f25269dae5f - std::panicking::default_hook::{{closure}}::hbe471161c7664ed6
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:271:22
   9:     0x7f25269dab9b - std::panicking::default_hook::ha3500da57aa4ac4f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:290:9
  10:     0x7f2529c3c8b5 - <rustc_driver_impl[fb92b3e21ac03dce]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[911a585bea10363d]::ops::function::FnOnce<(&core[911a585bea10363d]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7f25269db69d - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h6507bddc3eebb4a5
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/boxed.rs:2001:9
  12:     0x7f25269db69d - std::panicking::rust_panic_with_hook::h50c09d000dc561d2
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:696:13
  13:     0x7f25269db419 - std::panicking::begin_panic_handler::{{closure}}::h9e2b2176e00e0d9c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:583:13
  14:     0x7f25269d8786 - std::sys_common::backtrace::__rust_end_short_backtrace::h5739b8e512c09d02
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:150:18
  15:     0x7f25269db122 - rust_begin_unwind
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:579:5
  16:     0x7f2526a37ec3 - core::panicking::panic_fmt::hf33a1475b4dc5c3e
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14
  17:     0x7f25284efdf0 - rustc_query_system[caf472e4bac2b2b6]::query::plumbing::try_execute_query::<rustc_query_impl[a4bd04fc7a0236b8]::queries::layout_of, rustc_query_impl[a4bd04fc7a0236b8]::plumbing::QueryCtxt>
  18:     0x7f2528798d6a - <rustc_mir_transform[78e1eecd28eacd11]::const_prop::CanConstProp>::check
  19:     0x7f252878caa4 - <rustc_mir_transform[78e1eecd28eacd11]::const_prop_lint::ConstProp as rustc_mir_transform[78e1eecd28eacd11]::pass_manager::MirLint>::run_lint
  20:     0x7f2528777908 - rustc_mir_transform[78e1eecd28eacd11]::run_analysis_to_runtime_passes
  21:     0x7f252877687c - rustc_mir_transform[78e1eecd28eacd11]::mir_drops_elaborated_and_const_checked
  22:     0x7f25287752e6 - rustc_query_system[caf472e4bac2b2b6]::query::plumbing::try_execute_query::<rustc_query_impl[a4bd04fc7a0236b8]::queries::mir_drops_elaborated_and_const_checked, rustc_query_impl[a4bd04fc7a0236b8]::plumbing::QueryCtxt>
  23:     0x7f2529006a06 - rustc_mir_transform[78e1eecd28eacd11]::optimized_mir
  24:     0x7f25290053a4 - rustc_query_system[caf472e4bac2b2b6]::query::plumbing::try_execute_query::<rustc_query_impl[a4bd04fc7a0236b8]::queries::optimized_mir, rustc_query_impl[a4bd04fc7a0236b8]::plumbing::QueryCtxt>
  25:     0x7f2528a761ba - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_neighbours
  26:     0x7f2528a7331a - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  27:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  28:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  29:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  30:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  31:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  32:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  33:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  34:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  35:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  36:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  37:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  38:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  39:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  40:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  41:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  42:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  43:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  44:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  45:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  46:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  47:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  48:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  49:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  50:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  51:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  52:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  53:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  54:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  55:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  56:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  57:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  58:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  59:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  60:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  61:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  62:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  63:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  64:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  65:     0x7f2528a737c8 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_items_rec
  66:     0x7f25291bca7a - rustc_data_structures[a232da6b1231993b]::sync::par_for_each_in::<alloc[37f5578e48c4c353]::vec::Vec<rustc_middle[1a4ce3311a146f18]::mir::mono::MonoItem>, rustc_monomorphize[d198b8cd951ecf39]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>
  67:     0x7f25291bc711 - <rustc_session[b87ece769e9b9511]::session::Session>::time::<(), rustc_monomorphize[d198b8cd951ecf39]::collector::collect_crate_mono_items::{closure#1}>
  68:     0x7f25291bc304 - rustc_monomorphize[d198b8cd951ecf39]::collector::collect_crate_mono_items
  69:     0x7f25291ba3e2 - rustc_monomorphize[d198b8cd951ecf39]::partitioning::collect_and_partition_mono_items
  70:     0x7f25294a3b24 - rustc_query_system[caf472e4bac2b2b6]::query::plumbing::try_execute_query::<rustc_query_impl[a4bd04fc7a0236b8]::queries::collect_and_partition_mono_items, rustc_query_impl[a4bd04fc7a0236b8]::plumbing::QueryCtxt>
  71:     0x7f25294a354c - <rustc_query_impl[a4bd04fc7a0236b8]::Queries as rustc_middle[1a4ce3311a146f18]::ty::query::QueryEngine>::collect_and_partition_mono_items
  72:     0x7f252937506d - rustc_codegen_ssa[c1007917fa8b1cdc]::base::codegen_crate::<rustc_codegen_llvm[f4d32c07c99f5d2]::LlvmCodegenBackend>
  73:     0x7f2529374e51 - <rustc_codegen_llvm[f4d32c07c99f5d2]::LlvmCodegenBackend as rustc_codegen_ssa[c1007917fa8b1cdc]::traits::backend::CodegenBackend>::codegen_crate
  74:     0x7f2528e95991 - <rustc_session[b87ece769e9b9511]::session::Session>::time::<alloc[37f5578e48c4c353]::boxed::Box<dyn core[911a585bea10363d]::any::Any>, rustc_interface[bd8390756bd7a52a]::passes::start_codegen::{closure#0}>
  75:     0x7f2528e954d9 - rustc_interface[bd8390756bd7a52a]::passes::start_codegen
  76:     0x7f2528e91208 - <rustc_middle[1a4ce3311a146f18]::ty::context::GlobalCtxt>::enter::<<rustc_interface[bd8390756bd7a52a]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[911a585bea10363d]::result::Result<alloc[37f5578e48c4c353]::boxed::Box<dyn core[911a585bea10363d]::any::Any>, rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>>
  77:     0x7f2528e8efb8 - <rustc_interface[bd8390756bd7a52a]::queries::Queries>::ongoing_codegen
  78:     0x7f2528e8dd6c - rustc_span[fab0eb11f1fed58d]::with_source_map::<core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>, rustc_interface[bd8390756bd7a52a]::interface::run_compiler<core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>, rustc_driver_impl[fb92b3e21ac03dce]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  79:     0x7f2528e853cc - std[685882fd5f6d52e5]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[bd8390756bd7a52a]::util::run_in_thread_pool_with_globals<rustc_interface[bd8390756bd7a52a]::interface::run_compiler<core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>, rustc_driver_impl[fb92b3e21ac03dce]::run_compiler::{closure#1}>::{closure#0}, core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>>
  80:     0x7f2528e84dfa - <<std[685882fd5f6d52e5]::thread::Builder>::spawn_unchecked_<rustc_interface[bd8390756bd7a52a]::util::run_in_thread_pool_with_globals<rustc_interface[bd8390756bd7a52a]::interface::run_compiler<core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>, rustc_driver_impl[fb92b3e21ac03dce]::run_compiler::{closure#1}>::{closure#0}, core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>>::{closure#1} as core[911a585bea10363d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  81:     0x7f25269e5593 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h39990b24eedef2ab
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/boxed.rs:1987:9
  82:     0x7f25269e5593 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h01a027258444143b
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/boxed.rs:1987:9
  83:     0x7f25269e5593 - std::sys::unix::thread::Thread::new::thread_start::ha4f1cdd9c25884ba
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys/unix/thread.rs:108:17
  84:     0x7f252688f609 - start_thread
                               at /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477:8
  85:     0x7f25267b2133 - clone
                               at /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  86:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.69.0 (84c898d65 2023-04-16) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [layout_of] computing layout of `[closure@aquadoggo/src/materializer/tasks/dependency.rs:334:21: 334:42]`
#1 [mir_drops_elaborated_and_const_checked] elaborating drops for `materializer::tasks::dependency::tests::dispatches_reduce_tasks_for_pinned_child_dependencies::{closure#0}`
#2 [optimized_mir] optimizing MIR for `materializer::tasks::dependency::tests::dispatches_reduce_tasks_for_pinned_child_dependencies::{closure#0}`
#3 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `aquadoggo`

@sandreae
Copy link
Member Author

Updating to rustc 1.70.0 from rustc 1.69.0 fixed it. Was fun to see in any case.

@codecov
Copy link

codecov bot commented Jun 21, 2023

Codecov Report

Patch coverage: 86.48% and project coverage change: -0.07 ⚠️

Comparison is base (2e5a431) 90.32% compared to head (6bccaf5) 90.25%.

❗ Current head 6bccaf5 differs from pull request most recent head 85ddf8c. Consider uploading reports for the commit 85ddf8c to get more accurate results

Additional details and impacted files
@@               Coverage Diff               @@
##           development     #413      +/-   ##
===============================================
- Coverage        90.32%   90.25%   -0.07%     
===============================================
  Files               87       87              
  Lines             8203     8228      +25     
===============================================
+ Hits              7409     7426      +17     
- Misses             794      802       +8     
Impacted Files Coverage Δ
aquadoggo/src/materializer/tasks/reduce.rs 91.24% <86.48%> (-1.47%) ⬇️

... and 3 files 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.

@sandreae sandreae linked an issue Jun 21, 2023 that may be closed by this pull request
@sandreae sandreae marked this pull request as ready for review June 21, 2023 03:02
@adzialocha adzialocha self-requested a review June 21, 2023 12:31
@adzialocha adzialocha merged commit 2dcfa9d into development Jun 21, 2023
@adzialocha adzialocha deleted the fix-early-document-view-insertion branch June 21, 2023 12:31
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.

Document view inserted before document is materialized
2 participants