Skip to content

Commit 88f6634

Browse files
committed
api consistency updates
1 parent e8c8d36 commit 88f6634

4 files changed

Lines changed: 65 additions & 28 deletions

File tree

glue/src/stateful/db/any.rs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,7 @@ use commonware_storage::{
3737
translator::Translator,
3838
Persistable,
3939
};
40-
use commonware_utils::{
41-
channel::mpsc,
42-
non_empty_range,
43-
sync::{AsyncRwLock, AsyncRwLockReadGuard},
44-
Array,
45-
};
40+
use commonware_utils::{channel::mpsc, non_empty_range, sync::AsyncRwLock, Array};
4641
use std::{ops::Deref, sync::Arc};
4742

4843
type AnyDbHandle<F, E, C, I, H, U> = Arc<AsyncRwLock<Db<F, E, C, I, H, U>>>;
@@ -84,25 +79,13 @@ where
8479
self
8580
}
8681

87-
/// Acquire a read lock on the DB.
88-
pub async fn lock(
89-
&self,
90-
) -> AsyncRwLockReadGuard<'_, Db<F, E, C, I, H, unordered::Update<K, V>>> {
91-
self.db.read().await
92-
}
93-
94-
/// Get a reference to the inner batch.
95-
pub const fn batch(&self) -> &UnmerkleizedBatch<F, H, unordered::Update<K, V>> {
96-
&self.batch
97-
}
98-
9982
/// Read a value by key, falling back to committed state.
10083
pub async fn get(&self, key: &K) -> Result<Option<V::Value>, Error<F>> {
10184
let db = self.db.read().await;
10285
self.batch.get(key, &*db).await
10386
}
10487

105-
/// Read multiple values by key, amortizing lock acquisition and journal I/O.
88+
/// Read multiple values by key, falling back to committed state.
10689
///
10790
/// Returns results in the same order as the input keys.
10891
pub async fn get_many(&self, keys: &[&K]) -> Result<Vec<Option<V::Value>>, Error<F>> {
@@ -186,7 +169,7 @@ where
186169
self.batch.get(key, &*db).await
187170
}
188171

189-
/// Read multiple values by key, amortizing lock acquisition and journal I/O.
172+
/// Read multiple values by key, falling back to committed state.
190173
///
191174
/// Returns results in the same order as the input keys.
192175
pub async fn get_many(&self, keys: &[&K]) -> Result<Vec<Option<V::Value>>, Error<F>> {
@@ -201,6 +184,32 @@ where
201184
}
202185
}
203186

187+
/// Read-through operations for the `any` merkleized batch.
188+
impl<F, E, C, I, H, U> AnyMerkleized<F, E, C, I, H, U>
189+
where
190+
F: Family,
191+
E: Storage + Clock + Metrics,
192+
U: Update,
193+
C: Contiguous<Item = Operation<F, U>>,
194+
I: UnorderedIndex<Value = Location<F>> + 'static,
195+
H: Hasher,
196+
Operation<F, U>: Codec,
197+
{
198+
/// Read a value by key, falling back to committed state.
199+
pub async fn get(&self, key: &U::Key) -> Result<Option<U::Value>, Error<F>> {
200+
let db = self.db.read().await;
201+
self.inner.get(key, &*db).await
202+
}
203+
204+
/// Read multiple values by key, falling back to committed state.
205+
///
206+
/// Returns results in the same order as the input keys.
207+
pub async fn get_many(&self, keys: &[&U::Key]) -> Result<Vec<Option<U::Value>>, Error<F>> {
208+
let db = self.db.read().await;
209+
self.inner.get_many(keys, &*db).await
210+
}
211+
}
212+
204213
/// Implement [`Unmerkleized`](UnmerkleizedTrait) for the `any` unordered update kind.
205214
impl<F, E, C, I, H, K, V> UnmerkleizedTrait
206215
for AnyUnmerkleized<F, E, C, I, H, unordered::Update<K, V>>

glue/src/stateful/db/current.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ where
8888
self.batch.get(key, &*db).await
8989
}
9090

91-
/// Read multiple values by key, amortizing lock acquisition and journal I/O.
91+
/// Read multiple values by key, falling back to committed state.
9292
///
9393
/// Returns results in the same order as the input keys.
9494
pub async fn get_many(&self, keys: &[&K]) -> Result<Vec<Option<V::Value>>, Error<F>> {
@@ -173,7 +173,7 @@ where
173173
self.batch.get(key, &*db).await
174174
}
175175

176-
/// Read multiple values by key, amortizing lock acquisition and journal I/O.
176+
/// Read multiple values by key, falling back to committed state.
177177
///
178178
/// Returns results in the same order as the input keys.
179179
pub async fn get_many(&self, keys: &[&K]) -> Result<Vec<Option<V::Value>>, Error<F>> {
@@ -188,6 +188,32 @@ where
188188
}
189189
}
190190

191+
/// Read-through operations for the `current` merkleized batch.
192+
impl<F, E, C, I, H, U, const N: usize> CurrentMerkleized<F, E, C, I, H, U, N>
193+
where
194+
F: Graftable,
195+
E: Storage + Clock + Metrics,
196+
U: Update,
197+
C: Contiguous<Item = Operation<F, U>>,
198+
I: UnorderedIndex<Value = Location<F>> + 'static,
199+
H: Hasher,
200+
Operation<F, U>: Codec,
201+
{
202+
/// Read a value by key, falling back to committed state.
203+
pub async fn get(&self, key: &U::Key) -> Result<Option<U::Value>, Error<F>> {
204+
let db = self.db.read().await;
205+
self.inner.get(key, &*db).await
206+
}
207+
208+
/// Read multiple values by key, falling back to committed state.
209+
///
210+
/// Returns results in the same order as the input keys.
211+
pub async fn get_many(&self, keys: &[&U::Key]) -> Result<Vec<Option<U::Value>>, Error<F>> {
212+
let db = self.db.read().await;
213+
self.inner.get_many(keys, &*db).await
214+
}
215+
}
216+
191217
/// Implement [`Unmerkleized`](UnmerkleizedTrait) for the `current` unordered update kind.
192218
impl<F, E, C, I, H, K, V, const N: usize> UnmerkleizedTrait
193219
for CurrentUnmerkleized<F, E, C, I, H, unordered::Update<K, V>, N>

glue/src/stateful/db/immutable.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ where
107107
self.batch.get(key, &*db).await
108108
}
109109

110-
/// Read multiple values by key, amortizing lock acquisition and journal I/O.
110+
/// Read multiple values by key, falling back to committed state.
111111
///
112112
/// Returns results in the same order as the input keys.
113113
pub async fn get_many(&self, keys: &[&K]) -> Result<Vec<Option<V::Value>>, Error<F>> {
@@ -174,7 +174,7 @@ where
174174
self.inner.get(key, &*db).await
175175
}
176176

177-
/// Read multiple values by key, amortizing lock acquisition and journal I/O.
177+
/// Read multiple values by key, falling back to committed state.
178178
///
179179
/// Returns results in the same order as the input keys.
180180
pub async fn get_many(&self, keys: &[&K]) -> Result<Vec<Option<V::Value>>, Error<F>> {

glue/src/stateful/db/keyless.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ where
100100
self.batch.get(location, &*db).await
101101
}
102102

103-
/// Read values at multiple locations, amortizing lock acquisition.
103+
/// Read multiple values by location, falling back to committed state.
104104
///
105-
/// Locations must be sorted in ascending order.
105+
/// Locations must be sorted in ascending order. Returns results in the same
106+
/// order as the input locations.
106107
pub async fn get_many(
107108
&self,
108109
locations: &[Location<F>],
@@ -164,9 +165,10 @@ where
164165
self.inner.get(location, &*db).await
165166
}
166167

167-
/// Read values at multiple locations, amortizing lock acquisition.
168+
/// Read multiple values by location, falling back to committed state.
168169
///
169-
/// Locations must be sorted in ascending order.
170+
/// Locations must be sorted in ascending order. Returns results in the same
171+
/// order as the input locations.
170172
pub async fn get_many(
171173
&self,
172174
locations: &[Location<F>],

0 commit comments

Comments
 (0)