Project

General

Profile

Actions

Bug #80655

open
SZ SZ

mgr: DaemonStateIndex::with_device_create leaves empty DeviceState entries in memory forever on no-op or empty update

Bug #80655: mgr: DaemonStateIndex::with_device_create leaves empty DeviceState entries in memory forever on no-op or empty update

Added by Steven Zuraski 3 months ago. Updated 2 months ago.

Status:
Fix Under Review
Priority:
Normal
Category:
ceph-mgr
Target version:
-
Due date:
% Done:

0%

Source:
Backport:
Regression:
No
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:
Tags (freeform):
Merge Commit:
Fixed In:
Released In:
Upkeep Timestamp:

Description

DaemonStateIndex::with_device_create invokes _get_or_create_device(dev) to create and register a DeviceState instance in devices. However, unlike DaemonStateIndex::with_device_write, with_device_create lacks a post-callback empty check.

If a callback does not populate DeviceState (e.g., failed parsing, empty metadata, or no daemons attached), the empty dummy DeviceState remains permanently registered in DaemonStateIndex::devices.

src/mgr/DaemonState.h:

  template<typename Callback, typename...Args>
  void with_device_create(const std::string& dev,
              Callback&& cb, Args&&... args) {
    std::unique_lock l{lock};
    auto d = _get_or_create_device(dev);
    std::forward<Callback>(cb)(*d, std::forward<Args>(args)...);
  }

Compare with with_device_write:

  template<typename Callback, typename...Args>
  bool with_device_write(const std::string& dev,
             Callback&& cb, Args&&... args) {
    std::unique_lock l{lock};
    auto p = devices.find(dev);
    if (p == devices.end()) {
      return false;
    }
    std::forward<Callback>(cb)(*p->second, std::forward<Args>(args)...);
    if (p->second->empty()) {
      _erase_device(p->second);
    }
    return true;
  }

Steps to Reproduce (Unit Test)

TEST_F(DaemonStateTest, LatentBug_with_device_create_StaleEmptyDevice) {
  std::string dev_id = "empty_device_1";
  index->with_device_create(dev_id, [](DeviceState& dev) {
    // Callback leaves the device completely empty
  });

  // Verify whether an empty device was pruned
  bool exists = index->with_device(dev_id, [](DeviceState& dev) {});
  ASSERT_FALSE(exists) << "Empty device was not pruned and leaked in index";
}

Proposed Fix
Add the post-execution empty check to src/mgr/DaemonState.h:

--- a/src/mgr/DaemonState.h
+++ b/src/mgr/DaemonState.h
@@ -223,5 +223,8 @@ public:
     std::unique_lock l{lock};
     auto d = _get_or_create_device(dev);
     std::forward<Callback>(cb)(*d, std::forward<Args>(args)...);
+    if (d->empty()) {
+      _erase_device(d);
+    }
   }
Reference commits:

SZ Updated by Steven Zuraski 2 months ago Actions #1

  • Status changed from In Progress to Fix Under Review
  • Pull request ID set to 72170
Actions

Also available in: PDF Atom