mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-04-22 22:08:13 +00:00
storage: replace println
with tracing
(#417)
* replace `println` with `tracing` * fix * remove feature * !
This commit is contained in:
parent
3c86c5ed76
commit
57cd96ed6c
7 changed files with 31 additions and 25 deletions
Cargo.lock
storage
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -743,6 +743,7 @@ dependencies = [
|
|||
"serde",
|
||||
"tempfile",
|
||||
"thiserror",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -756,6 +757,7 @@ dependencies = [
|
|||
"rayon",
|
||||
"serde",
|
||||
"tower 0.5.1",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -23,6 +23,7 @@ cfg-if = { workspace = true }
|
|||
page_size = { version = "0.6.0" } # Needed for database resizes, they must be a multiple of the OS page size.
|
||||
paste = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
tracing = { workspace = true }
|
||||
|
||||
# Optional features.
|
||||
heed = { version = "0.20.5", features = ["read-txn-no-tls"] }
|
||||
|
|
|
@ -94,14 +94,14 @@ to bulk generate zero-sized marker types that implement [`Table`].
|
|||
This macro also generates other convenient traits specific to _your_ tables.
|
||||
|
||||
# Feature flags
|
||||
Different database backends are enabled by the feature flags:
|
||||
- `heed` (LMDB)
|
||||
- `redb`
|
||||
| Feature flag | Description |
|
||||
|--------------|-------------|
|
||||
| `heed` | Enables the `heed` (LMDB) backend
|
||||
| `redb` | Enables the `redb` backend
|
||||
|
||||
The default is `heed`.
|
||||
The defaults are: `heed`.
|
||||
|
||||
`tracing` is always enabled and cannot be disabled via feature-flag.
|
||||
<!-- FIXME: tracing should be behind a feature flag -->
|
||||
|
||||
# Examples
|
||||
The below is an example of using `cuprate-database`.
|
||||
|
|
|
@ -8,6 +8,7 @@ use std::{
|
|||
};
|
||||
|
||||
use heed::{DatabaseFlags, EnvFlags, EnvOpenOptions};
|
||||
use tracing::{debug, warn};
|
||||
|
||||
use crate::{
|
||||
backend::heed::{
|
||||
|
@ -70,18 +71,16 @@ impl Drop for ConcreteEnv {
|
|||
// We need to do `mdb_env_set_flags(&env, MDB_NOSYNC|MDB_ASYNCMAP, 0)`
|
||||
// to clear the no sync and async flags such that the below `self.sync()`
|
||||
// _actually_ synchronously syncs.
|
||||
if let Err(_e) = Env::sync(self) {
|
||||
// TODO: log error?
|
||||
if let Err(e) = Env::sync(self) {
|
||||
warn!("Env sync error: {e}");
|
||||
}
|
||||
|
||||
// TODO: log that we are dropping the database.
|
||||
|
||||
// TODO: use tracing.
|
||||
// <https://github.com/LMDB/lmdb/blob/b8e54b4c31378932b69f1298972de54a565185b1/libraries/liblmdb/lmdb.h#L49-L61>
|
||||
let result = self.env.read().unwrap().clear_stale_readers();
|
||||
|
||||
match result {
|
||||
Ok(n) => println!("LMDB stale readers cleared: {n}"),
|
||||
Err(e) => println!("LMDB stale reader clear error: {e:?}"),
|
||||
Ok(n) => debug!("LMDB stale readers cleared: {n}"),
|
||||
Err(e) => debug!("LMDB stale reader clear error: {e:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,11 +31,8 @@ impl Drop for ConcreteEnv {
|
|||
fn drop(&mut self) {
|
||||
// INVARIANT: drop(ConcreteEnv) must sync.
|
||||
if let Err(e) = self.sync() {
|
||||
// TODO: use tracing
|
||||
println!("{e:#?}");
|
||||
tracing::warn!("Env sync error: {e}");
|
||||
}
|
||||
|
||||
// TODO: log that we are dropping the database.
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,10 +9,10 @@ repository = "https://github.com/Cuprate/cuprate/tree/main/storage/service"
|
|||
keywords = ["cuprate", "service", "database"]
|
||||
|
||||
[features]
|
||||
default = ["heed"]
|
||||
heed = ["cuprate-database/heed"]
|
||||
redb = ["cuprate-database/redb"]
|
||||
redb-memorey = ["cuprate-database/redb-memory"]
|
||||
default = ["heed"]
|
||||
heed = ["cuprate-database/heed"]
|
||||
redb = ["cuprate-database/redb"]
|
||||
redb-memory = ["cuprate-database/redb-memory"]
|
||||
|
||||
[dependencies]
|
||||
cuprate-database = { workspace = true }
|
||||
|
@ -23,6 +23,7 @@ rayon = { workspace = true }
|
|||
tower = { workspace = true }
|
||||
futures = { workspace = true, features = ["std"] }
|
||||
crossbeam = { workspace = true, features = ["std"] }
|
||||
tracing = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
@ -5,6 +5,7 @@ use std::{
|
|||
};
|
||||
|
||||
use futures::channel::oneshot;
|
||||
use tracing::{info, warn};
|
||||
|
||||
use cuprate_database::{ConcreteEnv, DbResult, Env, RuntimeError};
|
||||
use cuprate_helper::asynch::InfallibleOneshotReceiver;
|
||||
|
@ -150,10 +151,16 @@ fn database_writer<Req, Res>(
|
|||
// add that much instead of the default 1GB.
|
||||
// <https://github.com/monero-project/monero/blob/059028a30a8ae9752338a7897329fe8012a310d5/src/blockchain_db/lmdb/db_lmdb.cpp#L665-L695>
|
||||
let old = env.current_map_size();
|
||||
let new = env.resize_map(None);
|
||||
let new = env.resize_map(None).get();
|
||||
|
||||
// TODO: use tracing.
|
||||
println!("resizing database memory map, old: {old}B, new: {new}B");
|
||||
const fn bytes_to_megabytes(bytes: usize) -> usize {
|
||||
bytes / 1_000_000
|
||||
}
|
||||
|
||||
let old_mb = bytes_to_megabytes(old);
|
||||
let new_mb = bytes_to_megabytes(new);
|
||||
|
||||
info!("Resizing database memory map, old: {old_mb}MB, new: {new_mb}MB");
|
||||
|
||||
// Try handling the request again.
|
||||
continue 'retry;
|
||||
|
@ -170,8 +177,7 @@ fn database_writer<Req, Res>(
|
|||
|
||||
// Send the response back, whether if it's an `Ok` or `Err`.
|
||||
if let Err(e) = response_sender.send(response) {
|
||||
// TODO: use tracing.
|
||||
println!("database writer failed to send response: {e:?}");
|
||||
warn!("Database writer failed to send response: {e:?}");
|
||||
}
|
||||
|
||||
continue 'main;
|
||||
|
|
Loading…
Reference in a new issue