mirror of
https://github.com/Cuprate/cuprate.git
synced 2025-04-16 11:11:54 +00:00
cuprated/database: fix error mappings + msg (#419)
* add * dbi * err * log and panic
This commit is contained in:
parent
550d8598e4
commit
51b56b0a8b
4 changed files with 22 additions and 14 deletions
|
@ -20,12 +20,13 @@ use std::{mem, sync::Arc};
|
|||
|
||||
use tokio::sync::mpsc;
|
||||
use tower::{Service, ServiceExt};
|
||||
use tracing::{info, level_filters::LevelFilter};
|
||||
use tracing::{error, info, level_filters::LevelFilter};
|
||||
use tracing_subscriber::{layer::SubscriberExt, reload::Handle, util::SubscriberInitExt, Registry};
|
||||
|
||||
use cuprate_consensus_context::{
|
||||
BlockChainContextRequest, BlockChainContextResponse, BlockchainContextService,
|
||||
};
|
||||
use cuprate_database::{InitError, DATABASE_CORRUPT_MSG};
|
||||
use cuprate_helper::time::secs_to_hms;
|
||||
use cuprate_types::blockchain::BlockchainWriteRequest;
|
||||
|
||||
|
@ -77,9 +78,13 @@ fn main() {
|
|||
config.blockchain_config(),
|
||||
Arc::clone(&db_thread_pool),
|
||||
)
|
||||
.unwrap();
|
||||
.inspect_err(|e| error!("Blockchain database error: {e}"))
|
||||
.expect(DATABASE_CORRUPT_MSG);
|
||||
|
||||
let (txpool_read_handle, txpool_write_handle, _) =
|
||||
cuprate_txpool::service::init_with_pool(config.txpool_config(), db_thread_pool).unwrap();
|
||||
cuprate_txpool::service::init_with_pool(config.txpool_config(), db_thread_pool)
|
||||
.inspect_err(|e| error!("Txpool database error: {e}"))
|
||||
.expect(DATABASE_CORRUPT_MSG);
|
||||
|
||||
// Initialize async tasks.
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ impl From<heed::Error> for crate::InitError {
|
|||
//
|
||||
// "Requested page not found - this usually indicates corruption."
|
||||
// <https://docs.rs/heed/latest/heed/enum.MdbError.html#variant.PageNotFound>
|
||||
E2::Corrupted | E2::PageNotFound => Self::Corrupt,
|
||||
E2::BadDbi | E2::Corrupted | E2::PageNotFound => Self::Corrupt,
|
||||
|
||||
// These errors shouldn't be returned on database init.
|
||||
E2::Incompatible
|
||||
|
@ -45,7 +45,6 @@ impl From<heed::Error> for crate::InitError {
|
|||
| E2::MapResized
|
||||
| E2::BadRslot
|
||||
| E2::BadValSize
|
||||
| E2::BadDbi
|
||||
| E2::Panic => Self::Unknown(Box::new(mdb_error)),
|
||||
},
|
||||
|
||||
|
@ -85,7 +84,7 @@ impl From<heed::Error> for crate::RuntimeError {
|
|||
//
|
||||
// "Requested page not found - this usually indicates corruption."
|
||||
// <https://docs.rs/heed/latest/heed/enum.MdbError.html#variant.PageNotFound>
|
||||
E2::Corrupted | E2::PageNotFound => panic!("{mdb_error:#?}\n{DATABASE_CORRUPT_MSG}"),
|
||||
E2::BadDbi | E2::Corrupted | E2::PageNotFound => panic!("{mdb_error:#?}\n{DATABASE_CORRUPT_MSG}"),
|
||||
|
||||
// These errors should not occur, and if they do,
|
||||
// the best thing `cuprate_database` can do for
|
||||
|
@ -99,8 +98,7 @@ impl From<heed::Error> for crate::RuntimeError {
|
|||
| E2::TlsFull
|
||||
| E2::TxnFull
|
||||
| E2::BadRslot
|
||||
| E2::VersionMismatch
|
||||
| E2::BadDbi => panic!("{mdb_error:#?}"),
|
||||
| E2::VersionMismatch => panic!("{mdb_error:#?}"),
|
||||
|
||||
// These errors are the same as above, but instead
|
||||
// of being errors we can't control, these are errors
|
||||
|
|
|
@ -10,13 +10,15 @@ use cfg_if::cfg_if;
|
|||
/// messages if we think the database is corrupted.
|
||||
///
|
||||
/// This is meant to be user-friendly.
|
||||
pub const DATABASE_CORRUPT_MSG: &str = r"Cuprate has encountered a fatal error. The database may be corrupted.
|
||||
pub const DATABASE_CORRUPT_MSG: &str = r"`cuprated` has encountered a fatal error. The database may be corrupted.
|
||||
|
||||
TODO: instructions on:
|
||||
1. What to do
|
||||
2. How to fix (re-sync, recover, etc)
|
||||
3. General advice for preventing corruption
|
||||
4. etc";
|
||||
If `cuprated` continues to crash with the current database,
|
||||
you may have to delete the database file and re-sync from scratch.
|
||||
|
||||
See <https://user.cuprate.org/resources/disk.html>
|
||||
for more information on where database files are.
|
||||
|
||||
If this happens frequently, consider using the `Safe` sync mode.";
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Misc
|
||||
/// Static string of the `crate` being used as the database backend.
|
||||
|
|
|
@ -24,6 +24,9 @@ pub type DbResult<T> = Result<T, RuntimeError>;
|
|||
pub enum InitError {
|
||||
/// The given `Path/File` existed and was accessible,
|
||||
/// but was not a valid database file.
|
||||
///
|
||||
/// This error can sometimes be returned after an
|
||||
/// initial corruption error over [`InitError::Corrupt`].
|
||||
#[error("database file exists but is not valid")]
|
||||
Invalid,
|
||||
|
||||
|
|
Loading…
Reference in a new issue