Skip to content

Commit 4cb600b

Browse files
derive inactivity floor from last commit, not range.start
1 parent 0d219c1 commit 4cb600b

2 files changed

Lines changed: 13 additions & 61 deletions

File tree

storage/src/qmdb/any/sync/mod.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::{
1313
self,
1414
any::{
1515
db::Db,
16+
operation::{update::Update, Operation},
1617
ordered::{
1718
fixed::{
1819
Db as OrderedFixedDb, Operation as OrderedFixedOp, Update as OrderedFixedUpdate,
@@ -34,12 +35,12 @@ use crate::{
3435
},
3536
FixedConfig, FixedValue, VariableConfig, VariableValue,
3637
},
37-
operation::{Committable, Key, Operation},
38+
operation::{Committable, Key},
3839
},
3940
translator::Translator,
40-
Context,
41+
Context, Persistable,
4142
};
42-
use commonware_codec::{CodecShared, Read as CodecRead};
43+
use commonware_codec::{Codec, CodecShared, Read as CodecRead};
4344
use commonware_cryptography::Hasher;
4445
use commonware_utils::{range::NonEmptyRange, Array};
4546

@@ -81,7 +82,7 @@ where
8182
}
8283

8384
/// Shared helper to build a [Db] from sync components.
84-
async fn build_db<F, E, O, I, H, U, C, T>(
85+
async fn build_db<F, E, U, I, H, C, T>(
8586
context: E,
8687
merkle_config: journaled::Config,
8788
log: C,
@@ -93,12 +94,12 @@ async fn build_db<F, E, O, I, H, U, C, T>(
9394
where
9495
F: merkle::Family,
9596
E: Context,
96-
O: Operation<F> + Committable + CodecShared + Send + Sync + 'static,
97+
U: Update + Send + Sync + 'static,
9798
I: IndexFactory<T, Value = Location<F>>,
9899
H: Hasher,
99-
U: Send + Sync + 'static,
100100
T: Translator,
101-
C: Mutable<Item = O>,
101+
C: Mutable<Item = Operation<F, U>> + Persistable<Error = crate::journal::Error>,
102+
Operation<F, U>: Codec + Committable + CodecShared,
102103
{
103104
let hasher = StandardHasher::<H>::new();
104105

@@ -122,7 +123,7 @@ where
122123
apply_batch_size as u64,
123124
)
124125
.await?;
125-
let db = Db::from_components(range.start(), log, index).await?;
126+
let db = Db::init_from_log(index, log, Some(range.start()), |_, _| {}).await?;
126127

127128
Ok(db)
128129
}
@@ -160,7 +161,7 @@ macro_rules! impl_sync_database {
160161
) -> Result<Self, qmdb::Error<F>> {
161162
let merkle_config = config.merkle_config.clone();
162163
let translator = config.translator.clone();
163-
build_db::<F, _, Self::Op, _, H, $update<K, V>, _, T>(
164+
build_db::<F, _, $update<K, V>, _, H, _, T>(
164165
context,
165166
merkle_config,
166167
log,

storage/src/qmdb/any/unordered/mod.rs

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
use crate::qmdb::any::traits::PersistableMutableLog;
33
use crate::{
44
index::Unordered as Index,
5-
journal::contiguous::{Contiguous, Mutable, Reader},
5+
journal::contiguous::{Contiguous, Reader},
66
merkle::{Family, Location},
77
qmdb::{
8-
any::{
9-
db::{AuthenticatedLog, Db},
10-
ValueEncoding,
11-
},
12-
build_snapshot_from_log,
13-
operation::{Committable, Key, Operation as OperationTrait},
8+
any::{db::Db, ValueEncoding},
9+
operation::Key,
1410
},
1511
Context,
1612
};
@@ -59,51 +55,6 @@ where
5955
}
6056
}
6157

62-
impl<
63-
F: Family,
64-
E: Context,
65-
C: Mutable<Item = O>,
66-
O: OperationTrait<F> + Codec + Committable + Send + Sync,
67-
I: Index<Value = Location<F>>,
68-
H: Hasher,
69-
U: Send + Sync,
70-
> Db<F, E, C, I, H, U>
71-
{
72-
/// Returns an [Db] initialized directly from the given components. The log is
73-
/// replayed from `inactivity_floor_loc` to build the snapshot, and that value is used as the
74-
/// inactivity floor. The last operation is assumed to be a commit.
75-
pub(crate) async fn from_components(
76-
inactivity_floor_loc: Location<F>,
77-
log: AuthenticatedLog<F, E, C, H>,
78-
mut snapshot: I,
79-
) -> Result<Self, crate::qmdb::Error<F>> {
80-
let (active_keys, last_commit_loc) = {
81-
let reader = log.reader().await;
82-
let active_keys =
83-
build_snapshot_from_log(inactivity_floor_loc, &reader, &mut snapshot, |_, _| {})
84-
.await?;
85-
let last_commit_loc = Location::new(
86-
reader
87-
.bounds()
88-
.end
89-
.checked_sub(1)
90-
.expect("commit should exist"),
91-
);
92-
assert!(reader.read(*last_commit_loc).await?.is_commit());
93-
(active_keys, last_commit_loc)
94-
};
95-
96-
Ok(Self {
97-
log,
98-
inactivity_floor_loc,
99-
snapshot,
100-
last_commit_loc,
101-
active_keys,
102-
_update: core::marker::PhantomData,
103-
})
104-
}
105-
}
106-
10758
#[cfg(any(test, feature = "test-traits"))]
10859
crate::qmdb::any::traits::impl_db_any! {
10960
[E, K, V, C, I, H] Db<crate::merkle::mmr::Family, E, C, I, H, Update<K, V>>

0 commit comments

Comments
 (0)