neorados: build new RADOS client using legacy librados::Rados

Client libraries like librbd cannot force the adaptation to neorados
and it would not be ideal to have two effective RADOS cluster
connections for librados and neorados.

The new neorados::RADOS::make_with_librados helper method will
allow neorados to re-use the existing thread pool, MGR, MON, and
objecter already created for librados::Rados.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
Jason Dillaman 2020-07-06 16:08:56 -04:00
parent 83b82bc3d6
commit 2148f22db6
7 changed files with 91 additions and 7 deletions

View File

@ -55,6 +55,7 @@
#include "include/common_fwd.h"
#include "include/buffer.h"
#include "include/rados/librados_fwd.hpp"
#include "common/ceph_time.h"
@ -531,6 +532,8 @@ public:
return init.result.get();
}
static RADOS make_with_librados(librados::Rados& rados);
RADOS(const RADOS&) = delete;
RADOS& operator =(const RADOS&) = delete;

View File

@ -19,6 +19,8 @@ namespace libradosstriper
class RadosStriper;
}
namespace neorados { class RADOS; }
namespace librados {
using ceph::bufferlist;
@ -1503,9 +1505,11 @@ inline namespace v14_2_0 {
callback_t cb_safe)
__attribute__ ((deprecated));
static AioCompletion *aio_create_completion(void *cb_arg, callback_t cb_complete);
friend std::ostream& operator<<(std::ostream &oss, const Rados& r);
private:
friend class neorados::RADOS;
// We don't allow assignment or copying
Rados(const Rados& rhs);
const Rados& operator=(const Rados& rhs);

View File

@ -40,9 +40,12 @@ class MLog;
class Messenger;
class AioCompletionImpl;
namespace neorados { namespace detail { class RadosClient; }}
class librados::RadosClient : public Dispatcher,
public md_config_obs_t
{
friend neorados::detail::RadosClient;
public:
using Dispatcher::cct;
private:

View File

@ -759,6 +759,9 @@ void RADOS::make_with_cct(CephContext* cct,
}
}
RADOS RADOS::make_with_librados(librados::Rados& rados) {
return RADOS{std::make_unique<detail::RadosClient>(rados.client)};
}
RADOS::RADOS() = default;

View File

@ -11,8 +11,8 @@
* Foundation. See file COPYING.
*
*/
#ifndef CEPH_LIBRADOS_RADOSCLIENT_H
#define CEPH_LIBRADOS_RADOSCLIENT_H
#ifndef CEPH_NEORADOS_RADOSIMPL_H
#define CEPH_NEORADOS_RADOSIMPL_H
#include <functional>
#include <memory>
@ -24,6 +24,8 @@
#include "common/ceph_context.h"
#include "common/ceph_mutex.h"
#include "librados/RadosClient.h"
#include "mon/MonClient.h"
#include "mgr/MgrClient.h"
@ -68,9 +70,6 @@ public:
mon_feature_t get_required_monitor_features() const {
return monclient.with_monmap(std::mem_fn(&MonMap::get_required_features));
}
int get_instance_id() const {
return instance_id;
}
};
class Client {
@ -107,13 +106,29 @@ public:
}
int get_instance_id() const override {
return rados->get_instance_id();
return rados->instance_id;
}
private:
std::unique_ptr<RADOS> rados;
};
class RadosClient : public Client {
public:
RadosClient(librados::RadosClient* rados_client)
: Client(rados_client->poolctx, {rados_client->cct},
rados_client->monclient, rados_client->objecter),
rados_client(rados_client) {
}
int get_instance_id() const override {
return rados_client->instance_id;
}
public:
librados::RadosClient* rados_client;
};
} // namespace detail
} // namespace neorados

View File

@ -1,3 +1,12 @@
add_executable(ceph_test_neorados test_neorados.cc)
target_link_libraries(ceph_test_neorados global libneorados
${unittest_libs}
radostest
radostest-cxx
librados
GTest::GTest)
add_executable(ceph_test_neorados_start_stop start_stop.cc)
target_link_libraries(ceph_test_neorados_start_stop global libneorados
${unittest_libs})

View File

@ -0,0 +1,47 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include "include/rados/librados.hpp"
#include "include/neorados/RADOS.hpp"
#include "common/async/blocked_completion.h"
#include "test/librados/test_cxx.h"
#include "gtest/gtest.h"
#include <iostream>
namespace neorados {
class TestNeoRADOS : public ::testing::Test {
public:
TestNeoRADOS() {
}
};
TEST_F(TestNeoRADOS, MakeWithLibRADOS) {
librados::Rados paleo_rados;
auto result = connect_cluster_pp(paleo_rados);
ASSERT_EQ("", result);
auto rados = RADOS::make_with_librados(paleo_rados);
ReadOp op;
bufferlist bl;
op.read(0, 0, &bl);
// provide pool that doesn't exists -- just testing round-trip
ASSERT_THROW(
rados.execute({"dummy-obj"}, std::numeric_limits<int64_t>::max(),
std::move(op), nullptr, ceph::async::use_blocked),
boost::system::system_error);
}
} // namespace neorados
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
int seed = getpid();
std::cout << "seed " << seed << std::endl;
srand(seed);
return RUN_ALL_TESTS();
}