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
23{
24 {
25 static struct RDaosRAII {
26 RDaosRAII() { daos_init(); }
27 ~RDaosRAII() { daos_fini(); }
28 } RAII = {};
29 }
30
31 daos_pool_info_t poolInfo{};
32
33 if (daos_label_is_valid(poolId.data()))
34 fPoolLabel = std::string(poolId);
35
36 if (int err = daos_pool_connect(poolId.data(), nullptr, DAOS_PC_RW, &fPoolHandle, &poolInfo, nullptr)) {
37 throw RException(R__FAIL("daos_pool_connect: error: " + std::string(d_errstr(err))));
38 }
39 uuid_copy(fPoolUuid, poolInfo.pi_uuid);
40
41 fEventQueue = std::make_unique<RDaosEventQueue>();
42}
43
45{
46 daos_pool_disconnect(fPoolHandle, nullptr);
47}
48
50{
51 char id[DAOS_UUID_STR_SIZE];
52 uuid_unparse(fPoolUuid, id);
53 return std::string(id);
54}
55
56////////////////////////////////////////////////////////////////////////////////
57
59{
60 char name[kOCNameMaxLength + 1] = {};
62 return std::string{name};
63}
64
66 : fDkey(fua.fDkey),
67 fRequests(fua.fRequests),
68 fIods(std::move(fua.fIods)),
69 fSgls(std::move(fua.fSgls)),
70 fEvent(fua.fEvent)
71{
72 d_iov_set(&fDistributionKey, &fDkey, sizeof(fDkey));
73}
74
76 std::span<RAkeyRequest> rs, bool is_async)
77 : fDkey(d), fRequests(rs)
78{
79 if (is_async)
80 fEvent.emplace();
81
82 fSgls.reserve(fRequests.size());
83 fIods.reserve(fRequests.size());
85
86 for (auto &r : fRequests) {
87 daos_iod_t iod;
88 iod.iod_nr = 1;
89 iod.iod_size =
90 std::accumulate(r.fIovs.begin(), r.fIovs.end(), 0, [](size_t c, d_iov_t &iov) { return c + iov.iov_len; });
91 iod.iod_recxs = nullptr;
93 d_iov_set(&iod.iod_name, const_cast<AttributeKey_t *>(&r.fAkey), sizeof(r.fAkey));
94 fIods.push_back(iod);
95
96 d_sg_list_t sgl;
97 sgl.sg_nr_out = 0;
98 sgl.sg_nr = r.fIovs.size();
99 sgl.sg_iovs = r.fIovs.data();
100 fSgls.push_back(sgl);
101 }
102}
103
105{
106 return fEvent ? &(fEvent.value()) : nullptr;
107}
108
110{
111 if (!cid.IsUnknown())
114
115 if (int err = daos_obj_open(container.fContainerHandle, oid, DAOS_OO_RW, &fObjectHandle, nullptr))
116 throw RException(R__FAIL("daos_obj_open: error: " + std::string(d_errstr(err))));
117}
118
120{
122}
123
125{
127 &args.fDistributionKey, args.fIods.size(), args.fIods.data(), args.fSgls.data(), nullptr,
128 args.GetEventPointer());
129}
130
132{
133 return daos_obj_update(fObjectHandle, DAOS_TX_NONE, 0, &args.fDistributionKey, args.fIods.size(), args.fIods.data(),
134 args.fSgls.data(), args.GetEventPointer());
135}
136
137////////////////////////////////////////////////////////////////////////////////
138
140{
141 if (int ret = daos_eq_create(&fQueue))
142 throw RException(R__FAIL("daos_eq_create: error: " + std::string(d_errstr(ret))));
143}
144
146{
147 daos_eq_destroy(fQueue, 0);
148}
149
151{
152 return daos_event_init(ev_ptr, fQueue, parent_ptr);
153}
154
156{
157 return daos_event_fini(ev_ptr);
158}
159
161{
162 int err;
163 bool flag;
164
165 if ((err = daos_event_parent_barrier(ev_ptr)) < 0)
166 return err;
167
168 if ((err = daos_event_test(ev_ptr, DAOS_EQ_WAIT, &flag)) < 0)
169 return err;
170 return 0;
171}
172
173////////////////////////////////////////////////////////////////////////////////
174
176 std::string_view containerId, bool create)
177 : fPool(pool)
178{
179 daos_cont_info_t containerInfo{};
180
181 // Creating containers supported only with a valid label (not UUID).
182 if (create && daos_label_is_valid(containerId.data())) {
183 fContainerLabel = std::string(containerId);
184 if (int err =
185 daos_cont_create_with_label(fPool->fPoolHandle, fContainerLabel.data(), nullptr, nullptr, nullptr)) {
186 // Ignore error for re-creating existing container.
187 if (err != -DER_EXIST)
188 throw RException(R__FAIL("daos_cont_create_with_label: error: " + std::string(d_errstr(err))));
189 }
190 }
191
192 // Opening containers is supported by valid label or UUID
193 if (int err = daos_cont_open(fPool->fPoolHandle, containerId.data(), DAOS_COO_RW, &fContainerHandle, &containerInfo,
194 nullptr))
195 throw RException(R__FAIL("daos_cont_open: error: " + std::string(d_errstr(err))));
196 uuid_copy(fContainerUuid, containerInfo.ci_uuid);
197}
198
200{
201 daos_cont_close(fContainerHandle, nullptr);
202}
203
205{
206 char id[DAOS_UUID_STR_SIZE];
207 uuid_unparse(fContainerUuid, id);
208 return std::string(id);
209}
210
213 ObjClassId_t cid)
214{
215 std::vector<d_iov_t> iovs(1);
216 d_iov_set(&iovs[0], buffer, length);
217 RDaosObject::RAkeyRequest requests[] = {{akey, std::move(iovs)}};
218 RDaosObject::FetchUpdateArgs args(dkey, requests);
219 return RDaosObject(*this, oid, cid.fCid).Fetch(args);
220}
221
225{
226
227 std::vector<d_iov_t> iovs(1);
228 d_iov_set(&iovs[0], const_cast<void *>(buffer), length);
229 RDaosObject::RAkeyRequest requests[] = {{akey, std::move(iovs)}};
230 RDaosObject::FetchUpdateArgs args(dkey, requests);
231 return RDaosObject(*this, oid, cid.fCid).Update(args);
232}
233
235 MultiObjectRWOperation_t &map, ObjClassId_t cid, int (RDaosObject::*fn)(RDaosObject::FetchUpdateArgs &))
236{
237 using request_t = std::tuple<std::unique_ptr<RDaosObject>, RDaosObject::FetchUpdateArgs>;
238
239 int ret;
240 std::vector<request_t> requests{};
241 requests.reserve(map.size());
242
243 // Initialize parent event used for grouping and waiting for completion of all requests
244 daos_event_t parent_event{};
245 if ((ret = fPool->fEventQueue->InitializeEvent(&parent_event)) < 0)
246 return ret;
247
248 for (auto &[key, batch] : map) {
249 requests.emplace_back(
250 std::make_unique<RDaosObject>(*this, batch.fOid, cid.fCid),
251 RDaosObject::FetchUpdateArgs{batch.fDistributionKey, batch.fDataRequests, /*is_async=*/true});
252
253 if ((ret = fPool->fEventQueue->InitializeEvent(std::get<1>(requests.back()).GetEventPointer(), &parent_event)) <
254 0)
255 return ret;
256
257 // Launch operation
258 if ((ret = (std::get<0>(requests.back()).get()->*fn)(std::get<1>(requests.back()))) < 0)
259 return ret;
260 }
261
262 // Sets parent barrier and waits for all children launched before it.
263 if ((ret = fPool->fEventQueue->WaitOnParentBarrier(&parent_event)) < 0)
264 return ret;
265
266 return fPool->fEventQueue->FinalizeEvent(&parent_event);
267}
#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:290
#define d(i)
Definition RSha256.hxx:102
#define c(i)
Definition RSha256.hxx:101
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h length
char name[80]
Definition TGX11.cxx:110
A RDaosContainer provides read/write access to objects in a given container.
Definition RDaos.hxx:157
RDaosContainer(std::shared_ptr< RDaosPool > pool, std::string_view containerId, bool create=false)
Definition RDaos.cxx:175
RDaosObject::DistributionKey_t DistributionKey_t
Definition RDaos.hxx:160
std::unordered_map< ROidDkeyPair, RWOperation, ROidDkeyPair::Hash > MultiObjectRWOperation_t
Definition RDaos.hxx:231
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:211
std::shared_ptr< RDaosPool > fPool
Definition RDaos.hxx:239
RDaosObject::AttributeKey_t AttributeKey_t
Definition RDaos.hxx:161
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:222
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:234
Provides low-level access to DAOS objects in a container.
Definition RDaos.hxx:87
int Fetch(FetchUpdateArgs &args)
Definition RDaos.cxx:124
int Update(FetchUpdateArgs &args)
Definition RDaos.cxx:131
std::unique_ptr< RDaosEventQueue > fEventQueue
Definition RDaos.hxx:72
RDaosPool(const RDaosPool &)=delete
Base class for all ROOT issued exceptions.
Definition RError.hxx:78
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
#define DER_EXIST
Definition daos.h:285
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)
#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)
@ DAOS_OO_RW
Definition daos.h:185
#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)
int daos_eq_create(daos_handle_t *eqh)
@ DAOS_COND_DKEY_FETCH
Definition daos.h:178
@ DAOS_COND_AKEY_FETCH
Definition daos.h:179
int daos_obj_close(daos_handle_t oh, daos_event_t *ev)
@ DAOS_IOD_SINGLE
Definition daos.h:195
int daos_cont_create_with_label(daos_handle_t poh, const char *label, daos_prop_t *cont_prop, uuid_t *uuid, daos_event_t *ev)
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)
#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:150
static int FinalizeEvent(daos_event_t *ev_ptr)
Release event data from queue.
Definition RDaos.cxx:155
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:160
Contains required information for a single fetch/update operation.
Definition RDaos.hxx:121
std::span< RAkeyRequest > fRequests
fRequests is a sequential container assumed to remain valid throughout the fetch/update operation,...
Definition RDaos.hxx:134
daos_key_t fDistributionKey
The distribution key, as used by the daos_obj_{fetch,update} functions.
Definition RDaos.hxx:137
DistributionKey_t fDkey
A daos_key_t is a type alias of d_iov_t.
Definition RDaos.hxx:131
Contains an attribute key and the associated IOVs for a single scatter-gather I/O request.
Definition RDaos.hxx:112
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
Event and event queue.
Definition daos.h:79
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