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), fRequests(fua.fRequests), fIods(std::move(fua.fIods)), fSgls(std::move(fua.fSgls)),
67 fEvent(fua.fEvent)
68{
69 d_iov_set(&fDistributionKey, &fDkey, sizeof(fDkey));
70}
71
73 std::span<RAkeyRequest> rs, bool is_async)
74 : fDkey(d), fRequests(rs)
75{
76 if (is_async)
77 fEvent.emplace();
78
79 fSgls.reserve(fRequests.size());
80 fIods.reserve(fRequests.size());
82
83 for (auto &r : fRequests) {
84 daos_iod_t iod;
85 iod.iod_nr = 1;
86 iod.iod_size =
87 std::accumulate(r.fIovs.begin(), r.fIovs.end(), 0, [](size_t c, d_iov_t &iov) { return c + iov.iov_len; });
88 iod.iod_recxs = nullptr;
90 d_iov_set(&iod.iod_name, const_cast<AttributeKey_t *>(&r.fAkey), sizeof(r.fAkey));
91 fIods.push_back(iod);
92
93 d_sg_list_t sgl;
94 sgl.sg_nr_out = 0;
95 sgl.sg_nr = r.fIovs.size();
96 sgl.sg_iovs = r.fIovs.data();
97 fSgls.push_back(sgl);
98 }
99}
100
102{
103 return fEvent ? &(fEvent.value()) : nullptr;
104}
105
107{
108 if (!cid.IsUnknown())
111
112 if (int err = daos_obj_open(container.fContainerHandle, oid, DAOS_OO_RW, &fObjectHandle, nullptr))
113 throw RException(R__FAIL("daos_obj_open: error: " + std::string(d_errstr(err))));
114}
115
117{
119}
120
122{
124 &args.fDistributionKey, args.fIods.size(), args.fIods.data(), args.fSgls.data(), nullptr,
125 args.GetEventPointer());
126}
127
129{
130 return daos_obj_update(fObjectHandle, DAOS_TX_NONE, 0, &args.fDistributionKey, args.fIods.size(), args.fIods.data(),
131 args.fSgls.data(), args.GetEventPointer());
132}
133
134////////////////////////////////////////////////////////////////////////////////
135
137{
138 if (int ret = daos_eq_create(&fQueue))
139 throw RException(R__FAIL("daos_eq_create: error: " + std::string(d_errstr(ret))));
140}
141
143{
144 daos_eq_destroy(fQueue, 0);
145}
146
148{
149 return daos_event_init(ev_ptr, fQueue, parent_ptr);
150}
151
153{
154 return daos_event_fini(ev_ptr);
155}
156
158{
159 int err;
160 bool flag;
161
162 if ((err = daos_event_parent_barrier(ev_ptr)) < 0)
163 return err;
164
165 if ((err = daos_event_test(ev_ptr, DAOS_EQ_WAIT, &flag)) < 0)
166 return err;
167 return 0;
168}
169
170////////////////////////////////////////////////////////////////////////////////
171
173 std::string_view containerId, bool create)
174 : fPool(pool)
175{
176 daos_cont_info_t containerInfo{};
177
178 // Creating containers supported only with a valid label (not UUID).
179 if (create && daos_label_is_valid(containerId.data())) {
180 fContainerLabel = std::string(containerId);
181 if (int err =
182 daos_cont_create_with_label(fPool->fPoolHandle, fContainerLabel.data(), nullptr, nullptr, nullptr)) {
183 // Ignore error for re-creating existing container.
184 if (err != -DER_EXIST)
185 throw RException(R__FAIL("daos_cont_create_with_label: error: " + std::string(d_errstr(err))));
186 }
187 }
188
189 // Opening containers is supported by valid label or UUID
190 if (int err = daos_cont_open(fPool->fPoolHandle, containerId.data(), DAOS_COO_RW, &fContainerHandle, &containerInfo,
191 nullptr))
192 throw RException(R__FAIL("daos_cont_open: error: " + std::string(d_errstr(err))));
193 uuid_copy(fContainerUuid, containerInfo.ci_uuid);
194}
195
197{
198 daos_cont_close(fContainerHandle, nullptr);
199}
200
202{
203 char id[DAOS_UUID_STR_SIZE];
204 uuid_unparse(fContainerUuid, id);
205 return std::string(id);
206}
207
210 ObjClassId_t cid)
211{
212 std::vector<d_iov_t> iovs(1);
213 d_iov_set(&iovs[0], const_cast<void *>(buffer), length);
214 RDaosObject::RAkeyRequest requests[] = {{akey, std::move(iovs)}};
215 RDaosObject::FetchUpdateArgs args(dkey, requests);
216 return RDaosObject(*this, oid, cid.fCid).Fetch(args);
217}
218
222{
223
224 std::vector<d_iov_t> iovs(1);
225 d_iov_set(&iovs[0], const_cast<void *>(buffer), length);
226 RDaosObject::RAkeyRequest requests[] = {{akey, std::move(iovs)}};
227 RDaosObject::FetchUpdateArgs args(dkey, requests);
228 return RDaosObject(*this, oid, cid.fCid).Update(args);
229}
230
232 int (RDaosObject::*fn)(RDaosObject::FetchUpdateArgs &))
233{
234 using request_t = std::tuple<std::unique_ptr<RDaosObject>, RDaosObject::FetchUpdateArgs>;
235
236 int ret;
237 std::vector<request_t> requests{};
238 requests.reserve(map.size());
239
240 // Initialize parent event used for grouping and waiting for completion of all requests
241 daos_event_t parent_event{};
242 if ((ret = fPool->fEventQueue->InitializeEvent(&parent_event)) < 0)
243 return ret;
244
245 for (auto &[key, batch] : map) {
246 requests.emplace_back(
247 std::make_unique<RDaosObject>(*this, batch.fOid, cid.fCid),
248 RDaosObject::FetchUpdateArgs{batch.fDistributionKey, batch.fDataRequests, /*is_async=*/true});
249
250 if ((ret = fPool->fEventQueue->InitializeEvent(std::get<1>(requests.back()).GetEventPointer(), &parent_event)) <
251 0)
252 return ret;
253
254 // Launch operation
255 if ((ret = (std::get<0>(requests.back()).get()->*fn)(std::get<1>(requests.back()))) < 0)
256 return ret;
257 }
258
259 // Sets parent barrier and waits for all children launched before it.
260 if ((ret = fPool->fEventQueue->WaitOnParentBarrier(&parent_event)) < 0)
261 return ret;
262
263 return fPool->fEventQueue->FinalizeEvent(&parent_event);
264}
#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:303
#define d(i)
Definition RSha256.hxx:102
#define c(i)
Definition RSha256.hxx:101
RooAbsTestStatistic * create(const char *name, const char *title, RooAbsReal &real, RooAbsData &adata, const RooArgSet &projDeps, RooAbsTestStatistic::Configuration const &cfg) override
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
std::shared_ptr< RDaosPool > fPool
Definition RDaos.hxx:239
RDaosContainer(std::shared_ptr< RDaosPool > pool, std::string_view containerId, bool create=false)
Definition RDaos.cxx:172
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:208
RDaosObject::DistributionKey_t DistributionKey_t
Definition RDaos.hxx:160
RDaosObject::AttributeKey_t AttributeKey_t
Definition RDaos.hxx:161
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:231
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:219
Provides low-level access to DAOS objects in a container.
Definition RDaos.hxx:87
int Update(FetchUpdateArgs &args)
Definition RDaos.cxx:128
int Fetch(FetchUpdateArgs &args)
Definition RDaos.cxx:121
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
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)
#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)
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)
@ DAOS_OCH_SHD_DEF
Definition daos.h:221
@ DAOS_OCH_RDD_DEF
Definition daos.h:219
int daos_eq_destroy(daos_handle_t eqh, int flags)
@ DAOS_OO_RW
Definition daos.h:185
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
@ DAOS_COND_DKEY_FETCH
Definition daos.h:178
@ DAOS_COND_AKEY_FETCH
Definition daos.h:179
int daos_fini(void)
int daos_event_parent_barrier(daos_event_t *ev)
static int FinalizeEvent(daos_event_t *ev_ptr)
Release event data from queue.
Definition RDaos.cxx:152
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:157
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:147
Contains required information for a single fetch/update operation.
Definition RDaos.hxx:121
DistributionKey_t fDkey
A daos_key_t is a type alias of d_iov_t.
Definition RDaos.hxx:131
daos_key_t fDistributionKey
The distribution key, as used by the daos_obj_{fetch,update} functions.
Definition RDaos.hxx:137
std::span< RAkeyRequest > fRequests
fRequests is a sequential container assumed to remain valid throughout the fetch/update operation,...
Definition RDaos.hxx:134
Wrap around a daos_oclass_id_t.
Definition RDaos.hxx:95
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