Commit 945f646b authored by Eric Cano's avatar Eric Cano
Browse files

Created a connection pool in BackentRados.

The rados operations now round-robin on the contexts to spread the load.
Modified the not yet used thread pool of BackendRados so it does not have its own context
anymore.
parent 853a280b
This diff is collapsed.
......@@ -114,8 +114,12 @@ private:
static std::string createUniqueClientId();
/** This function will lock or die (actually throw, that is) */
void lock(std::string name, uint64_t timeout_us, LockType lockType, const std::string & clientId);
inline void lockBackoff(std::string name, uint64_t timeout_us, LockType lockType, const std::string & clientId);
inline void lockNotify(std::string name, uint64_t timeout_us, LockType lockType, const std::string & clientId);
void lockWithIoContext(std::string name, uint64_t timeout_us, LockType lockType, const std::string& clientId,
librados::IoCtx & radosCtx);
inline void lockBackoff(std::string name, uint64_t timeout_us, LockType lockType,
const std::string & clientId, librados::IoCtx & radosCtx);
inline void lockNotify(std::string name, uint64_t timeout_us, LockType lockType,
const std::string & clientId, librados::IoCtx & radosCtx);
public:
ScopedLock * lockExclusive(std::string name, uint64_t timeout_us=0) override;
......@@ -191,7 +195,8 @@ private:
* Base class for jobs handled by the thread-and-context pool.
*/
class AsyncJob {
virtual void execute(librados::IoCtx & context)=0;
public:
virtual void execute()=0;
virtual ~AsyncJob() {}
};
......@@ -205,17 +210,17 @@ private:
*/
class RadosWorkerThreadAndContext: private cta::threading::Thread {
public:
RadosWorkerThreadAndContext(librados::Rados & cluster, const std::string & pool, const std::string & radosNameSpace,
int threadID, log::Logger & logger);
RadosWorkerThreadAndContext(BackendRados & parentBackend, int threadID, log::Logger & logger);
virtual ~RadosWorkerThreadAndContext();
void start() { cta::threading::Thread::start(); }
void wait() { cta::threading::Thread::wait(); }
private:
librados::IoCtx m_radosCtx;
BackendRados & m_parentBackend;
const int m_threadID;
log::LogContext m_lc;
void run() override;
};
friend RadosWorkerThreadAndContext;
/**
* The container for the threads
......@@ -353,7 +358,10 @@ private:
std::string m_pool;
std::string m_namespace;
librados::Rados m_cluster;
librados::IoCtx m_radosCtx;
std::vector<librados::IoCtx> m_radosCtxPool;
cta::threading::Mutex m_radosCxtIndexMutex;
size_t m_radosCtxIndex=0;
librados::IoCtx & getRadosCtx();
};
}} // end of cta::objectstore
......@@ -18,4 +18,4 @@
// A central switch to enable/disable RADOS based tests.
#pragma once
#undef TEST_RADOS
#define TEST_RADOS
......@@ -19,6 +19,7 @@
#include "BackendTest.hpp"
#include "BackendVFS.hpp"
#include "BackendRados.hpp"
#include "common/log/DummyLogger.hpp"
#include "common/exception/Exception.hpp"
#include "common/Timer.hpp"
#include "BackendRadosTestSwitch.hpp"
......@@ -224,7 +225,8 @@ TEST_P(BackendAbstractTest, ParametersInterface) {
static cta::objectstore::BackendVFS osVFS(__LINE__, __FILE__);
#ifdef TEST_RADOS
static cta::objectstore::BackendRados osRados("tapetest", "tapetest");
static cta::log::DummyLogger dl("");
static cta::objectstore::BackendRados osRados(dl, "tapetest", "tapetest");
INSTANTIATE_TEST_CASE_P(BackendTestRados, BackendAbstractTest, ::testing::Values((cta::objectstore::Backend*)&osRados));
#endif
INSTANTIATE_TEST_CASE_P(BackendTestVFS, BackendAbstractTest, ::testing::Values((cta::objectstore::Backend*)&osVFS));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment