From a1f2f19489e427aca96a82c77c76e76804b9338a Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sun, 4 Apr 2021 12:32:21 +0300 Subject: [PATCH] Do not increment inode statistics if the object already exists --- src/blockstore_init.cpp | 5 +++++ src/blockstore_stable.cpp | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/blockstore_init.cpp b/src/blockstore_init.cpp index dc6a2be8..9697ab0e 100644 --- a/src/blockstore_init.cpp +++ b/src/blockstore_init.cpp @@ -770,6 +770,7 @@ int blockstore_init_journal::handle_journal_part(void *buf, uint64_t done_pos, u void blockstore_init_journal::erase_dirty_object(blockstore_dirty_db_t::iterator dirty_it) { auto oid = dirty_it->first.oid; + bool exists = !IS_DELETE(dirty_it->second.state); auto dirty_end = dirty_it; dirty_end++; while (1) @@ -788,6 +789,10 @@ void blockstore_init_journal::erase_dirty_object(blockstore_dirty_db_t::iterator auto clean_it = bs->clean_db.find(oid); uint64_t clean_loc = clean_it != bs->clean_db.end() ? clean_it->second.location : UINT64_MAX; + if (exists && clean_loc == UINT64_MAX) + { + bs->inode_space_stats[oid.inode] -= bs->block_size; + } bs->erase_dirty(dirty_it, dirty_end, clean_loc); // Remove it from the flusher's queue, too // Otherwise it may end up referring to a small unstable write after reading the rest of the journal diff --git a/src/blockstore_stable.cpp b/src/blockstore_stable.cpp index 34fa80c7..ba0c552a 100644 --- a/src/blockstore_stable.cpp +++ b/src/blockstore_stable.cpp @@ -193,7 +193,25 @@ void blockstore_impl_t::mark_stable(const obj_ver_id & v, bool forget_dirty) // Allocations and deletions are counted when they're stabilized if (IS_BIG_WRITE(dirty_it->second.state)) { - inode_space_stats[dirty_it->first.oid.inode] += block_size; + int exists = -1; + if (dirty_it != dirty_db.begin()) + { + auto prev_it = dirty_it; + prev_it--; + if (prev_it->first.oid == v.oid) + { + exists = IS_DELETE(prev_it->second.state) ? 0 : 1; + } + } + if (exists == -1) + { + auto clean_it = clean_db.find(v.oid); + exists = clean_it != clean_db.end() ? 1 : 0; + } + if (!exists) + { + inode_space_stats[dirty_it->first.oid.inode] += block_size; + } } else if (IS_DELETE(dirty_it->second.state)) {