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

[ref] gva: move db handlers to writer crate

parent 98d1079f
No related branches found
No related tags found
1 merge request!1346Opti/gva txs history
......@@ -1069,7 +1069,6 @@ dependencies = [
"dubp",
"duniter-dbs",
"duniter-dbs-write-ops",
"duniter-gva",
"duniter-gva-db-writer",
"fast-threadpool",
"flume",
......@@ -1155,7 +1154,6 @@ dependencies = [
"http",
"log",
"mockall",
"once_cell",
"resiter",
"serde",
"serde_json",
......@@ -1173,6 +1171,7 @@ dependencies = [
"dubp",
"duniter-dbs",
"maplit",
"once_cell",
"resiter",
"smallvec",
]
......
......@@ -25,7 +25,6 @@ dirs = "3.0.1"
dubp = { version = "0.34.0" }
duniter-dbs = { path = "../../rust-libs/duniter-dbs", default-features = false, features = ["explorer", "leveldb_backend", "sled_backend"] }
duniter-dbs-write-ops = { path = "../../rust-libs/duniter-dbs-write-ops", default-features = false, features = ["explorer", "leveldb_backend", "sled_backend"] }
duniter-gva = { path = "../../rust-libs/modules/gva" }
duniter-gva-db-writer = { path = "../../rust-libs/modules/gva/db-writer" }
fast-threadpool = "0.2.2"
flume = "0.9.1"
......
......@@ -27,7 +27,7 @@ const CHUNK_SIZE: usize = 250;
pub(crate) fn migrate(profile_path: PathBuf) -> anyhow::Result<()> {
let start_time = Instant::now();
let (bc_db, shared_dbs) = duniter_dbs::open_dbs(Some(profile_path.as_path()));
let gva_db = duniter_gva::GvaModule::get_gva_db_rw(Some(profile_path.as_path()));
let gva_db = duniter_gva_db_writer::get_gva_db_rw(Some(profile_path.as_path()));
// Clear bc_db and gva_db
bc_db.clear()?;
......
......@@ -24,7 +24,6 @@ flume = "0.9.1"
futures = "0.3.6"
http = "0.2.1"
log = "0.4.11"
once_cell = "1.5.2"
resiter = "0.4.0"
serde = { version = "1.0.105", features = ["derive"] }
serde_urlencoded = "0.7.0"
......
......@@ -15,6 +15,7 @@ path = "src/lib.rs"
anyhow = "1.0.34"
duniter-dbs = { path = "../../../duniter-dbs" }
dubp = { version = "0.34.0" }
once_cell = "1.5.2"
resiter = "0.4.0"
[dev-dependencies]
......
......@@ -37,10 +37,32 @@ use duniter_dbs::databases::gva_v1::*;
use duniter_dbs::{
databases::gva_v1::{GvaV1Db, GvaV1DbReadable, GvaV1DbWritable},
kv_typed::prelude::*,
HashKeyV2, PubKeyKeyV2, SourceAmountValV2, TxDbV2, WalletConditionsV2,
prelude::*,
FileBackend, HashKeyV2, PubKeyKeyV2, SourceAmountValV2, TxDbV2, WalletConditionsV2,
};
use resiter::filter::Filter;
use std::collections::{BTreeSet, HashMap};
use std::{
collections::{BTreeSet, HashMap},
path::Path,
};
static GVA_DB_RO: once_cell::sync::OnceCell<GvaV1DbRo<FileBackend>> =
once_cell::sync::OnceCell::new();
static GVA_DB_RW: once_cell::sync::OnceCell<GvaV1Db<FileBackend>> =
once_cell::sync::OnceCell::new();
pub fn get_gva_db_ro(profile_path_opt: Option<&Path>) -> &'static GvaV1DbRo<FileBackend> {
GVA_DB_RO.get_or_init(|| get_gva_db_rw(profile_path_opt).get_ro_handler())
}
pub fn get_gva_db_rw(profile_path_opt: Option<&Path>) -> &'static GvaV1Db<FileBackend> {
GVA_DB_RW.get_or_init(|| {
duniter_dbs::databases::gva_v1::GvaV1Db::<FileBackend>::open(FileBackend::gen_backend_conf(
"gva_v1",
profile_path_opt,
))
.expect("Fail to open GVA DB")
})
}
pub struct UtxoV10<'s> {
pub id: UtxoIdV10,
......
......@@ -60,11 +60,12 @@ use dubp::documents_parser::prelude::*;
use dubp::wallet::prelude::*;
use dubp::{block::DubpBlockV10, crypto::hashs::Hash};
use duniter_dbs::databases::{
gva_v1::{GvaV1Db, GvaV1DbReadable, GvaV1DbRo, GvaV1DbWritable},
gva_v1::{GvaV1DbReadable, GvaV1DbRo},
txs_mp_v2::TxsMpV2DbReadable,
};
use duniter_dbs::prelude::*;
use duniter_dbs::{kv_typed::prelude::*, FileBackend, TxDbV2};
use duniter_gva_db_writer::{get_gva_db_ro, get_gva_db_rw};
#[cfg(not(test))]
use duniter_gva_dbs_reader::create_dbs_reader;
#[cfg(not(test))]
......@@ -80,11 +81,6 @@ use std::{
};
use warp::{http::Response as HttpResponse, Filter as _, Rejection, Stream};
static GVA_DB_RO: once_cell::sync::OnceCell<GvaV1DbRo<FileBackend>> =
once_cell::sync::OnceCell::new();
static GVA_DB_RW: once_cell::sync::OnceCell<GvaV1Db<FileBackend>> =
once_cell::sync::OnceCell::new();
#[derive(Debug)]
pub struct GvaModule {
conf: Option<GvaConf>,
......@@ -104,7 +100,7 @@ impl duniter_module::DuniterModule for GvaModule {
dbs_pool: &fast_threadpool::ThreadPoolSyncHandler<SharedDbs<FileBackend>>,
profile_path_opt: Option<&Path>,
) -> Result<Option<JoinHandle<KvResult<()>>>, ThreadPoolDisconnected> {
let gva_db = GvaModule::get_gva_db_rw(profile_path_opt);
let gva_db = get_gva_db_rw(profile_path_opt);
if conf.gva.is_some() {
Ok(Some(dbs_pool.launch(move |_| {
duniter_gva_db_writer::apply_block(&block, gva_db)
......@@ -119,7 +115,7 @@ impl duniter_module::DuniterModule for GvaModule {
dbs_pool: &fast_threadpool::ThreadPoolSyncHandler<SharedDbs<FileBackend>>,
profile_path_opt: Option<&Path>,
) -> Result<Option<JoinHandle<KvResult<()>>>, ThreadPoolDisconnected> {
let gva_db = GvaModule::get_gva_db_rw(profile_path_opt);
let gva_db = get_gva_db_rw(profile_path_opt);
if conf.gva.is_some() {
Ok(Some(dbs_pool.launch(move |_| {
for block in blocks.deref() {
......@@ -137,7 +133,7 @@ impl duniter_module::DuniterModule for GvaModule {
dbs_pool: &fast_threadpool::ThreadPoolSyncHandler<SharedDbs<FileBackend>>,
profile_path_opt: Option<&Path>,
) -> Result<Option<JoinHandle<KvResult<()>>>, ThreadPoolDisconnected> {
let gva_db = GvaModule::get_gva_db_rw(profile_path_opt);
let gva_db = get_gva_db_rw(profile_path_opt);
if conf.gva.is_some() {
Ok(Some(dbs_pool.launch(move |_| {
duniter_gva_db_writer::revert_block(&block, gva_db)
......@@ -185,7 +181,7 @@ impl duniter_module::DuniterModule for GvaModule {
conf: conf.gva.to_owned(),
currency: currency.to_owned(),
dbs_pool: dbs_pool.to_owned(),
gva_db_ro: GvaModule::get_gva_db_ro(profile_path_opt),
gva_db_ro: get_gva_db_ro(profile_path_opt),
mempools,
self_pubkey: conf.self_key_pair.public_key(),
software_version,
......@@ -228,7 +224,7 @@ impl duniter_module::DuniterModule for GvaModule {
profile_path_opt: Option<&Path>,
pubkey: PublicKey,
) -> KvResult<Option<duniter_module::TxsHistoryForBma>> {
let gva_db = GvaModule::get_gva_db_ro(profile_path_opt);
let gva_db = get_gva_db_ro(profile_path_opt);
let duniter_gva_dbs_reader::txs_history::TxsHistory {
sent,
received,
......@@ -274,7 +270,7 @@ impl duniter_module::DuniterModule for GvaModule {
hash: Hash,
profile_path_opt: Option<&Path>,
) -> KvResult<Option<(TransactionDocumentV10, Option<BlockNumber>)>> {
let gva_db = GvaModule::get_gva_db_ro(profile_path_opt);
let gva_db = get_gva_db_ro(profile_path_opt);
dbs_pool
.execute(move |dbs| {
if let Some(tx) = dbs.txs_mp_db.txs().get(&duniter_dbs::HashKeyV2(hash))? {
......@@ -290,18 +286,6 @@ impl duniter_module::DuniterModule for GvaModule {
}
impl GvaModule {
fn get_gva_db_ro(profile_path_opt: Option<&Path>) -> &'static GvaV1DbRo<FileBackend> {
use duniter_dbs::databases::gva_v1::GvaV1DbWritable as _;
GVA_DB_RO.get_or_init(|| GvaModule::get_gva_db_rw(profile_path_opt).get_ro_handler())
}
pub fn get_gva_db_rw(profile_path_opt: Option<&Path>) -> &'static GvaV1Db<FileBackend> {
GVA_DB_RW.get_or_init(|| {
duniter_dbs::databases::gva_v1::GvaV1Db::<FileBackend>::open(
FileBackend::gen_backend_conf("gva_v1", profile_path_opt),
)
.expect("Fail to open GVA DB")
})
}
async fn start_inner(
conf: GvaConf,
currency: String,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment