Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
RDaos.cxx
Go to the documentation of this file.
1/// \file RDaos.cxx
2/// \author Javier Lopez-Gomez <j.lopez@cern.ch>
3/// \date 2020-11-14
4/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
5/// is welcome!
6
7/*************************************************************************
8 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
9 * All rights reserved. *
10 * *
11 * For the licensing terms see $ROOTSYS/LICENSE. *
12 * For the list of contributors see $ROOTSYS/README/CREDITS. *
13 *************************************************************************/
14
15#include <ROOT/RDaos.hxx>
16#include <ROOT/RError.hxx>
17
18#include <numeric>
19#include <stdexcept>
20
22{
23 {
24 static struct RDaosRAII {
25 RDaosRAII() { daos_init(); }
26 ~RDaosRAII() { daos_fini(); }
27 } RAII = {};
28 }
29
30 daos_pool_info_t poolInfo{};
31
32 if (daos_label_is_valid(poolId.data()))
33 fPoolLabel = std::string(poolId);
34
35 if (int err = daos_pool_connect(poolId.data(), nullptr, DAOS_PC_RW, &fPoolHandle, &poolInfo, nullptr)) {
36 throw RException(R__FAIL("daos_pool_connect: error: " + std::string(d_errstr(err))));
37 }
38 uuid_copy(fPoolUuid, poolInfo.pi_uuid);
39
40 fEventQueue = std::make_unique<RDaosEventQueue>();
41}
42
47
49{
50 char id[DAOS_UUID_STR_SIZE];
51 uuid_unparse(fPoolUuid, id);
52 return std::string(id);
53}
54
55////////////////////////////////////////////////////////////////////////////////
56
58{
59 char name[kOCNameMaxLength + 1] = {};
61 return std::string{name};
62}
63
65 : fDkey(fua.fDkey),
66 fRequests(fua.fRequests),
67 fIods(std::move(fua.fIods)),
68 fSgls(std::move(fua.fSgls)),
69 fEvent(fua.fEvent)
70{
72}
73
75 std::span<RAkeyRequest> rs, bool is_async)
76 : fDkey(d), fRequests(rs)
77{
78 if (is_async)
79 fEvent.emplace();
80
81 fSgls.reserve(fRequests.size());
82 fIods.reserve(fRequests.size());
84
85 for (auto &r : fRequests) {
86 daos_iod_t iod;
87 iod.iod_nr = 1;
88 iod.iod_size =
89 std::accumulate(r.fIovs.begin(), r.fIovs.end(), 0, [](size_t c, d_iov_t &iov) { return c + iov.iov_len; });
90 iod.iod_recxs = nullptr;
92 d_iov_set(&iod.iod_name, const_cast<AttributeKey_t *>(&r.fAkey), sizeof(r.fAkey));
93 fIods.push_back(iod);
94
95 d_sg_list_t sgl;
96 sgl.sg_nr_out = 0;
97 sgl.sg_nr = r.fIovs.size();
98 sgl.sg_iovs = r.fIovs.data();
99 fSgls.push_back(sgl);
100 }
101}
102
107
109{
110 if (!cid.IsUnknown())
113
114 if (int err = daos_obj_open(container.fContainerHandle, oid, DAOS_OO_RW, &fObjectHandle, nullptr))
115 throw RException(R__FAIL("daos_obj_open: error: " + std::string(d_errstr(err))));
116}
117
122
129
131{
132 return daos_obj_update(fObjectHandle, DAOS_TX_NONE, 0, &args.fDistributionKey, args.fIods.size(), args.fIods.data(),
133 args.fSgls.data(), args.GetEventPointer());
134}
135
136////////////////////////////////////////////////////////////////////////////////
137
139{
140 if (int ret = daos_eq_create(&fQueue))
141 throw RException(R__FAIL("daos_eq_create: error: " + std::string(d_errstr(ret))));
142}
143
148
150{
151 return daos_event_init(ev_ptr, fQueue, parent_ptr);
152}
153
158
160{
161 int err;
162 bool flag;
163
164 if ((err = daos_event_parent_barrier(ev_ptr)) < 0)
165 return err;
166
167 if ((err = daos_event_test(ev_ptr, DAOS_EQ_WAIT, &flag)) < 0)
168 return err;
169 return 0;
170}
171
172////////////////////////////////////////////////////////////////////////////////
173
175 std::string_view containerId, bool create)
176 : fPool(pool)
177{
178 daos_cont_info_t containerInfo{};
179
180 // Creating containers supported only with a valid label (not UUID).
181 if (create && daos_label_is_valid(containerId.data())) {
182 fContainerLabel = std::string(containerId);
183 if (int err =
184 daos_cont_create_with_label(fPool->fPoolHandle, fContainerLabel.data(), nullptr, nullptr, nullptr)) {
185 // Ignore error for re-creating existing container.
186 if (err != -DER_EXIST)
187 throw RException(R__FAIL("daos_cont_create_with_label: error: " + std::string(d_errstr(err))));
188 }
189 }
190
191 // Opening containers is supported by valid label or UUID
192 if (int err = daos_cont_open(fPool->fPoolHandle, containerId.data(), DAOS_COO_RW, &fContainerHandle, &containerInfo,
193 nullptr))
194 throw RException(R__FAIL("daos_cont_open: error: " + std::string(d_errstr(err))));
195 uuid_copy(fContainerUuid, containerInfo.ci_uuid);
196}
197
202
204{
205 char id[DAOS_UUID_STR_SIZE];
206 uuid_unparse(fContainerUuid, id);
207 return std::string(id);
208}
209
212 ObjClassId_t cid)
213{
214 std::vector<d_iov_t> iovs(1);
215 d_iov_set(&iovs[0], buffer, length);
216 RDaosObject::RAkeyRequest requests[] = {{akey, std::move(iovs)}};
217 RDaosObject::FetchUpdateArgs args(dkey, requests);
218 return RDaosObject(*this, oid, cid.fCid).Fetch(args);
219}
220
221int ROOT::Experimental::Internal::RDaosContainer::WriteSingleAkey(const void *buffer, std::size_t length,
224{
225
226 std::vector<d_iov_t> iovs(1);
227 d_iov_set(&iovs[0], const_cast<void *>(buffer), length);
228 RDaosObject::RAkeyRequest requests[] = {{akey, std::move(iovs)}};
229 RDaosObject::FetchUpdateArgs args(dkey, requests);
230 return RDaosObject(*this, oid, cid.fCid).Update(args);
231}
232
235{
236 using request_t = std::tuple<std::unique_ptr<RDaosObject>, RDaosObject::FetchUpdateArgs>;
237
238 int ret;
239 std::vector<request_t> requests{};
240 requests.reserve(map.size());
241
242 // Initialize parent event used for grouping and waiting for completion of all requests
243 daos_event_t parent_event{};
244 if ((ret = fPool->fEventQueue->InitializeEvent(&parent_event)) < 0)
245 return ret;
246
247 for (auto &[key, batch] : map) {
248 requests.emplace_back(
249 std::make_unique<RDaosObject>(*this, batch.fOid, cid.fCid),
250 RDaosObject::FetchUpdateArgs{batch.fDistributionKey, batch.fDataRequests, /*is_async=*/true});
251
252 if ((ret = fPool->fEventQueue->InitializeEvent(std::get<1>(requests.back()).GetEventPointer(), &parent_event)) <
253 0)
254 return ret;
255
256 // Launch operation
257 if ((ret = (std::get<0>(requests.back()).get()->*fn)(std::get<1>(requests.back()))) < 0)
258 return ret;
259 }
260
261 // Sets parent barrier and waits for all children launched before it.
262 if ((ret = fPool->fEventQueue->WaitOnParentBarrier(&parent_event)) < 0)
263 return ret;
264
265 return fPool->fEventQueue->FinalizeEvent(&parent_event);
266}
ROOT::R::TRInterface & r
Definition Object.C:4
#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:299
#define d(i)
Definition RSha256.hxx:102
#define c(i)
Definition RSha256.hxx:101
char * ret
Definition Rotated.cxx:221
char name[80]
Definition TGX11.cxx:148
Double_t err
A RDaosContainer provides read/write access to objects in a given container.
Definition RDaos.hxx:156
RDaosContainer(std::shared_ptr< RDaosPool > pool, std::string_view containerId, bool create=false)
Definition RDaos.cxx:174
RDaosObject::DistributionKey_t DistributionKey_t
Definition RDaos.hxx:159
std::unordered_map< ROidDkeyPair, RWOperation, ROidDkeyPair::Hash > MultiObjectRWOperation_t
Definition RDaos.hxx:230
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:210
std::shared_ptr< RDaosPool > fPool
Definition RDaos.hxx:238
RDaosObject::AttributeKey_t AttributeKey_t
Definition RDaos.hxx:160
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:221
int VectorReadWrite(MultiObjectRWOperation_t &map, ObjClassId_t cid, int(RDaosObject::*fn)(RDaosObject::FetchUpdateArgs &))
Perform a vector read/write operation on different objects.
Definition RDaos.cxx:233
int Fetch(FetchUpdateArgs &args)
Definition RDaos.cxx:123
int Update(FetchUpdateArgs &args)
Definition RDaos.cxx:130
std::unique_ptr< RDaosEventQueue > fEventQueue
Definition RDaos.hxx:71
RDaosPool(const RDaosPool &)=delete
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
STL class.
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:256
@ DAOS_OCH_SHD_DEF
Definition daos.h:221
@ DAOS_OCH_RDD_DEF
Definition daos.h:219
int daos_pool_disconnect(daos_handle_t poh, daos_event_t *ev)
@ DAOS_OT_MULTI_UINT64
Definition daos.h:166
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:50
int daos_obj_open(daos_handle_t coh, daos_obj_id_t oid, unsigned int mode, daos_handle_t *oh, daos_event_t *ev)
@ DAOS_COND_DKEY_FETCH
Definition daos.h:178
@ DAOS_COND_AKEY_FETCH
Definition daos.h:179
#define DAOS_TX_NONE
Definition daos.h:70
int daos_pool_connect(const char *pool, const char *grp, unsigned int flags, daos_handle_t *poh, daos_pool_info_t *info, daos_event_t *ev)
int daos_event_fini(daos_event_t *ev)
#define DAOS_UUID_STR_SIZE
Definition daos.h:245
int daos_init(void)
int daos_obj_generate_oid(daos_handle_t coh, daos_obj_id_t *oid, enum daos_otype_t type, daos_oclass_id_t cid, daos_oclass_hints_t hints, uint32_t args)
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)
static bool daos_label_is_valid(const char *)
Definition daos.h:247
int daos_event_init(daos_event_t *ev, daos_handle_t eqh, daos_event_t *parent)
int daos_event_test(daos_event_t *ev, int64_t timeout, bool *flag)
struct daos_event daos_event_t
Event and event queue.
int daos_eq_create(daos_handle_t *eqh)
int daos_obj_close(daos_handle_t oh, daos_event_t *ev)
@ DAOS_IOD_SINGLE
Definition daos.h:195
int daos_eq_destroy(daos_handle_t eqh, int flags)
int daos_cont_open(daos_handle_t poh, const char *uuid, unsigned int flags, daos_handle_t *coh, daos_cont_info_t *info, daos_event_t *ev)
@ DAOS_OO_RW
Definition daos.h:185
#define DAOS_PC_RW
Definition daos.h:73
#define DAOS_EQ_WAIT
Wait for completion event forever.
Definition daos.h:88
int daos_fini(void)
int daos_event_parent_barrier(daos_event_t *ev)
int InitializeEvent(daos_event_t *ev_ptr, daos_event_t *parent_ptr=nullptr) const
Reserve event in queue, optionally tied to a parent event.
Definition RDaos.cxx:149
static int FinalizeEvent(daos_event_t *ev_ptr)
Release event data from queue.
Definition RDaos.cxx:154
static int WaitOnParentBarrier(daos_event_t *ev_ptr)
Sets event barrier for a given parent event and waits for the completion of all children launched bef...
Definition RDaos.cxx:159
Contains required information for a single fetch/update operation.
Definition RDaos.hxx:120
std::span< RAkeyRequest > fRequests
fRequests is a sequential container assumed to remain valid throughout the fetch/update operation,...
Definition RDaos.hxx:133
daos_key_t fDistributionKey
The distribution key, as used by the daos_obj_{fetch,update} functions.
Definition RDaos.hxx:136
DistributionKey_t fDkey
A daos_key_t is a type alias of d_iov_t.
Definition RDaos.hxx:130
static constexpr std::size_t kOCNameMaxLength
This limit is currently not defined in any header and any call to daos_oclass_id2name() within DAOS u...
Definition RDaos.hxx:107
Contains an attribute key and the associated IOVs for a single scatter-gather I/O request.
Definition RDaos.hxx:111
iovec for memory buffer
Definition daos.h:37
Scatter/gather list for memory buffers.
Definition daos.h:44
uint32_t sg_nr_out
Definition daos.h:46
d_iov_t * sg_iovs
Definition daos.h:47
uint32_t sg_nr
Definition daos.h:45
Container information.
Definition daos.h:259
daos_iod_type_t iod_type
Definition daos.h:200
unsigned int iod_nr
Definition daos.h:203
daos_key_t iod_name
Definition daos.h:199
daos_size_t iod_size
Definition daos.h:201
daos_recx_t * iod_recxs
Definition daos.h:204
Storage pool.
Definition daos.h:273
uuid_t pi_uuid
Definition daos.h:274