Skip to content
Snippets Groups Projects
Commit 5f3d842f authored by Éloïs's avatar Éloïs
Browse files

[ref] db-tools: prepare sled mig: rename kv_db & make replayable read tx

rename mod kv_db -> kv_db_old
parent 99d1dde1
No related branches found
No related tags found
1 merge request!263[ref] prepare sled mig
Showing
with 56 additions and 37 deletions
......@@ -26,7 +26,7 @@ use crate::errors::DursCoreError;
use crate::DursCore;
pub use dbex::*;
use durs_conf::DuRsConf;
use durs_dbs_tools::kv_db::KvFileDbHandler;
use durs_dbs_tools::kv_db_old::KvFileDbHandler;
pub use durs_network::cli::sync::SyncOpt;
pub use keys::KeysOpt;
use log::Level;
......@@ -94,7 +94,7 @@ pub enum DursCommandEnum<T: ExecutableModuleCommand> {
impl<T: ExecutableModuleCommand> DursCommand<T> {
fn open_bc_db(&self, profile_path: &PathBuf) -> Result<KvFileDbHandler, DursCoreError> {
let bc_db_path = durs_conf::get_blockchain_db_path(profile_path.clone());
durs_dbs_tools::kv_db::KvFileDbHandler::open_db(
durs_dbs_tools::kv_db_old::KvFileDbHandler::open_db(
bc_db_path.as_path(),
&durs_bc_db_reader::bc_db_schema(),
)
......
......@@ -155,7 +155,7 @@ impl DursCore<DuRsConf> {
/// Execute core command
pub fn execute_core_command<PlugFunc>(
bc_db: durs_dbs_tools::kv_db::KvFileDbHandler,
bc_db: durs_dbs_tools::kv_db_old::KvFileDbHandler,
core_command: DursCoreCommand,
durs_core_opts: DursCoreOptions,
mut plug_modules: PlugFunc,
......@@ -278,7 +278,7 @@ impl DursCore<DuRsConf> {
/// Start durs server
pub fn start(
mut self,
bc_db: durs_dbs_tools::kv_db::KvFileDbHandler,
bc_db: durs_dbs_tools::kv_db_old::KvFileDbHandler,
) -> Result<(), DursCoreError> {
if self.network_modules_count == 0 {
fatal_error!(
......
......@@ -24,7 +24,7 @@ use std::collections::HashMap;
/// Find certifications that emitted in indicated blocks expiring
pub fn find_expire_certs<DB: BcDbInReadTx>(
db: &DB,
blocks_expiring: Vec<BlockNumber>,
blocks_expiring: &[BlockNumber],
) -> Result<HashMap<(WotId, WotId), BlockNumber>, DbError> {
let mut all_expire_certs = HashMap::new();
for expire_block_id in blocks_expiring {
......@@ -36,7 +36,7 @@ pub fn find_expire_certs<DB: BcDbInReadTx>(
if let Some(value) = entry_result?.1 {
if let DbValue::U64(cert) = value {
let (source, target) = cert_from_u64(cert);
all_expire_certs.insert((source, target), expire_block_id);
all_expire_certs.insert((source, target), *expire_block_id);
} else {
return Err(DbError::DBCorrupted);
}
......
......@@ -237,7 +237,7 @@ mod test {
use dubp_common_doc::Blockstamp;
use dup_crypto_tests_tools::mocks::pubkey;
use durs_common_tests_tools::collections::slice_same_elems;
use durs_dbs_tools::kv_db::KvFileDbHandler;
use durs_dbs_tools::kv_db_old::KvFileDbHandler;
fn gen_mock_dal_idty(pubkey: PubKey, created_block_id: BlockNumber) -> IdentityDb {
IdentityDb {
......
......@@ -37,7 +37,7 @@ pub mod paging;
pub mod tools;
pub mod traits;
pub use durs_dbs_tools::kv_db::{
pub use durs_dbs_tools::kv_db_old::{
from_db_value, KvFileDbRead as DbReadable, KvFileDbReader as Reader,
KvFileDbRoHandler as BcDbRo, KvFileDbSchema, KvFileDbStoreType, KvFileDbValue as DbValue,
Readable as DbReader,
......@@ -111,7 +111,7 @@ impl<'r, 'db: 'r, DB> durs_common_tools::traits::NotMock for BcDbWithReaderStruc
pub mod tests {
use super::*;
use durs_dbs_tools::kv_db::KvFileDbHandler;
use durs_dbs_tools::kv_db_old::KvFileDbHandler;
use tempfile::tempdir;
#[inline]
......
......@@ -34,7 +34,7 @@ where
fn r<D, F>(&self, f: F) -> Result<D, DbError>
where
DB: DbReadable,
F: FnOnce(&BcDbWithReaderStruct<DB>) -> Result<D, DbError>;
F: Fn(&BcDbWithReaderStruct<DB>) -> Result<D, DbError>;
}
impl<DB> BcDbRead<DB> for DB
......@@ -44,7 +44,7 @@ where
fn r<D, F>(&self, f: F) -> Result<D, DbError>
where
DB: DbReadable,
F: FnOnce(&BcDbWithReaderStruct<DB>) -> Result<D, DbError>,
F: Fn(&BcDbWithReaderStruct<DB>) -> Result<D, DbError>,
{
self.read(|r| f(&BcDbWithReaderStruct { db: self, r }))
}
......@@ -61,7 +61,7 @@ pub trait BcDbWithReader {
#[cfg(feature = "mock")]
impl<'a> BcDbWithReader for MockBcDbInReadTx {
type DB = crate::BcDbRo;
type R = durs_dbs_tools::kv_db::MockKvFileDbReader;
type R = durs_dbs_tools::kv_db_old::MockKvFileDbReader;
fn db(&self) -> &Self::DB {
unreachable!()
......
......@@ -37,7 +37,7 @@ pub mod current_metadata;
pub mod indexes;
pub mod writers;
pub use durs_dbs_tools::kv_db::{
pub use durs_dbs_tools::kv_db_old::{
KvFileDbHandler, KvFileDbRead as DbReadable, KvFileDbRoHandler, KvFileDbSchema,
KvFileDbStoreType, KvFileDbValue, KvFileDbWriter as DbWriter,
};
......
......@@ -90,7 +90,7 @@ fn treat_chainable_block(
let blocks_expiring = Vec::with_capacity(0); // TODO
let expire_certs = durs_bc_db_reader::indexes::certs::find_expire_certs(
&BcDbRwWithWriter { db, w },
blocks_expiring,
&blocks_expiring,
)?;
// If we're in block genesis, get the currency parameters
......
......@@ -224,7 +224,7 @@ mod tests {
]),
db.read(|r| fork_resolution_algo(
&BcDbRwWithReader { db: &db, r },
&mut fork_tree,
&fork_tree,
fork_window_size,
current_blockstamp,
&invalid_blocks
......@@ -256,7 +256,7 @@ mod tests {
Some(new_main_blocks.iter().map(|b| b.blockstamp()).collect()),
db.read(|r| fork_resolution_algo(
&BcDbRwWithReader { db: &db, r },
&mut fork_tree,
&fork_tree,
fork_window_size,
current_blockstamp,
&invalid_blocks
......
......@@ -148,12 +148,12 @@ pub fn receive_req(
bc.db()
.r(|db_r| {
Ok(pubkeys
.into_iter()
.iter()
.map(|p| {
(
p,
*p,
durs_bc_db_reader::indexes::identities::get_uid(
db_r, &p,
db_r, p,
)
.unwrap_or(None),
)
......
......@@ -97,7 +97,7 @@ impl BlockApplicator {
let expire_certs = if let Some(db) = self.db.take() {
let expire_certs = db
.r(|db_r| {
durs_bc_db_reader::indexes::certs::find_expire_certs(db_r, blocks_expiring)
durs_bc_db_reader::indexes::certs::find_expire_certs(db_r, &blocks_expiring)
})
.expect("find_expire_certs() : DbError");
self.db = Some(db);
......
......@@ -101,8 +101,8 @@ impl QueryFields for Query {
exec_in_db_transaction!(blocks(
executor,
trail,
paging_opt,
block_interval_opt,
paging_opt.as_ref(),
block_interval_opt.as_ref(),
step as usize,
sort_order
))
......
......@@ -29,7 +29,7 @@ pub struct FilledBlockInterval {
impl FilledBlockInterval {
pub(crate) fn new(
block_interval_opt: Option<BlockInterval>,
block_interval_opt: Option<&BlockInterval>,
current_block_number_opt: Option<BlockNumber>,
) -> Self {
let current_block_number = current_block_number_opt.unwrap_or(BlockNumber(0)).0 as usize;
......@@ -120,7 +120,7 @@ mod tests {
assert_eq! {
500..=750,
FilledBlockInterval::new(Some(BlockInterval {
FilledBlockInterval::new(Some(&BlockInterval {
from: Some(500),
to: None,
}), Some(BlockNumber(750))).get_range()
......@@ -128,7 +128,7 @@ mod tests {
assert_eq! {
500..=700,
FilledBlockInterval::new(Some(BlockInterval {
FilledBlockInterval::new(Some(&BlockInterval {
from: Some(500),
to: Some(700),
}), Some(BlockNumber(750))).get_range()
......
......@@ -35,11 +35,14 @@ impl Default for FilledPaging {
}
}
impl From<Option<Paging>> for FilledPaging {
fn from(paging_opt: Option<Paging>) -> Self {
impl From<Option<&Paging>> for FilledPaging {
fn from(paging_opt: Option<&Paging>) -> Self {
if let Some(paging) = paging_opt {
FilledPaging {
page_number: paging.page_number.unwrap_or(DEFAULT_PAGE_NUMBER_I32) as isize,
page_number: paging
.page_number
.clone()
.unwrap_or(DEFAULT_PAGE_NUMBER_I32) as isize,
page_size: if let Some(page_size) = paging.page_size {
if page_size < MIN_PAGE_SIZE {
MIN_PAGE_SIZE as usize
......@@ -115,7 +118,7 @@ mod tests {
page_number: 0,
page_size: 10,
},
FilledPaging::from(Some(Paging {
FilledPaging::from(Some(&Paging {
page_number: None,
page_size: Some(10)
})),
......@@ -125,7 +128,7 @@ mod tests {
page_number: 1,
page_size: 50,
},
FilledPaging::from(Some(Paging {
FilledPaging::from(Some(&Paging {
page_number: Some(1),
page_size: None
})),
......@@ -135,7 +138,7 @@ mod tests {
page_number: 1,
page_size: 10,
},
FilledPaging::from(Some(Paging {
FilledPaging::from(Some(&Paging {
page_number: Some(1),
page_size: Some(10)
})),
......
......@@ -28,8 +28,8 @@ use juniper_from_schema::{QueryTrail, Walked};
pub(crate) fn execute<DB: BcDbInReadTx>(
db: &DB,
trail: &QueryTrail<'_, BlocksPage, Walked>,
paging_opt: Option<Paging>,
block_interval_opt: Option<BlockInterval>,
paging_opt: Option<&Paging>,
block_interval_opt: Option<&BlockInterval>,
step: usize,
sort_order: SortOrder,
) -> Result<BlocksPage, DbError> {
......
// Copyright (C) 2017-2019 The AXIOM TEAM Association.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Define Key-Value database
///////////////////////
/// OLD A SUPPRIMER ///
///////////////////////
mod file;
#[cfg(feature = "mock")]
......
......@@ -198,7 +198,7 @@ pub trait KvFileDbRead: Sized {
/// Read datas in transaction database
fn read<F, R>(&self, f: F) -> Result<R, DbError>
where
F: FnOnce(KvFileDbReader) -> Result<R, DbError>;
F: Fn(KvFileDbReader) -> Result<R, DbError>;
}
impl KvFileDbRead for KvFileDbRoHandler {
......@@ -221,7 +221,7 @@ impl KvFileDbRead for KvFileDbRoHandler {
#[inline]
fn read<F, R>(&self, f: F) -> Result<R, DbError>
where
F: FnOnce(KvFileDbReader) -> Result<R, DbError>,
F: Fn(KvFileDbReader) -> Result<R, DbError>,
{
self.0.read(f)
}
......@@ -320,7 +320,7 @@ impl KvFileDbRead for KvFileDbHandler {
}
fn read<F, R>(&self, f: F) -> Result<R, DbError>
where
F: FnOnce(KvFileDbReader) -> Result<R, DbError>,
F: Fn(KvFileDbReader) -> Result<R, DbError>,
{
Ok(f(KvFileDbReader(&self.arc_clone().read()?.read()?))?)
}
......
......@@ -31,7 +31,8 @@
mod errors;
mod free_struct_db;
pub mod kv_db;
/// module a supprimer
pub mod kv_db_old;
pub use errors::DbError;
pub use free_struct_db::{open_free_struct_file_db, open_free_struct_memory_db, BinFreeStructDb};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment