29#include <unordered_map>
31using Uuid_t = std::array<unsigned char, 16>;
36 auto seed = std::hash<uint64_t>{}(oid.
lo);
37 seed ^= std::hash<uint64_t>{}(oid.
hi) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
43 template <>
struct hash<
Uuid_t> {
45 return std::hash<std::string_view>{}
46 (std::string_view(
reinterpret_cast<std::string_view::const_pointer
>(u.data()), u.size()));
52{
return (lhs.
lo == rhs.
lo) && (lhs.
hi == rhs.
hi); }
63class RDaosFakeObject {
65 std::mutex fMutexStorage;
66 std::unordered_map<std::string, std::string> fStorage;
75 RDaosFakeObject() =
default;
76 ~RDaosFakeObject() =
default;
84 if (nr != 1 || iods[0].iod_nr !=1 || iods[0].iod_type !=
DAOS_IOD_SINGLE
85 || sgls[0].sg_nr != 1)
88 std::lock_guard<std::mutex> lock(fMutexStorage);
89 auto it = fStorage.find(GetKey(dkey, &iods[0].iod_name));
90 if (it == fStorage.end())
93 std::copy_n(std::begin(it->second), std::min(iov.
iov_buf_len, it->second.size()),
94 reinterpret_cast<char *
>(iov.
iov_buf));
100 if (nr != 1 || iods[0].iod_nr !=1 || iods[0].iod_type !=
DAOS_IOD_SINGLE
101 || sgls[0].sg_nr != 1)
104 std::lock_guard<std::mutex> lock(fMutexStorage);
105 auto &data = fStorage[GetKey(dkey, &iods[0].iod_name)];
117class RDaosFakeContainer {
119 std::mutex fMutexObjects;
120 std::unordered_map<daos_obj_id_t, std::unique_ptr<RDaosFakeObject>> fObjects;
123 RDaosFakeContainer() =
default;
124 ~RDaosFakeContainer() =
default;
126 RDaosFakeObject *GetObject(
daos_obj_id_t oid,
unsigned int mode) {
128 std::lock_guard<std::mutex> lock(fMutexObjects);
129 auto &obj = fObjects[oid];
131 obj = std::make_unique<RDaosFakeObject>();
144 static std::mutex fMutexPools;
145 static std::unordered_map<Uuid_t, std::unique_ptr<RDaosFakePool>> fPools;
147 std::mutex fMutexContainers;
148 std::unordered_map<Uuid_t, std::unique_ptr<RDaosFakeContainer>> fContainers;
153 static RDaosFakePool *GetPool(
const Uuid_t uuid) {
154 std::lock_guard<std::mutex> lock(fMutexPools);
155 auto &pool = fPools[uuid];
157 pool = std::make_unique<RDaosFakePool>();
161 RDaosFakePool() =
default;
162 ~RDaosFakePool() =
default;
164 void CreateContainer(
const Uuid_t uuid) {
165 std::lock_guard<std::mutex> lock(fMutexContainers);
166 fContainers.emplace(uuid, std::make_unique<RDaosFakeContainer>());
169 RDaosFakeContainer *GetContainer(
const Uuid_t uuid) {
170 std::lock_guard<std::mutex> lock(fMutexContainers);
171 auto it = fContainers.find(uuid);
172 return (it != fContainers.end()) ? it->second.get() :
nullptr;
176std::mutex RDaosFakePool::fMutexPools;
177std::unordered_map<Uuid_t, std::unique_ptr<RDaosFakePool>> RDaosFakePool::fPools;
194 Cookie(
void *p) : fPointer(p) {}
195 ~Cookie() { fPointer =
nullptr; }
196 void *GetPointer() {
return fPointer; }
202 template <
typename T>
206 template <
typename T>
207 static inline typename std::add_pointer<T>::type ToPointer(
const daos_handle_t h)
208 {
return reinterpret_cast<typename std::add_pointer<T>::type
>(
209 reinterpret_cast<Cookie *
>(
h.cookie)->GetPointer()); }
212 {
delete reinterpret_cast<Cookie *
>(
h.cookie); }
243 return rc ?
"DER_INVAL" :
"Success";
248 if (strcmp(
name,
"SX") == 0)
return OC_SX;
260 strcpy(
name,
"RP_XSF");
276 auto pool = RDaosHandle::ToPointer<RDaosFakePool>(poh);
280 std::copy_n(uuid, std::tuple_size<Uuid_t>::value, std::begin(u));
281 pool->CreateContainer(u);
292 auto pool = RDaosHandle::ToPointer<RDaosFakePool>(poh);
297 std::copy_n(uuid, std::tuple_size<Uuid_t>::value, std::begin(u));
298 auto cont = pool->GetContainer(u);
301 *coh = RDaosHandle::ToHandle(cont);
308 RDaosHandle::Invalidate(coh);
330 int64_t timeout,
unsigned int nevents,
daos_event_t **events)
362 auto cont = RDaosHandle::ToPointer<RDaosFakeContainer>(coh);
365 auto obj = cont->GetObject(oid, mode);
366 *oh = RDaosHandle::ToHandle(obj);
373 RDaosHandle::Invalidate(oh);
386 auto obj = RDaosHandle::ToPointer<RDaosFakeObject>(oh);
389 return obj->Fetch(dkey, nr, iods, sgls);
400 auto obj = RDaosHandle::ToPointer<RDaosFakeObject>(oh);
403 return obj->Update(dkey, nr, iods, sgls);
421 std::copy_n(uuid, std::tuple_size<Uuid_t>::value, std::begin(u));
422 *poh = RDaosHandle::ToHandle(RDaosFakePool::GetPool(u));
429 RDaosHandle::Invalidate(poh);
typedef void(GLAPIENTRYP _GLUfuncptr)(void)
#define R__LOG_WARNING(...)
TRObject operator()(const T1 &t1) const
This file is a reduced version of daos_xxx.h headers that provides (simplified) declarations for use ...
uint16_t daos_oclass_id_t
@ OC_RP_XSF
Replicated object class which is extremely scalable for fetch.
int daos_oclass_id2name(daos_oclass_id_t oc_id, char *name)
const char * d_errstr(int rc)
int daos_pool_disconnect(daos_handle_t poh, daos_event_t *ev)
void d_rank_list_free(d_rank_list_t *rank_list)
int daos_oclass_name2id(const char *name)
int daos_obj_fetch(daos_handle_t oh, daos_handle_t th, uint64_t flags, daos_key_t *dkey, unsigned int nr, daos_iod_t *iods, d_sg_list_t *sgls, daos_iom_t *ioms, daos_event_t *ev)
int daos_obj_open(daos_handle_t coh, daos_obj_id_t oid, unsigned int mode, daos_handle_t *oh, daos_event_t *ev)
int daos_cont_create(daos_handle_t poh, const uuid_t uuid, daos_prop_t *cont_prop, daos_event_t *ev)
int daos_event_fini(daos_event_t *ev)
int daos_obj_update(daos_handle_t oh, daos_handle_t th, uint64_t flags, daos_key_t *dkey, unsigned int nr, daos_iod_t *iods, d_sg_list_t *sgls, daos_event_t *ev)
int daos_cont_close(daos_handle_t coh, daos_event_t *ev)
int daos_event_init(daos_event_t *ev, daos_handle_t eqh, daos_event_t *parent)
int daos_eq_create(daos_handle_t *eqh)
int daos_cont_open(daos_handle_t poh, const uuid_t uuid, unsigned int flags, daos_handle_t *coh, daos_cont_info_t *info, daos_event_t *ev)
int daos_pool_connect(const uuid_t uuid, const char *grp, const d_rank_list_t *svc, unsigned int flags, daos_handle_t *poh, daos_pool_info_t *info, daos_event_t *ev)
d_rank_list_t * daos_rank_list_parse(const char *str, const char *sep)
int daos_obj_close(daos_handle_t oh, daos_event_t *ev)
std::array< unsigned char, 16 > Uuid_t
int daos_eq_destroy(daos_handle_t eqh, int flags)
int daos_eq_poll(daos_handle_t eqh, int wait_running, int64_t timeout, unsigned int nevents, daos_event_t **events)
bool operator==(const daos_obj_id_t &lhs, const daos_obj_id_t &rhs)
RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
Scatter/gather list for memory buffers.
Generic handle for various DAOS components like container, object, etc.
daos properties, for pool or container