From 7a4e7475366b13ea78962424e5e4cb27bfdc03ee Mon Sep 17 00:00:00 2001 From: Laura Flores Date: Wed, 22 Dec 2021 23:09:25 +0000 Subject: [PATCH] mgr: expose rocksdb version number in the mgr module It is only necessary here to link the rocksdb include directory since the mgr simply needs access to the rocksdb version numbers. Signed-off-by: Laura Flores Co-authored-by: Kefu Chai Co-authored-by: Adam Kupczyk --- src/CMakeLists.txt | 13 +++++++------ src/mgr/ActivePyModules.cc | 25 ++++++++++++++++++------- src/mgr/ActivePyModules.h | 1 + src/mgr/BaseMgrModule.cc | 10 ++++++++++ src/mgr/CMakeLists.txt | 2 ++ src/pybind/mgr/ceph_module.pyi | 1 + src/pybind/mgr/mgr_module.py | 8 ++++++++ 7 files changed, 47 insertions(+), 13 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7c1a9fe89f6..1157df00a19 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -593,6 +593,13 @@ if(WITH_LIBRADOSSTRIPER) add_subdirectory(libradosstriper) endif() +# make rocksdb statically + +if(NOT WITH_SYSTEM_ROCKSDB) + include(BuildRocksDB) + build_rocksdb() +endif(NOT WITH_SYSTEM_ROCKSDB) + if(WITH_MGR) add_subdirectory(mgr) endif() @@ -630,12 +637,6 @@ target_link_libraries(ceph-mon mon os global-static ceph-common install(TARGETS ceph-mon DESTINATION bin) # OSD/ObjectStore -# make rocksdb statically - -if(NOT WITH_SYSTEM_ROCKSDB) - include(BuildRocksDB) - build_rocksdb() -endif(NOT WITH_SYSTEM_ROCKSDB) include(TestBigEndian) test_big_endian(CEPH_BIG_ENDIAN) diff --git a/src/mgr/ActivePyModules.cc b/src/mgr/ActivePyModules.cc index 0c08f3a02b5..1e9b932daa9 100644 --- a/src/mgr/ActivePyModules.cc +++ b/src/mgr/ActivePyModules.cc @@ -14,27 +14,29 @@ // Include this first to get python headers earlier #include "Gil.h" +#include "ActivePyModules.h" + +#include + #include "common/errno.h" #include "include/stringify.h" -#include "PyFormatter.h" - -#include "osd/OSDMap.h" #include "mon/MonMap.h" +#include "osd/OSDMap.h" #include "osd/osd_types.h" #include "mgr/MgrContext.h" #include "mgr/TTLCache.h" #include "mgr/mgr_perf_counters.h" +#include "DaemonKey.h" +#include "DaemonServer.h" +#include "mgr/MgrContext.h" +#include "PyFormatter.h" // For ::mgr_store_prefix #include "PyModule.h" #include "PyModuleRegistry.h" #include "PyUtil.h" -#include "ActivePyModules.h" -#include "DaemonKey.h" -#include "DaemonServer.h" - #define dout_context g_ceph_context #define dout_subsys ceph_subsys_mgr #undef dout_prefix @@ -1025,6 +1027,15 @@ PyObject* ActivePyModules::get_perf_schema_python( return f.get(); } +PyObject* ActivePyModules::get_rocksdb_version() +{ + std::string version = std::to_string(ROCKSDB_MAJOR) + "." + + std::to_string(ROCKSDB_MINOR) + "." + + std::to_string(ROCKSDB_PATCH); + + return PyUnicode_FromString(version.c_str()); +} + PyObject *ActivePyModules::get_context() { auto l = without_gil([&] { diff --git a/src/mgr/ActivePyModules.h b/src/mgr/ActivePyModules.h index 3054fa3a277..2547c256538 100644 --- a/src/mgr/ActivePyModules.h +++ b/src/mgr/ActivePyModules.h @@ -101,6 +101,7 @@ public: PyObject *get_perf_schema_python( const std::string &svc_type, const std::string &svc_id); + PyObject *get_rocksdb_version(); PyObject *get_context(); PyObject *get_osdmap(); /// @note @c fct is not allowed to acquire locks when holding GIL diff --git a/src/mgr/BaseMgrModule.cc b/src/mgr/BaseMgrModule.cc index bd6475a2bed..4c905a6f79e 100644 --- a/src/mgr/BaseMgrModule.cc +++ b/src/mgr/BaseMgrModule.cc @@ -670,6 +670,13 @@ get_perf_schema(BaseMgrModule *self, PyObject *args) return self->py_modules->get_perf_schema_python(type_str, svc_id); } +static PyObject* +ceph_get_rocksdb_version(BaseMgrModule *self) +{ + return self->py_modules->get_rocksdb_version(); +} + + static PyObject * ceph_get_osdmap(BaseMgrModule *self, PyObject *args) { @@ -1446,6 +1453,9 @@ PyMethodDef BaseMgrModule_methods[] = { {"_ceph_get_perf_schema", (PyCFunction)get_perf_schema, METH_VARARGS, "Get the performance counter schema"}, + {"_ceph_get_rocksdb_version", (PyCFunction)ceph_get_rocksdb_version, METH_NOARGS, + "Get the current RocksDB version number"}, + {"_ceph_log", (PyCFunction)ceph_log, METH_VARARGS, "Emit a (local) log message"}, diff --git a/src/mgr/CMakeLists.txt b/src/mgr/CMakeLists.txt index d688030343e..a53d1d8c2a0 100644 --- a/src/mgr/CMakeLists.txt +++ b/src/mgr/CMakeLists.txt @@ -37,6 +37,8 @@ if(WITH_MGR) if(WITH_LIBCEPHSQLITE) target_link_libraries(ceph-mgr cephsqlite SQLite3::SQLite3) endif() + target_include_directories(ceph-mgr PRIVATE + $) target_link_libraries(ceph-mgr osdc client heap_profiler global-static ceph-common diff --git a/src/pybind/mgr/ceph_module.pyi b/src/pybind/mgr/ceph_module.pyi index 4794d9c3611..ca323870e58 100644 --- a/src/pybind/mgr/ceph_module.pyi +++ b/src/pybind/mgr/ceph_module.pyi @@ -71,6 +71,7 @@ class BaseMgrModule(object): def _ceph_get_server(self, hostname: Optional[str]) -> Union[ServerInfoT, List[ServerInfoT]]: ... def _ceph_get_perf_schema(self, svc_type: str, svc_name: str) -> Dict[str, Any]: ... + def _ceph_get_rocksdb_version(self) -> str: ... def _ceph_get_counter(self, svc_type: str, svc_name: str, path: str) -> Dict[str, List[Tuple[float, int]]]: ... def _ceph_get_latest_counter(self, svc_type, svc_name, path): ... def _ceph_get_metadata(self, svc_type, svc_id): ... diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index b9c86be7c3e..30cd1fc5e4b 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -1452,6 +1452,14 @@ class MgrModule(ceph_module.BaseMgrModule, MgrModuleLoggingMixin): """ return self._ceph_get_perf_schema(svc_type, svc_name) + def get_rocksdb_version(self) -> str: + """ + Called by the plugin to fetch the latest RocksDB version number. + + :return: str representing the major, minor, and patch RocksDB version numbers + """ + return self._ceph_get_rocksdb_version() + @API.expose def get_counter(self, svc_type: str, -- 2.47.3