Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@danlaine
Copy link
Collaborator

@danlaine danlaine commented Aug 1, 2025

This PR:

  • Factors out the Any sync client and its associated types into adb::sync, and adapts the types to be generic over a Syncable database trait.
  • Implements Syncable for adb::Immutable.
  • Adapts the sync/example to be able to run with either a fixed::Any or adb::Immutable database.
  • Updates the sync/example architecture and adds structure to the crate.

@patrick-ogrady patrick-ogrady added this to the v0.0.58 milestone Aug 12, 2025
/// - No section index < `lower_bound / items_per_section` exists.
/// - No section index > `upper_bound / items_per_section` exists.
/// - The last retained section is truncated so that its last item’s location is `<= upper_bound`.
pub(crate) async fn init_sync(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know we did this already with fixed journal, but wondering if this sync-client-specific code should be outside the core journal module. It seems more application specific?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fair point.

I moved the fixed journal's init_sync and helpers to adb/any/fixed/sync.rs and made them functions rather than methods.

For the variable journal, I moved them to adb/any/variable/sync.rs. I'm not sure this is the right place because:

  1. Sync isn't yet implemented for any::variable::Any yet
  2. These functions are used by any::Immutable

but I'm not immediately sure where a better place to put this code would be.

More generally, I'd like to hear others' thoughts on how we should organize the sync-related code. As it stands, there are sync modules for any::fixed, any::variable, any::immutable. An alternative would be to consolidate all sync-related implementations for these types in one place/module.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Or perhaps I misunderstood your original comment, @roberto-bayardo, and you had in mind a sync module at storage/src/journal/variable/sync.rs?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Feels more like it belongs in adb somewhere since that's what we're syncing, but if a "syncable journal" is generic enough to be independent of adb, then I guess it could go in journal/ ?

@patrick-ogrady patrick-ogrady modified the milestones: v0.0.58, v0.0.59 Aug 12, 2025
Copy link
Contributor

@patrick-ogrady patrick-ogrady left a comment

Choose a reason for hiding this comment

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

🤌

use crate::adb::sync::engine::Config;
use commonware_codec::Encode;

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we don't do this \n elsewhere in the codebase but I do find it clearer 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Your call. As you say, it's somewhat easier to read at the cost of being inconsistent with mod.rs files.

/// - Reuse any on-disk data whose logical locations lie within [lower_bound, upper_bound].
/// - Discard/ignore any data strictly below `lower_bound` and strictly above `upper_bound`.
/// - Report `size()` equal to the next location to be filled.
fn create_journal(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I wonder if we should just do create and resize?

I don't think the caller here needs to know/care if it is journal (and/or that is implicit from the types)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the _journal suffix makes sense. Otherwise, when you look at the pub trait Database and see create, you might assume that it creates a database when actually it creates a journal. Of course, the comment and return type tell you that it's not. But still, I think the extra verbosity is warranted in this case to avoid:

let journal = DB::create() // Feels like this should return a db?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how this database/journal trait will evolve and I'm ok to keep as-is for now (until the other adbs are supported).

@patrick-ogrady patrick-ogrady merged commit 7fb95a7 into main Aug 13, 2025
35 checks passed
@patrick-ogrady patrick-ogrady deleted the danlaine/sync-factor branch August 13, 2025 20:50
@codecov
Copy link

codecov bot commented Aug 13, 2025

Codecov Report

❌ Patch coverage is 96.73147% with 116 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.69%. Comparing base (e924dee) to head (07899fe).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
storage/src/adb/sync/resolver.rs 56.25% 35 Missing ⚠️
storage/src/adb/sync/engine.rs 91.24% 24 Missing ⚠️
storage/src/adb/any/fixed/sync.rs 98.77% 18 Missing ⚠️
storage/src/adb/immutable/sync/mod.rs 98.19% 14 Missing ⚠️
storage/src/adb/any/variable/sync.rs 98.83% 7 Missing ⚠️
storage/src/adb/sync/error.rs 0.00% 6 Missing ⚠️
storage/src/adb/sync/target.rs 93.75% 5 Missing ⚠️
storage/src/adb/sync/requests.rs 90.32% 3 Missing ⚠️
storage/src/journal/mod.rs 66.66% 3 Missing ⚠️
storage/src/adb/sync/gaps.rs 98.55% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main    #1341      +/-   ##
==========================================
+ Coverage   91.56%   91.69%   +0.13%     
==========================================
  Files         266      275       +9     
  Lines       67545    68964    +1419     
==========================================
+ Hits        61846    63239    +1393     
- Misses       5699     5725      +26     
Files with missing lines Coverage Δ
storage/src/adb/any/fixed/mod.rs 98.54% <100.00%> (ø)
storage/src/adb/any/variable/mod.rs 95.57% <100.00%> (ø)
storage/src/adb/current.rs 96.84% <ø> (ø)
storage/src/adb/immutable/mod.rs 96.96% <100.00%> (ø)
storage/src/adb/immutable/sync/journal.rs 100.00% <100.00%> (ø)
storage/src/adb/sync/mod.rs 100.00% <100.00%> (ø)
storage/src/adb/verify.rs 100.00% <100.00%> (ø)
storage/src/journal/fixed.rs 97.60% <ø> (-0.18%) ⬇️
storage/src/journal/variable.rs 94.66% <100.00%> (+0.44%) ⬆️
storage/src/mmr/journaled.rs 98.65% <100.00%> (ø)
... and 11 more

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e924dee...07899fe. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

4 participants