Skip to content

Commit

Permalink
Remove optimization on blk free operation
Browse files Browse the repository at this point in the history
The optimization in blk free may cause the following issue, just remove it and wait for GC handling:
- T1: blob1 is written with LSN 1 — [blkid=10, chunk=1, cnt=5].
- T2: blob1 is deleted with LSN 10, causing the last_append_offset to revert to 10.
- T3: blob2 is written with LSN 11 — [blkid=10, chunk=1, cnt=5].
- T4: The SM is terminated and restarted.
- T5: LSN 1 is replayed, committing block [blkid=10, chunk=1, cnt=5].
- T6: LSN 11 is replayed, committing block [blkid=10, chunk=1, cnt=5].
- T7: LSN 10 is committed, freeing block [blkid=10, chunk=1, cnt=5].
- T8: LSN 11 is committed again, but since the blocks have already been freed, they are not available for LSN 11.
  • Loading branch information
yawzhang authored and Besroy committed Feb 14, 2025
1 parent cabbc4e commit fb28db4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 27 deletions.
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class HomestoreConan(ConanFile):
name = "homestore"
version = "6.6.19"
version = "6.6.20"

homepage = "https://github.com/eBay/Homestore"
description = "HomeStore Storage Engine"
Expand Down
28 changes: 2 additions & 26 deletions src/lib/blkalloc/append_blk_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,33 +127,9 @@ void AppendBlkAllocator::cp_flush(CP* cp) {
}
}

//
// free operation does:
// 1. book keeping "total freeable" space
// 2. if the blk being freed happens to be last block, move last_append_offset backwards accordingly;
//
// free operation books keeping "total freeable" space
void AppendBlkAllocator::free(const BlkId& bid) {
// If we are freeing the last block, just move the offset back
blk_num_t cur_last_offset = m_last_append_offset.load();
auto const input_last_offset = bid.blk_num() + bid.blk_count();
blk_num_t new_last_offset;
bool freeing_in_middle{false};
do {
if (input_last_offset == cur_last_offset) {
new_last_offset = bid.blk_num();
freeing_in_middle = false;
} else {
new_last_offset = cur_last_offset;
freeing_in_middle = true;
}
} while (!m_last_append_offset.compare_exchange_weak(cur_last_offset, new_last_offset));

if (freeing_in_middle) {
// Freeing something in the middle, increment the count
m_freeable_nblks.fetch_add(bid.blk_count());
} else {
m_commit_offset.store(m_last_append_offset.load());
}
m_freeable_nblks.fetch_add(bid.blk_count());
m_is_dirty.store(true);
}

Expand Down

0 comments on commit fb28db4

Please sign in to comment.