mirror of
https://github.com/0glabs/0g-storage-node.git
synced 2024-11-20 15:05:19 +00:00
Fix issue in reverting the last incomplete tx. (#215)
This commit is contained in:
parent
ae6ecfec96
commit
69b71fc0b2
@ -189,15 +189,8 @@ impl EntryBatchData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_data(&mut self, start_byte: usize, mut data: Vec<u8>) -> Result<Vec<u16>> {
|
pub fn insert_data(&mut self, start_byte: usize, mut data: Vec<u8>) -> Result<Vec<u16>> {
|
||||||
assert!(start_byte % BYTES_PER_SECTOR == 0);
|
assert_eq!(start_byte % BYTES_PER_SECTOR, 0);
|
||||||
assert!(data.len() % BYTES_PER_SECTOR == 0);
|
assert_eq!(data.len() % BYTES_PER_SECTOR, 0);
|
||||||
|
|
||||||
if data.is_empty() || self.get(start_byte, data.len()) == Some(&data) {
|
|
||||||
// TODO(zz): This assumes the caller has processed chain reorg (truncate flow) before
|
|
||||||
// inserting new data, and the data of the same file are always inserted with the
|
|
||||||
// same pattern.
|
|
||||||
return Ok(vec![]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the entry is completed
|
// Check if the entry is completed
|
||||||
let (list, subtree_list) = if let EntryBatchData::Incomplete(x) = self {
|
let (list, subtree_list) = if let EntryBatchData::Incomplete(x) = self {
|
||||||
|
@ -127,6 +127,14 @@ impl EntryBatch {
|
|||||||
/// Return `Error` if the new data overlaps with old data.
|
/// Return `Error` if the new data overlaps with old data.
|
||||||
/// Convert `Incomplete` to `Completed` if the chunk is completed after the insertion.
|
/// Convert `Incomplete` to `Completed` if the chunk is completed after the insertion.
|
||||||
pub fn insert_data(&mut self, offset: usize, data: Vec<u8>) -> Result<Vec<u16>> {
|
pub fn insert_data(&mut self, offset: usize, data: Vec<u8>) -> Result<Vec<u16>> {
|
||||||
|
if data.is_empty()
|
||||||
|
|| self
|
||||||
|
.get_unsealed_data(offset, data.len() / BYTES_PER_SECTOR)
|
||||||
|
.as_ref()
|
||||||
|
== Some(&data)
|
||||||
|
{
|
||||||
|
return Ok(vec![]);
|
||||||
|
}
|
||||||
self.data.insert_data(offset * BYTES_PER_SECTOR, data)
|
self.data.insert_data(offset * BYTES_PER_SECTOR, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -708,6 +708,7 @@ impl LogManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if let Some(tx) = last_tx_to_insert {
|
if let Some(tx) = last_tx_to_insert {
|
||||||
|
log_manager.revert_to(tx.seq - 1)?;
|
||||||
log_manager.put_tx(tx)?;
|
log_manager.put_tx(tx)?;
|
||||||
let mut merkle = log_manager.merkle.write();
|
let mut merkle = log_manager.merkle.write();
|
||||||
for (index, h) in extra_leaves {
|
for (index, h) in extra_leaves {
|
||||||
|
Loading…
Reference in New Issue
Block a user