From 843b7052d24c6c61e7cf85d73fe748f1af1b2d58 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Sat, 27 Mar 2021 23:12:33 +0300 Subject: [PATCH] Add an assertion when clearing deleted metadata entries, add debug details when freeing blocks --- src/blockstore_flush.cpp | 17 +++++++++++++++-- src/blockstore_init.cpp | 5 ++++- src/blockstore_rollback.cpp | 3 ++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/blockstore_flush.cpp b/src/blockstore_flush.cpp index dc94b2a35..8d9c428d5 100644 --- a/src/blockstore_flush.cpp +++ b/src/blockstore_flush.cpp @@ -482,6 +482,14 @@ resume_1: } if (has_delete) { + clean_disk_entry *new_entry = (clean_disk_entry*)(meta_new.buf + meta_new.pos*bs->clean_entry_size); + if (new_entry->oid.inode != 0 && new_entry->oid != cur.oid) + { + printf("Fatal error (metadata corruption or bug): tried to delete metadata entry %lu (%lx:%lx) while deleting %lx:%lx\n", + clean_loc >> bs->block_order, new_entry->oid.inode, new_entry->oid.stripe, cur.oid.inode, cur.oid.stripe); + exit(1); + } + // zero out new metadata entry memset(meta_new.buf + meta_new.pos*bs->clean_entry_size, 0, bs->clean_entry_size); } else @@ -775,7 +783,10 @@ void journal_flusher_co::update_clean_db() if (old_clean_loc != UINT64_MAX && old_clean_loc != clean_loc) { #ifdef BLOCKSTORE_DEBUG - printf("Free block %lu (new location is %lu)\n", old_clean_loc >> bs->block_order, clean_loc >> bs->block_order); + printf("Free block %lu from %lx:%lx v%lu (new location is %lu)\n", + old_clean_loc >> bs->block_order, + cur.oid.inode, cur.oid.stripe, cur.version, + clean_loc >> bs->block_order); #endif bs->data_alloc->set(old_clean_loc >> bs->block_order, false); } @@ -784,7 +795,9 @@ void journal_flusher_co::update_clean_db() auto clean_it = bs->clean_db.find(cur.oid); bs->clean_db.erase(clean_it); #ifdef BLOCKSTORE_DEBUG - printf("Free block %lu (delete)\n", clean_loc >> bs->block_order); + printf("Free block %lu from %lx:%lx v%lu (delete)\n", + clean_loc >> bs->block_order, + cur.oid.inode, cur.oid.stripe, cur.version); #endif bs->data_alloc->set(clean_loc >> bs->block_order, false); clean_loc = UINT64_MAX; diff --git a/src/blockstore_init.cpp b/src/blockstore_init.cpp index ca3906f4d..4f6a238c8 100644 --- a/src/blockstore_init.cpp +++ b/src/blockstore_init.cpp @@ -111,7 +111,10 @@ void blockstore_init_meta::handle_entries(void* entries, unsigned count, int blo { // free the previous block #ifdef BLOCKSTORE_DEBUG - printf("Free block %lu (new location is %lu)\n", clean_it->second.location >> block_order, done_cnt+i); + printf("Free block %lu from %lx:%lx v%lu (new location is %lu)\n", + clean_it->second.location >> block_order, + clean_it->first.inode, clean_it->first.stripe, clean_it->second.version, + done_cnt+i); #endif bs->data_alloc->set(clean_it->second.location >> block_order, false); } diff --git a/src/blockstore_rollback.cpp b/src/blockstore_rollback.cpp index 20aa1b563..0de305d9e 100644 --- a/src/blockstore_rollback.cpp +++ b/src/blockstore_rollback.cpp @@ -251,7 +251,8 @@ void blockstore_impl_t::erase_dirty(blockstore_dirty_db_t::iterator dirty_start, if (IS_BIG_WRITE(dirty_it->second.state) && dirty_it->second.location != clean_loc) { #ifdef BLOCKSTORE_DEBUG - printf("Free block %lu\n", dirty_it->second.location >> block_order); + printf("Free block %lu from %lx:%lx v%lu\n", dirty_it->second.location >> block_order, + dirty_it->first.oid.inode, dirty_it->first.oid.stripe, dirty_it->first.version); #endif data_alloc->set(dirty_it->second.location >> block_order, false); }