Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/lib/index/wb_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,7 @@ void IndexWBCache::recover(sisl::byte_view sb) {
auto cpg = cp_mgr().cp_guard();
auto icp_ctx = r_cast< IndexCPContext* >(cpg.context(cp_consumer_t::INDEX_SVC));
std::map< BlkId, IndexBufferPtr > bufs = icp_ctx->recover(std::move(sb));
bool allocator_state_changed{false};

LOGINFOMOD(wbcache, "Detected unclean shutdown, prior cp={} had to flush {} nodes, recovering... ", icp_ctx->id(),
bufs.size());
Expand Down Expand Up @@ -657,7 +658,8 @@ void IndexWBCache::recover(sisl::byte_view sb) {
was_node_committed(buf->m_up_buffer));
buf->m_node_freed = false;
r_cast< persistent_hdr_t* >(buf->m_bytes)->node_deleted = false;
m_vdev->commit_blk(buf->m_blkid);
auto alloc_status = m_vdev->commit_blk(buf->m_blkid);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to add a HS_REL_ASSERT(alloc_status == BlkAllocStatus::SUCCESS) to not ignore any failure when committing blk, since it will be dangerous to go ahead with an uncommitted blk here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before this PR the result of m_vdev->commit_blk() was ignored and with the flow covered by this PR, unsuccessful status will not trigger the flush. I think fixing the error-path is a different concern and should be documented and implemented separately.

@JacksonYao287 JacksonYao287 Aug 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure。 I am still thinking that since vdev->cp_flush is very light-weight, and for those non-dirtied blk_allocator , it`s no-op.

so, I think it will be simpler for this PR to always call m_vdev->cp_flush() in async_cp_flush(no need to check allocator_state_changed)(even if cp_ctx->id() is not zero when there is not any dirty buffer). it will be just several line changes and can cover all cases

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

allocator_state_changed |= (alloc_status == BlkAllocStatus::SUCCESS);
if (buf->m_node_level) { potential_parent_recovered_bufs.insert(buf); }
prune_from_up_buffer(buf);
}
Expand All @@ -668,7 +670,8 @@ void IndexWBCache::recover(sisl::byte_view sb) {
// Both current and up buffer is committed, we can safely commit the current block
LOGTRACEMOD(wbcache, "New buffer {} and the up buffer {} are committed", buf->to_string(),
buf->m_up_buffer->to_string());
m_vdev->commit_blk(buf->m_blkid);
auto alloc_status = m_vdev->commit_blk(buf->m_blkid);
allocator_state_changed |= (alloc_status == BlkAllocStatus::SUCCESS);
pending_bufs.push_back(buf->m_up_buffer);
} else {
// Up buffer is not committed, we need to repair it first
Expand Down Expand Up @@ -766,6 +769,8 @@ void IndexWBCache::recover(sisl::byte_view sb) {
}
}
}

m_force_vdev_flush.store(allocator_state_changed, std::memory_order_release);
m_in_recovery = false;
m_vdev->recovery_completed();
}
Expand Down Expand Up @@ -847,9 +852,14 @@ folly::Future< bool > IndexWBCache::async_cp_flush(IndexCPContext* cp_ctx) {
// cp_ctx->to_string_dot(filename);
// #endif
if (!cp_ctx->any_dirty_buffers()) {
if (cp_ctx->id() == 0) {
// For the first CP, we need to flush the journal buffer to the meta blk
LOGINFO("First time boot cp, we shall flush the vdev to ensure all cp information is created");
// For the first CP, we need to flush the journal buffer to the meta blk.
// Also after recovery, bitmap could be fixed with no dirty index buffers.
const bool force_vdev_flush =
(cp_ctx->id() == 0) ||
m_force_vdev_flush.exchange(false, std::memory_order_acq_rel);

if (force_vdev_flush) {
LOGINFO("Flush the vdev to ensure all cp information is created");
m_vdev->cp_flush(cp_ctx);
} else {
CP_PERIODIC_LOG(DEBUG, unmove(cp_ctx->id()), "Btree does not have any dirty buffers to flush");
Expand Down
1 change: 1 addition & 0 deletions src/lib/index/wb_cache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class IndexWBCache : public IndexWBCacheBase {
void* m_meta_blk;
bool m_in_recovery{false};
std::unordered_set< uint32_t > m_updated_ordinals;
std::atomic<bool> m_force_vdev_flush{false};

public:
IndexWBCache(const std::shared_ptr< VirtualDev >& vdev, std::pair< meta_blk*, sisl::byte_view > sb,
Expand Down
Loading