Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RDaos.cxx
Go to the documentation of this file.
1/// \file RDaos.cxx
2/// \ingroup NTuple ROOT7
3/// \author Javier Lopez-Gomez <j.lopez@cern.ch>
4/// \date 2020-11-14
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#include <ROOT/RDaos.hxx>
17#include <ROOT/RError.hxx>
18
19#include <numeric>
20#include <stdexcept>
21
22ROOT::Experimental::Detail::RDaosPool::RDaosPool(std::string_view poolUuid, std::string_view serviceReplicas) {
23 {
24 static struct RDaosRAII {
25 RDaosRAII() { daos_init(); }
26 ~RDaosRAII() { daos_fini(); }
27 } RAII = {};
28 }
29
30 struct SvcRAII {
31 d_rank_list_t *rankList;
32 SvcRAII(std::string_view ranks) { rankList = daos_rank_list_parse(ranks.data(), "_"); }
33 ~SvcRAII() { d_rank_list_free(rankList); }
34 } Svc(serviceReplicas);
35 daos_pool_info_t poolInfo{};
36
37 uuid_parse(poolUuid.data(), fPoolUuid);
38 if (int err = daos_pool_connect(fPoolUuid, nullptr, Svc.rankList, DAOS_PC_RW, &fPoolHandle, &poolInfo, nullptr))
39 throw RException(R__FAIL("daos_pool_connect: error: " + std::string(d_errstr(err))));
40}
41
43 daos_pool_disconnect(fPoolHandle, nullptr);
44}
45
46
47////////////////////////////////////////////////////////////////////////////////
48
49
51{
52 char name[kOCNameMaxLength + 1] = {};
54 return std::string{name};
55}
56
57
59 : fDkey(fua.fDkey), fAkey(fua.fAkey),
60 fIods{fua.fIods[0]}, fSgls{fua.fSgls[0]}, fIovs(std::move(fua.fIovs)), fEv(fua.fEv)
61{
63 d_iov_set(&fIods[0].iod_name, &fAkey, sizeof(fAkey));
64}
65
67(DistributionKey_t &d, AttributeKey_t &a, std::vector<d_iov_t> &v, daos_event_t *p)
68 : fDkey(d), fAkey(a), fIovs(v), fEv(p)
69{
71
72 d_iov_set(&fIods[0].iod_name, &fAkey, sizeof(fAkey));
73 fIods[0].iod_nr = 1;
74 fIods[0].iod_size = std::accumulate(v.begin(), v.end(), 0,
75 [](daos_size_t _a, d_iov_t _b) { return _a + _b.iov_len; });
76 fIods[0].iod_recxs = nullptr;
78
79 fSgls[0].sg_nr_out = 0;
80 fSgls[0].sg_nr = fIovs.size();
81 fSgls[0].sg_iovs = fIovs.data();
82}
83
85 ObjClassId cid)
86{
87 if (!cid.IsUnknown())
88 daos_obj_generate_id(&oid, DAOS_OF_DKEY_UINT64 | DAOS_OF_AKEY_UINT64 /*| DAOS_OF_ARRAY_BYTE*/, cid.fCid, 0);
89 if (int err = daos_obj_open(container.fContainerHandle, oid, DAOS_OO_RW, &fObjectHandle, nullptr))
90 throw RException(R__FAIL("daos_obj_open: error: " + std::string(d_errstr(err))));
91}
92
94{
96}
97
99{
103 &args.fDistributionKey, 1, args.fIods, args.fSgls, nullptr, args.fEv);
104}
105
107{
109 args.fIods, args.fSgls, args.fEv);
110}
111
112
113////////////////////////////////////////////////////////////////////////////////
114
115
117 : fSize(size), fEvs(std::unique_ptr<daos_event_t[]>(new daos_event_t[size]))
118{
120 for (std::size_t i = 0; i < fSize; ++i)
121 daos_event_init(&fEvs[i], fQueue, nullptr);
122}
123
125 for (std::size_t i = 0; i < fSize; ++i)
126 daos_event_fini(&fEvs[i]);
127 daos_eq_destroy(fQueue, 0);
128}
129
131 auto evp = std::unique_ptr<daos_event_t*[]>(new daos_event_t*[fSize]);
132 std::size_t n = fSize;
133 while (n) {
134 int c;
135 if ((c = daos_eq_poll(fQueue, 0, DAOS_EQ_WAIT, n, evp.get())) < 0)
136 break;
137 n -= c;
138 }
139 return n;
140}
141
142
143////////////////////////////////////////////////////////////////////////////////
144
145
147 std::string_view containerUuid, bool create)
148 : fPool(pool)
149{
150 daos_cont_info_t containerInfo{};
151
152 uuid_parse(containerUuid.data(), fContainerUuid);
153 if (create) {
154 if (int err = daos_cont_create(fPool->fPoolHandle, fContainerUuid, nullptr, nullptr))
155 throw RException(R__FAIL("daos_cont_create: error: " + std::string(d_errstr(err))));
156 }
157 if (int err = daos_cont_open(fPool->fPoolHandle, fContainerUuid, DAOS_COO_RW,
158 &fContainerHandle, &containerInfo, nullptr))
159 throw RException(R__FAIL("daos_cont_open: error: " + std::string(d_errstr(err))));
160}
161
163 daos_cont_close(fContainerHandle, nullptr);
164}
165
168 ObjClassId_t cid)
169{
170 std::vector<d_iov_t> iovs(1);
171 d_iov_set(&iovs[0], buffer, length);
172 RDaosObject::FetchUpdateArgs args(dkey, akey, iovs);
173 return RDaosObject(*this, oid, cid.fCid).Fetch(args);
174}
175
178 ObjClassId_t cid)
179{
180 std::vector<d_iov_t> iovs(1);
181 d_iov_set(&iovs[0], const_cast<void *>(buffer), length);
182 RDaosObject::FetchUpdateArgs args(dkey, akey, iovs);
183 return RDaosObject(*this, oid, cid.fCid).Update(args);
184}
size_t fSize
void d_rank_list_free(d_rank_list_t *rank_list)
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
Definition RError.hxx:291
#define d(i)
Definition RSha256.hxx:102
#define c(i)
Definition RSha256.hxx:101
#define a(i)
Definition RSha256.hxx:99
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
char name[80]
Definition TGX11.cxx:110
A RDaosContainer provides read/write access to objects in a given container.
Definition RDaos.hxx:124
std::shared_ptr< RDaosPool > fPool
Definition RDaos.hxx:158
int ReadSingleAkey(void *buffer, std::size_t length, daos_obj_id_t oid, DistributionKey_t dkey, AttributeKey_t akey, ObjClassId_t cid)
Read data from a single object attribute key to the given buffer.
Definition RDaos.cxx:166
RDaosObject::DistributionKey_t DistributionKey_t
Definition RDaos.hxx:127
RDaosObject::AttributeKey_t AttributeKey_t
Definition RDaos.hxx:128
int WriteSingleAkey(const void *buffer, std::size_t length, daos_obj_id_t oid, DistributionKey_t dkey, AttributeKey_t akey, ObjClassId_t cid)
Write the given buffer to a single object attribute key.
Definition RDaos.cxx:176
RDaosContainer(std::shared_ptr< RDaosPool > pool, std::string_view containerUuid, bool create=false)
Definition RDaos.cxx:146
Provides low-level access to DAOS objects in a container.
Definition RDaos.hxx:62
int Update(FetchUpdateArgs &args)
Definition RDaos.cxx:106
int Fetch(FetchUpdateArgs &args)
Definition RDaos.cxx:98
RDaosPool(const RDaosPool &)=delete
Base class for all ROOT issued exceptions.
Definition RError.hxx:114
int daos_oclass_id2name(daos_oclass_id_t oc_id, char *name)
const char * d_errstr(int rc)
#define DAOS_COO_RW
Definition daos.h:253
int daos_pool_disconnect(daos_handle_t poh, daos_event_t *ev)
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)
static void d_iov_set(d_iov_t *iov, void *buf, size_t size)
Definition daos.h:54
@ DAOS_COND_DKEY_FETCH
Definition daos.h:167
@ DAOS_COND_AKEY_FETCH
Definition daos.h:168
int daos_obj_open(daos_handle_t coh, daos_obj_id_t oid, unsigned int mode, daos_handle_t *oh, daos_event_t *ev)
#define DAOS_TX_NONE
Definition daos.h:68
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)
@ DAOS_OO_RW
Definition daos.h:174
int daos_init(void)
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)
static int daos_obj_generate_id(daos_obj_id_t *oid, daos_ofeat_t ofeats, daos_oclass_id_t cid, uint32_t args)
Definition daos.h:204
@ DAOS_OF_AKEY_UINT64
Definition daos.h:162
@ DAOS_OF_DKEY_UINT64
Definition daos.h:161
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)
@ DAOS_REC_ANY
Any record size, it is used by fetch.
Definition daos.h:201
int daos_obj_close(daos_handle_t oh, daos_event_t *ev)
@ DAOS_IOD_SINGLE
Definition daos.h:184
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)
#define DAOS_PC_RW
Definition daos.h:71
#define DAOS_EQ_WAIT
Wait for completion event forever.
Definition daos.h:86
int daos_fini(void)
uint64_t daos_size_t
Definition daos.h:60
const Int_t n
Definition legend1.C:16
int Poll()
Wait for all events in this event queue to complete.
Definition RDaos.cxx:130
Contains required information for a single fetch/update operation.
Definition RDaos.hxx:89
DistributionKey_t fDkey
A daos_key_t is a type alias of d_iov_t.
Definition RDaos.hxx:99
daos_key_t fDistributionKey
The distribution key, as used by the daos_obj_{fetch,update} functions.
Definition RDaos.hxx:103
Wrap around a daos_oclass_id_t.
Definition RDaos.hxx:71
iovec for memory buffer
Definition daos.h:37
uint32_t sg_nr_out
Definition daos.h:50
d_iov_t * sg_iovs
Definition daos.h:51
uint32_t sg_nr
Definition daos.h:49
Container information.
Definition daos.h:256
Event and event queue.
Definition daos.h:77
daos_iod_type_t iod_type
Definition daos.h:189
unsigned int iod_nr
Definition daos.h:191
daos_size_t iod_size
Definition daos.h:190
daos_recx_t * iod_recxs
Definition daos.h:192
Storage pool.
Definition daos.h:273