Skip to content

Commit 8b6ba3e

Browse files
committed
refactor: get many reordering allowed
1 parent a470731 commit 8b6ba3e

4 files changed

Lines changed: 28 additions & 13 deletions

File tree

crates/storage/src/hot/mdbx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,11 @@ mod tests {
489489
{
490490
let reader: Tx<RO> = db.reader().unwrap();
491491
let addresses: Vec<Address> = accounts.iter().map(|(addr, _)| *addr).collect();
492-
let read_accounts: Vec<Option<Account>> =
492+
let read_accounts: Vec<(_, Option<Account>)> =
493493
reader.get_many::<hot::PlainAccountState, _>(addresses.iter()).unwrap();
494494

495495
for (i, (_, expected_account)) in accounts.iter().enumerate() {
496-
assert_eq!(read_accounts[i].as_ref(), Some(expected_account));
496+
assert_eq!(read_accounts[i].1.as_ref(), Some(expected_account));
497497
}
498498
}
499499
}

crates/storage/src/hot/mem.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,9 @@ mod tests {
581581
let values = reader.get_many::<TestTable, _>(keys).unwrap();
582582

583583
assert_eq!(values.len(), 3);
584-
assert_eq!(values[0], Some(Bytes::from_static(b"first")));
585-
assert_eq!(values[1], Some(Bytes::from_static(b"second")));
586-
assert_eq!(values[2], Some(Bytes::from_static(b"third")));
584+
assert_eq!(values[0], (&1u64, Some(Bytes::from_static(b"first"))));
585+
assert_eq!(values[1], (&2u64, Some(Bytes::from_static(b"second"))));
586+
assert_eq!(values[2], (&3u64, Some(Bytes::from_static(b"third"))));
587587
}
588588
}
589589

crates/storage/src/hot/revm.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ impl<U: HotKvRead> HotKvRead for RevmRead<U> {
6969
self.reader.get_dual::<T>(key1, key2)
7070
}
7171

72-
fn get_many<'a, T, I>(&self, keys: I) -> Result<Vec<Option<T::Value>>, Self::Error>
72+
fn get_many<'a, T, I>(
73+
&self,
74+
keys: I,
75+
) -> Result<Vec<(&'a T::Key, Option<T::Value>)>, Self::Error>
7376
where
7477
T::Key: 'a,
7578
T: Table,
@@ -138,7 +141,10 @@ impl<U: HotKvWrite> HotKvRead for RevmWrite<U> {
138141
self.writer.get_dual::<T>(key1, key2)
139142
}
140143

141-
fn get_many<'a, T, I>(&self, keys: I) -> Result<Vec<Option<T::Value>>, Self::Error>
144+
fn get_many<'a, T, I>(
145+
&self,
146+
keys: I,
147+
) -> Result<Vec<(&'a T::Key, Option<T::Value>)>, Self::Error>
142148
where
143149
T::Key: 'a,
144150
T: Table,

crates/storage/src/hot/traits.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,21 @@ pub trait HotKvRead {
125125
///
126126
/// # Returns
127127
///
128-
/// A vector of `Option<T::Value>`, where each element corresponds to the
129-
/// value for the respective key in the input iterator. If a key does not
130-
/// exist in the table, the corresponding element will be `None`.
128+
/// A vector of `(&'a T::Key, Option<T::Value>)`, where each element
129+
/// corresponds to the value for the respective key in the input iterator.
130+
/// If a key does not exist in the table, the corresponding element will be
131+
/// `None`.
132+
///
133+
/// Implementations ARE NOT required to preserve the order of the input
134+
/// keys in the output vector. Users should not rely on any specific
135+
/// ordering.
131136
///
132137
/// If any error occurs during retrieval or deserialization, the entire
133138
/// operation will return an error.
134-
fn get_many<'a, T, I>(&self, keys: I) -> Result<Vec<Option<T::Value>>, Self::Error>
139+
fn get_many<'a, T, I>(
140+
&self,
141+
keys: I,
142+
) -> Result<Vec<(&'a T::Key, Option<T::Value>)>, Self::Error>
135143
where
136144
T::Key: 'a,
137145
T: Table,
@@ -140,10 +148,11 @@ pub trait HotKvRead {
140148
let mut key_buf = [0u8; MAX_KEY_SIZE];
141149

142150
keys.into_iter()
143-
.map(|key| self.raw_get(T::NAME, key.encode_key(&mut key_buf)))
144-
.map(|maybe_val| {
151+
.map(|key| (key, self.raw_get(T::NAME, key.encode_key(&mut key_buf))))
152+
.map(|(key, maybe_val)| {
145153
maybe_val
146154
.and_then(|val| ValSer::maybe_decode_value(val.as_deref()).map_err(Into::into))
155+
.map(|res| (key, res))
147156
})
148157
.collect()
149158
}

0 commit comments

Comments
 (0)