Logo ROOT  
Reference Guide
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
58
60{
61 char name[kOCNameMaxLength + 1] = {};
63 return std::string{name};
64}
65
67 : fDkey(fua.fDkey), fAkeys(fua.fAkeys), fIovs(fua.fIovs), fIods(std::move(fua.fIods)), fSgls(std::move(fua.fSgls)),
68 fEvent(std::move(fua.fEvent))
69{
71}
72
74 std::span<const AttributeKey_t> as,
75 std::span<d_iov_t> vs, bool is_async)
76 : fDkey(d), fAkeys(as), fIovs(vs)
77{
78 if (is_async)
79 fEvent.emplace();
80
81 fSgls.reserve(fAkeys.size());
82 fIods.reserve(fAkeys.size());
84
85 for (unsigned i = 0; i < fAkeys.size(); ++i) {
86 daos_iod_t iod;
87 iod.iod_nr = 1;
88 iod.iod_size = fIovs[i].iov_len;
89 iod.iod_recxs = nullptr;
91 d_iov_set(&iod.iod_name, const_cast<AttributeKey_t *>(&(fAkeys[i])), sizeof(fAkeys[i]));
92 fIods.push_back(iod);
93
94 d_sg_list_t sgl;
95 sgl.sg_nr_out = 0;
96 sgl.sg_nr = 1;
97 sgl.sg_iovs = &fIovs[i];
98 fSgls.push_back(sgl);
99 }
100}
101
103{
104 return fEvent ? &(fEvent.value()) : nullptr;
105}
106
108 ObjClassId cid)
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
119{
121}
122
124{
126 &args.fDistributionKey, args.fAkeys.size(), args.fIods.data(), args.fSgls.data(), nullptr,
127 args.GetEventPointer());
128}
129
131{
132 return daos_obj_update(fObjectHandle, DAOS_TX_NONE, 0, &args.fDistributionKey, args.fAkeys.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
145{
146 daos_eq_destroy(fQueue, 0);
147}
148
150{
151 return daos_event_init(ev_ptr, fQueue, parent_ptr);
152}
153
155{
156 return daos_event_fini(ev_ptr);
157}
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
199 daos_cont_close(fContainerHandle, nullptr);
200}
201
203{
204 char id[DAOS_UUID_STR_SIZE];
205 uuid_unparse(fContainerUuid, id);
206 return std::string(id);
207}
208
211 ObjClassId_t cid)
212{
213 AttributeKey_t akeys[] = {akey};
214 d_iov_t iovs[1];
215 d_iov_set(&iovs[0], buffer, length);
216 RDaosObject::FetchUpdateArgs args(dkey, akeys, iovs);
217 return RDaosObject(*this, oid, cid.fCid).Fetch(args);
218}
219
223{
224 AttributeKey_t akeys[] = {akey};
225 d_iov_t iovs[1];
226 d_iov_set(&iovs[0], const_cast<void *>(buffer), length);
227 RDaosObject::FetchUpdateArgs args(dkey, akeys, iovs);
228 return RDaosObject(*this, oid, cid.fCid).Update(args);
229}
230
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.push_back(std::make_tuple(
247 std::make_unique<RDaosObject>(*this, batch.fOid, cid.fCid),
248 RDaosObject::FetchUpdateArgs{batch.fDistributionKey, batch.fAttributeKeys, batch.fIovs, /*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:291
#define d(i)
Definition: RSha256.hxx:102
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:148
std::shared_ptr< RDaosPool > fPool
Definition: RDaos.hxx:207
RDaosContainer(std::shared_ptr< RDaosPool > pool, std::string_view containerId, bool create=false)
Definition: RDaos.cxx:174
std::unordered_map< ROidDkeyPair, RWOperation, ROidDkeyPair::Hash > MultiObjectRWOperation_t
Definition: RDaos.hxx:199
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:209
RDaosObject::DistributionKey_t DistributionKey_t
Definition: RDaos.hxx:151
RDaosObject::AttributeKey_t AttributeKey_t
Definition: RDaos.hxx:152
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:220
Provides low-level access to DAOS objects in a container.
Definition: RDaos.hxx:86
int Update(FetchUpdateArgs &args)
Definition: RDaos.cxx:130
int Fetch(FetchUpdateArgs &args)
Definition: RDaos.cxx:123
std::unique_ptr< RDaosEventQueue > fEventQueue
Definition: RDaos.hxx:71
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:255
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:284
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
@ DAOS_OO_RW
Definition: daos.h:185
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:244
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:246
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)
@ DAOS_COND_DKEY_FETCH
Definition: daos.h:178
@ DAOS_COND_AKEY_FETCH
Definition: daos.h:179
int daos_eq_create(daos_handle_t *eqh)
@ DAOS_OCH_SHD_DEF
Definition: daos.h:220
@ DAOS_OCH_RDD_DEF
Definition: daos.h:218
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)
basic_string_view< char > string_view
TString as(SEXP s)
Definition: RExports.h:86
int FinalizeEvent(daos_event_t *ev_ptr)
Release event data from queue.
Definition: RDaos.cxx:154
int InitializeEvent(daos_event_t *ev_ptr, daos_event_t *parent_ptr=nullptr)
Reserve event in queue, optionally tied to a parent event.
Definition: RDaos.cxx:149
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:111
DistributionKey_t fDkey
A daos_key_t is a type alias of d_iov_t.
Definition: RDaos.hxx:123
daos_key_t fDistributionKey
The distribution key, as used by the daos_obj_{fetch,update} functions.
Definition: RDaos.hxx:128
std::span< const AttributeKey_t > fAkeys
Definition: RDaos.hxx:124
Wrap around a daos_oclass_id_t.
Definition: RDaos.hxx:94
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:258
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:202
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:203
Storage pool.
Definition: daos.h:272