Skip to content

Commit af72d2f

Browse files
authored
Add isblk alloced and free_blk_now api in dataservice. (#826)
During replay nublocks needs to check if blks are alloced and call free_blk_now to directly free the blks from bitmap cache and not depend on cp flush.
1 parent aba4d00 commit af72d2f

File tree

7 files changed

+51
-11
lines changed

7 files changed

+51
-11
lines changed

conanfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class HomestoreConan(ConanFile):
1111
name = "homestore"
12-
version = "7.3.1"
12+
version = "7.3.2"
1313

1414
homepage = "https://github.com/eBay/Homestore"
1515
description = "HomeStore Storage Engine"

src/include/homestore/blkdata_service.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,22 @@ class BlkDataService {
201201
*/
202202
folly::Future< std::error_code > async_free_blk(MultiBlkId const& bid);
203203

204+
/**
205+
* @brief Frees the specified block IDs immediately. Used during log replay on commit only.
206+
*
207+
* @param bid The block ID to free.
208+
* @return An error code indicating the result of the operation.
209+
*/
210+
std::error_code free_blk_now(MultiBlkId const& bid);
211+
212+
/**
213+
* @brief Check if the blk id is free or not.
214+
*
215+
* @param bid The block ID to check.
216+
* @return Return whether blkid is alloced or not.
217+
*/
218+
bool is_blk_alloced(BlkId const& blkid) const;
219+
204220
/**
205221
* @brief : get the blk size of this data service;
206222
*

src/lib/blkalloc/bitmap_blk_allocator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ sisl::byte_array BitmapBlkAllocator::acquire_underlying_buffer() {
157157
synchronize_rcu();
158158

159159
BLKALLOC_REL_ASSERT(old_alloc_list_ptr == nullptr, "Multiple acquires concurrently?");
160-
return (m_disk_bm->serialize(m_align_size));
160+
// Copy the serialized buffer as cp flush can interefere with incoming I/O's.
161+
// Cp flush happens not only during restart but also during normal I/O's.
162+
return (m_disk_bm->serialize(m_align_size, true /* force_copy */));
161163
}
162164

163165
void BitmapBlkAllocator::release_underlying_buffer() {

src/lib/blkalloc/varsize_blk_allocator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,8 @@ blk_count_t VarsizeBlkAllocator::free_blks_direct(MultiBlkId const& bid) {
698698
auto const do_free = [this](BlkId const& b) {
699699
BlkAllocPortion& portion = blknum_to_portion(b.blk_num());
700700
{
701+
BLKALLOC_LOG(TRACE, "Freeing directly to portion={} blkid={} set_bits_count={}",
702+
blknum_to_portion_num(b.blk_num()), b.to_string(), get_alloced_blk_count());
701703
auto const start_blk_id = portion.get_portion_num() * get_blks_per_portion();
702704
auto const end_blk_id = start_blk_id + get_blks_per_portion() - 1;
703705
auto lock{portion.portion_auto_lock()};
@@ -707,8 +709,6 @@ blk_count_t VarsizeBlkAllocator::free_blks_direct(MultiBlkId const& bid) {
707709
BLKALLOC_REL_ASSERT(m_cache_bm->is_bits_set(b.blk_num(), b.blk_count()), "Expected bits to be set");
708710
m_cache_bm->reset_bits(b.blk_num(), b.blk_count());
709711
}
710-
BLKALLOC_LOG(TRACE, "Freeing directly to portion={} blkid={} set_bits_count={}",
711-
blknum_to_portion_num(b.blk_num()), b.to_string(), get_alloced_blk_count());
712712
return b.blk_count();
713713
};
714714

src/lib/blkdata_svc/blkdata_service.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,23 @@ folly::Future< std::error_code > BlkDataService::async_free_blk(MultiBlkId const
295295
return f;
296296
}
297297

298+
std::error_code BlkDataService::free_blk_now(MultiBlkId const& bids) {
299+
if (is_stopping()) return std::make_error_code(std::errc::operation_canceled);
300+
incr_pending_request_num();
301+
302+
if (!m_vdev->is_blk_exist(bids)) {
303+
decr_pending_request_num();
304+
return std::make_error_code(std::errc::resource_unavailable_try_again);
305+
} else {
306+
auto cpg = hs()->cp_mgr().cp_guard();
307+
m_vdev->free_blk(bids, s_cast< VDevCPContext* >(cpg.context(cp_consumer_t::BLK_DATA_SVC)), true /* free_now */);
308+
}
309+
decr_pending_request_num();
310+
return std::error_code{};
311+
}
312+
313+
bool BlkDataService::is_blk_alloced(BlkId const& blkid) const { return m_vdev->is_blk_alloced(blkid); }
314+
298315
void BlkDataService::start() {
299316
// Register to CP for flush dirty buffers underlying virtual device layer;
300317
hs()->cp_mgr().register_consumer(cp_consumer_t::BLK_DATA_SVC,

src/lib/device/virtual_dev.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,12 @@ BlkAllocStatus VirtualDev::commit_blk(BlkId const& blkid) {
164164
HS_LOG(ERROR, device, "fail to commit_blk: bid {}", blkid.to_string());
165165
return BlkAllocStatus::INVALID_DEV;
166166
}
167-
HS_LOG(DEBUG, device, "commit_blk: bid {}", blkid.to_string());
167+
168+
for (int i = 0; i < blkid.blk_count(); i++) {
169+
auto t = BlkId{blkid.blk_num() + i, 1 /* nblks */, blkid.chunk_num()};
170+
HS_LOG(DEBUG, device, "commit_blk: bid {}", t.to_string());
171+
}
172+
168173
auto const recovering = homestore::hs()->is_initializing();
169174
if (!recovering) {
170175
// in non-recovery mode, if a blk is committed without allocating, it will cause data corruption
@@ -328,9 +333,9 @@ BlkAllocStatus VirtualDev::alloc_blks_from_chunk(blk_count_t nblks, blk_alloc_hi
328333
return status;
329334
}
330335

331-
void VirtualDev::free_blk(BlkId const& bid, VDevCPContext* vctx) {
332-
auto do_free_action = [this](auto const& b, VDevCPContext* vctx) {
333-
if (vctx && (m_allocator_type != blk_allocator_type_t::append)) {
336+
void VirtualDev::free_blk(BlkId const& bid, VDevCPContext* vctx, bool free_now) {
337+
auto do_free_action = [this](auto const& b, VDevCPContext* vctx, bool free_now) {
338+
if (vctx && (m_allocator_type != blk_allocator_type_t::append) && !free_now) {
334339
// We don't want to accumulate here for append blk allocator.
335340
vctx->m_free_blkid_list.push_back(b);
336341
} else {
@@ -348,10 +353,10 @@ void VirtualDev::free_blk(BlkId const& bid, VDevCPContext* vctx) {
348353
MultiBlkId const& mbid = r_cast< MultiBlkId const& >(bid);
349354
auto it = mbid.iterate();
350355
while (auto const b = it.next()) {
351-
do_free_action(*b, vctx);
356+
do_free_action(*b, vctx, free_now);
352357
}
353358
} else {
354-
do_free_action(bid, vctx);
359+
do_free_action(bid, vctx, free_now);
355360
}
356361
}
357362

src/lib/device/virtual_dev.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class VirtualDev {
172172
/// @return Allocation Status
173173
virtual BlkAllocStatus commit_blk(BlkId const& blkid);
174174

175-
virtual void free_blk(BlkId const& b, VDevCPContext* vctx = nullptr);
175+
virtual void free_blk(BlkId const& b, VDevCPContext* vctx = nullptr, bool free_now = false);
176176

177177
/////////////////////// Write API related methods /////////////////////////////
178178
/// @brief Asynchornously write the buffer to the device on a given blkid

0 commit comments

Comments
 (0)