Fix issue in reverting the last incomplete tx. (#215)

This commit is contained in:
peilun-conflux 2024-09-27 10:02:47 +08:00 committed by GitHub
parent ae6ecfec96
commit 69b71fc0b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 9 deletions

View File

@ -189,15 +189,8 @@ impl EntryBatchData {
}
pub fn insert_data(&mut self, start_byte: usize, mut data: Vec<u8>) -> Result<Vec<u16>> {
assert!(start_byte % BYTES_PER_SECTOR == 0);
assert!(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![]);
}
assert_eq!(start_byte % BYTES_PER_SECTOR, 0);
assert_eq!(data.len() % BYTES_PER_SECTOR, 0);
// Check if the entry is completed
let (list, subtree_list) = if let EntryBatchData::Incomplete(x) = self {

View File

@ -127,6 +127,14 @@ impl EntryBatch {
/// Return `Error` if the new data overlaps with old data.
/// 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>> {
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)
}

View File

@ -708,6 +708,7 @@ impl LogManager {
};
if let Some(tx) = last_tx_to_insert {
log_manager.revert_to(tx.seq - 1)?;
log_manager.put_tx(tx)?;
let mut merkle = log_manager.merkle.write();
for (index, h) in extra_leaves {