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

Replicate entries and operations in their topologically sorted order #437

Closed
wants to merge 26 commits into from

Conversation

sandreae
Copy link
Member

@sandreae sandreae commented Jul 6, 2023

LogHeightStrategy sends entries and operations in their topologically sorted order and Ingest expects them to arrive in this way.

📋 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

Comment on lines 79 to +124
for (public_key, log_heights) in remote_needs {
for (log_id, seq_num) in log_heights {
let entry_messages: Vec<Message> = store
// Get the entries the remote needs for each log.
let log_entries = store
.get_entries_from(&public_key, &log_id, &seq_num)
.await
.expect("Fatal database error")
.iter()
.map(|entry| {
trace!(
"Prepare message containing entry at {:?} on {:?} for {}",
entry.seq_num(),
entry.log_id(),
entry.public_key().display()
);

Message::Entry(entry.clone().encoded_entry, entry.payload().cloned())
})
.collect();
messages.extend(entry_messages);
.expect("Fatal database error");

for entry in log_entries {
// Get the entry as well as we need some additional information in order to
// send the entries in the correct order.
let operation = store
.get_operation(&entry.hash().into())
.await
.expect("Fatal database error")
.expect("Operation should be in store");

// We only send entries if their operation has been materialized.
if let Some(sorted_index) = operation.sorted_index {
entries.push((entry, operation.document_id, sorted_index));
}
}
}
}

messages
// Sort all entries by document_id & sorted_index.
entries.sort_by(
|(_, document_id_a, sorted_index_a), (_, document_id_b, sorted_index_b)| {
(document_id_a, sorted_index_a).cmp(&(document_id_b, sorted_index_b))
},
);

// Compose the actual messages.
entries
.iter()
.map(|(entry, _, _)| {
trace!(
"Prepare message containing entry at {:?} on {:?} for {}",
entry.seq_num(),
entry.log_id(),
entry.public_key().display()
);

Message::Entry(entry.clone().encoded_entry, entry.payload().cloned())
})
.collect()
Copy link
Member Author

Choose a reason for hiding this comment

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

If all of this could be it's own SQL query that would be rather nice....

@codecov
Copy link

codecov bot commented Jul 6, 2023

Codecov Report

Patch coverage: 93.40% and project coverage change: +0.20 🎉

Comparison is base (ae27ff2) 90.05% compared to head (ac05928) 90.26%.

Additional details and impacted files
@@               Coverage Diff               @@
##           development     #437      +/-   ##
===============================================
+ Coverage        90.05%   90.26%   +0.20%     
===============================================
  Files               87       87              
  Lines             8439     8492      +53     
===============================================
+ Hits              7600     7665      +65     
+ Misses             839      827      -12     
Impacted Files Coverage Δ
aquadoggo/src/db/types/operation.rs 86.66% <ø> (ø)
aquadoggo/src/graphql/mutations/publish.rs 100.00% <ø> (ø)
aquadoggo/src/replication/strategies/log_height.rs 89.06% <83.33%> (+1.56%) ⬆️
aquadoggo/src/replication/manager.rs 88.97% <84.61%> (-0.27%) ⬇️
aquadoggo/src/db/stores/operation.rs 89.01% <90.76%> (+4.54%) ⬆️
aquadoggo/src/materializer/tasks/reduce.rs 90.07% <95.91%> (+1.28%) ⬆️
aquadoggo/src/db/models/utils.rs 99.46% <100.00%> (+0.01%) ⬆️
aquadoggo/src/replication/ingest.rs 96.96% <100.00%> (+12.03%) ⬆️
aquadoggo/src/replication/session.rs 86.66% <100.00%> (+1.85%) ⬆️

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

@sandreae
Copy link
Member Author

sandreae commented Jul 9, 2023

Closed as work was rebased over here: #442

@sandreae sandreae closed this Jul 9, 2023
@sandreae sandreae deleted the send-operations-in-order branch July 9, 2023 07:19
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.

1 participant