mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-12-22 03:29:25 +00:00
Storage: remove get_range
(#359)
Some checks failed
CI / fmt (push) Has been cancelled
CI / typo (push) Has been cancelled
CI / ci (macos-latest, stable, bash) (push) Has been cancelled
CI / ci (ubuntu-latest, stable, bash) (push) Has been cancelled
CI / ci (windows-latest, stable-x86_64-pc-windows-gnu, msys2 {0}) (push) Has been cancelled
Deny / audit (push) Has been cancelled
Doc / build (push) Has been cancelled
Doc / deploy (push) Has been cancelled
Some checks failed
CI / fmt (push) Has been cancelled
CI / typo (push) Has been cancelled
CI / ci (macos-latest, stable, bash) (push) Has been cancelled
CI / ci (ubuntu-latest, stable, bash) (push) Has been cancelled
CI / ci (windows-latest, stable-x86_64-pc-windows-gnu, msys2 {0}) (push) Has been cancelled
Deny / audit (push) Has been cancelled
Doc / build (push) Has been cancelled
Doc / deploy (push) Has been cancelled
* remove `get_range` * change usages of `get_range` * clippy * cargo update * fix test + update comment
This commit is contained in:
parent
7b8756fa80
commit
80369b82d2
7 changed files with 506 additions and 318 deletions
770
Cargo.lock
generated
770
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -9,7 +9,7 @@ use monero_serai::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use cuprate_database::{
|
use cuprate_database::{
|
||||||
DbResult, RuntimeError, StorableVec, {DatabaseIter, DatabaseRo, DatabaseRw},
|
DbResult, RuntimeError, StorableVec, {DatabaseRo, DatabaseRw},
|
||||||
};
|
};
|
||||||
use cuprate_helper::cast::usize_to_u64;
|
use cuprate_helper::cast::usize_to_u64;
|
||||||
use cuprate_helper::{
|
use cuprate_helper::{
|
||||||
|
@ -268,10 +268,12 @@ pub fn get_block_complete_entry(
|
||||||
|
|
||||||
let first_tx_idx = miner_tx_idx + 1;
|
let first_tx_idx = miner_tx_idx + 1;
|
||||||
|
|
||||||
let tx_blobs = tables
|
let tx_blobs = (first_tx_idx..(usize_to_u64(numb_non_miner_txs) + first_tx_idx))
|
||||||
.tx_blobs_iter()
|
.map(|idx| {
|
||||||
.get_range(first_tx_idx..(usize_to_u64(numb_non_miner_txs) + first_tx_idx))?
|
let tx_blob = tables.tx_blobs().get(&idx)?.0;
|
||||||
.map(|tx_blob| Ok(Bytes::from(tx_blob?.0)))
|
|
||||||
|
Ok(Bytes::from(tx_blob))
|
||||||
|
})
|
||||||
.collect::<Result<_, RuntimeError>>()?;
|
.collect::<Result<_, RuntimeError>>()?;
|
||||||
|
|
||||||
Ok(BlockCompleteEntry {
|
Ok(BlockCompleteEntry {
|
||||||
|
|
|
@ -22,9 +22,7 @@ use rayon::{
|
||||||
};
|
};
|
||||||
use thread_local::ThreadLocal;
|
use thread_local::ThreadLocal;
|
||||||
|
|
||||||
use cuprate_database::{
|
use cuprate_database::{ConcreteEnv, DatabaseRo, DbResult, Env, EnvInner, RuntimeError};
|
||||||
ConcreteEnv, DatabaseIter, DatabaseRo, DbResult, Env, EnvInner, RuntimeError,
|
|
||||||
};
|
|
||||||
use cuprate_database_service::{init_thread_pool, DatabaseReadService, ReaderThreads};
|
use cuprate_database_service::{init_thread_pool, DatabaseReadService, ReaderThreads};
|
||||||
use cuprate_helper::map::combine_low_high_bits_to_u128;
|
use cuprate_helper::map::combine_low_high_bits_to_u128;
|
||||||
use cuprate_types::{
|
use cuprate_types::{
|
||||||
|
@ -616,10 +614,9 @@ fn next_chain_entry(
|
||||||
let chain_height = crate::ops::blockchain::chain_height(table_block_heights)?;
|
let chain_height = crate::ops::blockchain::chain_height(table_block_heights)?;
|
||||||
let last_height_in_chain_entry = min(first_known_height + next_entry_size, chain_height);
|
let last_height_in_chain_entry = min(first_known_height + next_entry_size, chain_height);
|
||||||
|
|
||||||
let (block_ids, block_weights) = table_block_infos
|
let (block_ids, block_weights) = (first_known_height..last_height_in_chain_entry)
|
||||||
.get_range(first_known_height..last_height_in_chain_entry)?
|
.map(|height| {
|
||||||
.map(|block_info| {
|
let block_info = table_block_infos.get(&height)?;
|
||||||
let block_info = block_info?;
|
|
||||||
|
|
||||||
Ok((block_info.block_hash, block_info.weight))
|
Ok((block_info.block_hash, block_info.weight))
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Implementation of `trait Database` for `heed`.
|
//! Implementation of `trait Database` for `heed`.
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Import
|
//---------------------------------------------------------------------------------------------------- Import
|
||||||
use std::{cell::RefCell, ops::RangeBounds};
|
use std::cell::RefCell;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::heed::types::HeedDb,
|
backend::heed::types::HeedDb,
|
||||||
|
@ -90,6 +90,7 @@ fn is_empty<T: Table>(db: &HeedDb<T::Key, T::Value>, tx_ro: &heed::RoTxn<'_>) ->
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- DatabaseIter Impl
|
//---------------------------------------------------------------------------------------------------- DatabaseIter Impl
|
||||||
impl<T: Table> DatabaseIter<T> for HeedTableRo<'_, T> {
|
impl<T: Table> DatabaseIter<T> for HeedTableRo<'_, T> {
|
||||||
|
/*
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_range<'a, Range>(
|
fn get_range<'a, Range>(
|
||||||
&'a self,
|
&'a self,
|
||||||
|
@ -101,6 +102,8 @@ impl<T: Table> DatabaseIter<T> for HeedTableRo<'_, T> {
|
||||||
Ok(self.db.range(self.tx_ro, &range)?.map(|res| Ok(res?.1)))
|
Ok(self.db.range(self.tx_ro, &range)?.map(|res| Ok(res?.1)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn iter(&self) -> DbResult<impl Iterator<Item = DbResult<(T::Key, T::Value)>> + '_> {
|
fn iter(&self) -> DbResult<impl Iterator<Item = DbResult<(T::Key, T::Value)>> + '_> {
|
||||||
Ok(self.db.iter(self.tx_ro)?.map(|res| Ok(res?)))
|
Ok(self.db.iter(self.tx_ro)?.map(|res| Ok(res?)))
|
||||||
|
|
|
@ -65,6 +65,7 @@ fn is_empty<T: Table>(
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- DatabaseIter
|
//---------------------------------------------------------------------------------------------------- DatabaseIter
|
||||||
impl<T: Table + 'static> DatabaseIter<T> for RedbTableRo<T::Key, T::Value> {
|
impl<T: Table + 'static> DatabaseIter<T> for RedbTableRo<T::Key, T::Value> {
|
||||||
|
/*
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_range<'a, Range>(
|
fn get_range<'a, Range>(
|
||||||
&'a self,
|
&'a self,
|
||||||
|
@ -79,6 +80,8 @@ impl<T: Table + 'static> DatabaseIter<T> for RedbTableRo<T::Key, T::Value> {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn iter(&self) -> DbResult<impl Iterator<Item = DbResult<(T::Key, T::Value)>> + '_> {
|
fn iter(&self) -> DbResult<impl Iterator<Item = DbResult<(T::Key, T::Value)>> + '_> {
|
||||||
Ok(ReadableTable::iter(self)?.map(|result| {
|
Ok(ReadableTable::iter(self)?.map(|result| {
|
||||||
|
|
|
@ -225,7 +225,7 @@ fn db_read_write() {
|
||||||
|
|
||||||
// Assert the whole range is there.
|
// Assert the whole range is there.
|
||||||
{
|
{
|
||||||
let range = table_ro.get_range(..).unwrap();
|
let range = table_ro.values().unwrap();
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for result in range {
|
for result in range {
|
||||||
let value = result.unwrap();
|
let value = result.unwrap();
|
||||||
|
@ -235,20 +235,14 @@ fn db_read_write() {
|
||||||
assert_eq!(i, N);
|
assert_eq!(i, N);
|
||||||
}
|
}
|
||||||
|
|
||||||
// `get_range()` tests.
|
// iter tests.
|
||||||
let mut key = KEY;
|
|
||||||
key += N;
|
|
||||||
let range = KEY..key;
|
|
||||||
|
|
||||||
// Assert count is correct.
|
// Assert count is correct.
|
||||||
assert_eq!(
|
assert_eq!(N as usize, table_ro.values().unwrap().count());
|
||||||
N as usize,
|
|
||||||
table_ro.get_range(range.clone()).unwrap().count()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Assert each returned value from the iterator is owned.
|
// Assert each returned value from the iterator is owned.
|
||||||
{
|
{
|
||||||
let mut iter = table_ro.get_range(range.clone()).unwrap();
|
let mut iter = table_ro.values().unwrap();
|
||||||
let value = iter.next().unwrap().unwrap(); // 1. take value out
|
let value = iter.next().unwrap().unwrap(); // 1. take value out
|
||||||
drop(iter); // 2. drop the `impl Iterator + 'a`
|
drop(iter); // 2. drop the `impl Iterator + 'a`
|
||||||
assert_value(value); // 3. assert even without the iterator, the value is alive
|
assert_value(value); // 3. assert even without the iterator, the value is alive
|
||||||
|
@ -256,7 +250,7 @@ fn db_read_write() {
|
||||||
|
|
||||||
// Assert each value is the same.
|
// Assert each value is the same.
|
||||||
{
|
{
|
||||||
let mut iter = table_ro.get_range(range).unwrap();
|
let mut iter = table_ro.values().unwrap();
|
||||||
for _ in 0..N {
|
for _ in 0..N {
|
||||||
let value = iter.next().unwrap().unwrap();
|
let value = iter.next().unwrap().unwrap();
|
||||||
assert_value(value);
|
assert_value(value);
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
//! Abstracted database table operations; `trait DatabaseRo` & `trait DatabaseRw`.
|
//! Abstracted database table operations; `trait DatabaseRo` & `trait DatabaseRw`.
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Import
|
//---------------------------------------------------------------------------------------------------- Import
|
||||||
use std::ops::RangeBounds;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
error::{DbResult, RuntimeError},
|
error::{DbResult, RuntimeError},
|
||||||
table::Table,
|
table::Table,
|
||||||
|
@ -35,6 +33,9 @@ Each iteration of the iterator has the potential to error as well."
|
||||||
/// - <https://github.com/Cuprate/cuprate/pull/102#discussion_r1548695610>
|
/// - <https://github.com/Cuprate/cuprate/pull/102#discussion_r1548695610>
|
||||||
/// - <https://github.com/Cuprate/cuprate/pull/104>
|
/// - <https://github.com/Cuprate/cuprate/pull/104>
|
||||||
pub trait DatabaseIter<T: Table> {
|
pub trait DatabaseIter<T: Table> {
|
||||||
|
/*
|
||||||
|
FIXME: <https://github.com/Cuprate/cuprate/issues/348>
|
||||||
|
|
||||||
/// Get an [`Iterator`] of value's corresponding to a range of keys.
|
/// Get an [`Iterator`] of value's corresponding to a range of keys.
|
||||||
///
|
///
|
||||||
/// For example:
|
/// For example:
|
||||||
|
@ -55,6 +56,8 @@ pub trait DatabaseIter<T: Table> {
|
||||||
where
|
where
|
||||||
Range: RangeBounds<T::Key> + 'a;
|
Range: RangeBounds<T::Key> + 'a;
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
/// Get an [`Iterator`] that returns the `(key, value)` types for this database.
|
/// Get an [`Iterator`] that returns the `(key, value)` types for this database.
|
||||||
#[doc = doc_iter!()]
|
#[doc = doc_iter!()]
|
||||||
#[expect(clippy::iter_not_returning_iterator)]
|
#[expect(clippy::iter_not_returning_iterator)]
|
||||||
|
|
Loading…
Reference in a new issue