mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-12-23 03:59:31 +00:00
write: impl write_block()
This commit is contained in:
parent
c65eb0a3ca
commit
a598fc38d2
1 changed files with 26 additions and 2 deletions
|
@ -15,9 +15,11 @@ use cuprate_types::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
env::{Env, EnvInner},
|
||||
error::RuntimeError,
|
||||
service::types::{ResponseReceiver, ResponseResult, ResponseSender},
|
||||
ConcreteEnv, Env,
|
||||
transaction::TxRw,
|
||||
ConcreteEnv,
|
||||
};
|
||||
|
||||
//---------------------------------------------------------------------------------------------------- Constants
|
||||
|
@ -225,6 +227,28 @@ impl DatabaseWriter {
|
|||
|
||||
/// [`WriteRequest::WriteBlock`].
|
||||
#[inline]
|
||||
#[allow(clippy::significant_drop_tightening)]
|
||||
fn write_block(env: &ConcreteEnv, block: &VerifiedBlockInformation) -> ResponseResult {
|
||||
todo!()
|
||||
let env_inner = env.env_inner();
|
||||
let tx_rw = env_inner.tx_rw()?;
|
||||
|
||||
let result = {
|
||||
let mut tables_mut = env_inner.open_tables_mut(&tx_rw)?;
|
||||
crate::ops::block::add_block(block, &mut tables_mut)
|
||||
};
|
||||
|
||||
match result {
|
||||
Ok(()) => {
|
||||
tx_rw.commit()?;
|
||||
Ok(Response::WriteBlockOk)
|
||||
}
|
||||
Err(e) => {
|
||||
// INVARIANT: ensure database atomicity by aborting
|
||||
// the transaction on `add_block()` failures.
|
||||
tx_rw
|
||||
.abort()
|
||||
.expect("TODO: if we cannot maintain atomicity by aborting, should we panic?");
|
||||
Err(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue