Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mgr: map injector #41260

Merged
merged 7 commits into from Jul 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 27 additions & 7 deletions src/common/options/global.yaml.in
Expand Up @@ -1428,11 +1428,11 @@ options:
- name: mon_initial_members
type: str
level: advanced
fmt_desc: The IDs of initial monitors in a cluster during startup. If
specified, Ceph requires an odd number of monitors to form an
fmt_desc: The IDs of initial monitors in a cluster during startup. If
specified, Ceph requires an odd number of monitors to form an
initial quorum (e.g., 3).
note: A *majority* of monitors in your cluster must be able to reach
each other in order to establish a quorum. You can decrease the initial
note: A *majority* of monitors in your cluster must be able to reach
each other in order to establish a quorum. You can decrease the initial
number of monitors to establish a quorum with this setting.
services:
- mon
Expand Down Expand Up @@ -2633,13 +2633,13 @@ options:
desc: number of PGs for new pools
fmt_desc: The default number of placement groups for a pool. The default
value is the same as ``pg_num`` with ``mkpool``.
long_desc: With default value of `osd_pool_default_pg_autoscale_mode` being
`on` the number of PGs for new pools will start out with 1 pg, unless the
long_desc: With default value of `osd_pool_default_pg_autoscale_mode` being
`on` the number of PGs for new pools will start out with 1 pg, unless the
user specifies the pg_num.
default: 32
services:
- mon
see_also:
see_also:
- osd_pool_default_pg_autoscale_mode
flags:
- runtime
Expand Down Expand Up @@ -6202,3 +6202,23 @@ options:
- spdk
- pmem
- hm_smr
- name: mgr_inject
type: bool
level: dev
desc: Enable/disable injection of fake data in the mgr module
default: false
flags:
- runtime
with_legacy: true
pereman2 marked this conversation as resolved.
Show resolved Hide resolved
services:
- mgr
- name: mgr_inject_num_osds
type: int
level: dev
desc: Number of osds to inject in the mgr module
default: 0
flags:
- runtime
with_legacy: true
pereman2 marked this conversation as resolved.
Show resolved Hide resolved
services:
- mgr
2 changes: 1 addition & 1 deletion src/mgr/ActivePyModules.cc
Expand Up @@ -1225,7 +1225,7 @@ void ActivePyModules::config_notify()
// C++ code, and avoid any potential lock cycles.
dout(15) << "notify (config) " << name << dendl;
// workaround for https://bugs.llvm.org/show_bug.cgi?id=35984
finisher.queue(new LambdaContext([module=module](int r){
finisher.queue(new LambdaContext([module=module](int r){
module->config_notify();
}));
}
Expand Down
1 change: 1 addition & 0 deletions src/mgr/CMakeLists.txt
Expand Up @@ -16,6 +16,7 @@ if(WITH_MGR)
DaemonServer.cc
DaemonState.cc
Gil.cc
Injector.cc
Mgr.cc
MgrStandby.cc
MetricCollector.cc
Expand Down
20 changes: 15 additions & 5 deletions src/mgr/ClusterState.h
Expand Up @@ -21,6 +21,7 @@
#include "osdc/Objecter.h"
#include "mon/MonClient.h"
#include "mon/PGMap.h"
#include "mgr/Injector.h"
#include "mgr/ServiceMap.h"

class MMgrDigest;
Expand Down Expand Up @@ -118,12 +119,21 @@ class ClusterState
return monc->with_monmap(std::forward<Args>(args)...);
}

template<typename... Args>
auto with_osdmap(Args &&... args) const ->
decltype(objecter->with_osdmap(std::forward<Args>(args)...))
bool inject_python_on() const {
return g_conf().get_val<bool>("mgr_inject");
}
template <typename Callback, typename ...Args>
auto with_osdmap(Callback&& cb, Args&& ...args) const ->
decltype(objecter->with_osdmap(std::forward<Callback>(cb),
std::forward<Args>(args)...))
{
ceph_assert(objecter != nullptr);
return objecter->with_osdmap(std::forward<Args>(args)...);
if(inject_python_on()) {
OSDMap *osdmap = Injector::get_osdmap();
return std::forward<Callback>(cb)(*osdmap, std::forward<Args>(args)...);
} else {
ceph_assert(objecter != nullptr);
return objecter->with_osdmap(std::forward<Callback>(cb), std::forward<Args>(args)...);
}
}

// call cb(osdmap, pg_map, ...args) with the appropriate locks
Expand Down
50 changes: 50 additions & 0 deletions src/mgr/Injector.cc
@@ -0,0 +1,50 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "mgr/Injector.h"

#include "osd/OSDMap.h"

#include "PyFormatter.h"

#include "PyUtil.h"

using namespace std;

int64_t Injector::get_num_osds() {
return g_conf().get_val<int64_t>("mgr_inject_num_osds");
}

// OSDMap::dump_osds filters not existent osds so we need
// to set the state so we dump non existent ones too
void Injector::mark_exists_osds(OSDMap *osdmap) {
for (int osd = 0; osd < Injector::get_num_osds(); osd++) {
osdmap->set_state(osd, CEPH_OSD_EXISTS);
}
}

PyObject *Injector::get_python(const std::string &what) {
PyFormatter f;

if (what == "osd_map") {
int64_t num_osds = Injector::get_num_osds();
OSDMap *osdmap = new OSDMap;
uuid_d id = uuid_d();
osdmap->build_simple(g_ceph_context, 1, id, num_osds);
Injector::mark_exists_osds(osdmap);
pereman2 marked this conversation as resolved.
Show resolved Hide resolved
osdmap->dump(&f);
} else {
Py_RETURN_NONE;
}
PyObject *obj = f.get();
return obj;
}

OSDMap *Injector::get_osdmap() {
int64_t num_osds = Injector::get_num_osds();
OSDMap *osdmap = new OSDMap;
uuid_d id = uuid_d();
osdmap->build_simple(g_ceph_context, 1, id, num_osds);
Injector::mark_exists_osds(osdmap);
return osdmap;
}
19 changes: 19 additions & 0 deletions src/mgr/Injector.h
@@ -0,0 +1,19 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#pragma once

#include "osd/OSDMap.h"

#include "PyUtil.h"

class Injector {
private:
static int64_t get_num_osds();
static void mark_exists_osds(OSDMap *osdmap);

public:
static PyObject *get_python(const std::string &what);
static OSDMap *get_osdmap();
};