Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RDaos.hxx
Go to the documentation of this file.
1/// \file ROOT/RDaos.hxx
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-2021, 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#ifndef ROOT7_RDaos
17#define ROOT7_RDaos
18
19#include <string_view>
20#include <ROOT/TypeTraits.hxx>
21#include <ROOT/RSpan.hxx>
22
23#include <daos.h>
24
25#include <cstdint>
26#include <functional>
27#include <memory>
28#include <string>
29#include <type_traits>
30#include <vector>
31#include <optional>
32#include <unordered_map>
33
34#ifndef DAOS_UUID_STR_SIZE
35#define DAOS_UUID_STR_SIZE 37
36#endif
37
38namespace ROOT {
39
40namespace Experimental {
41namespace Internal {
42
47
48 /// \brief Sets event barrier for a given parent event and waits for the completion of all children launched before
49 /// the barrier (must have at least one child).
50 /// \return 0 on success; a DAOS error code otherwise (< 0).
51 static int WaitOnParentBarrier(daos_event_t *ev_ptr);
52 /// \brief Reserve event in queue, optionally tied to a parent event.
53 /// \return 0 on success; a DAOS error code otherwise (< 0).
54 int InitializeEvent(daos_event_t *ev_ptr, daos_event_t *parent_ptr = nullptr) const;
55 /// \brief Release event data from queue.
56 /// \return 0 on success; a DAOS error code otherwise (< 0).
57 static int FinalizeEvent(daos_event_t *ev_ptr);
58};
59
60class RDaosContainer;
61
62/**
63 \class RDaosPool
64 \brief A RDaosPool provides access to containers in a specific DAOS pool.
65 */
66class RDaosPool {
67 friend class RDaosContainer;
68private:
70 uuid_t fPoolUuid{};
71 std::string fPoolLabel{};
72 std::unique_ptr<RDaosEventQueue> fEventQueue;
73
74public:
75 RDaosPool(const RDaosPool&) = delete;
76 RDaosPool(std::string_view poolId);
77 ~RDaosPool();
78
79 RDaosPool& operator=(const RDaosPool&) = delete;
80 std::string GetPoolUuid();
81};
82
83/**
84 \class RDaosObject
85 \brief Provides low-level access to DAOS objects in a container.
86 */
88private:
90public:
91 using DistributionKey_t = std::uint64_t;
92 using AttributeKey_t = std::uint64_t;
93 /// \brief Wrap around a `daos_oclass_id_t`. An object class describes the schema of data distribution
94 /// and protection.
95 struct ObjClassId {
97
99 ObjClassId(const std::string &name) : fCid(daos_oclass_name2id(name.data())) {}
100
101 bool IsUnknown() const { return fCid == OC_UNKNOWN; }
102 std::string ToString() const;
103
104 /// This limit is currently not defined in any header and any call to
105 /// `daos_oclass_id2name()` within DAOS uses a stack-allocated buffer
106 /// whose length varies from 16 to 50, e.g. `https://github.com/daos-stack/daos/blob/master/src/utils/daos_dfs_hdlr.c#L78`.
107 /// As discussed with the development team, 64 is a reasonable limit.
108 static constexpr std::size_t kOCNameMaxLength = 64;
109 };
110
111 /// \brief Contains an attribute key and the associated IOVs for a single scatter-gather I/O request.
114 std::vector<d_iov_t> fIovs{};
115
116 RAkeyRequest(const AttributeKey_t a, const std::vector<d_iov_t> &iovs) : fAkey(a), fIovs(iovs){};
117 RAkeyRequest(const AttributeKey_t a, std::vector<d_iov_t> &&iovs) : fAkey(a), fIovs(std::move(iovs)){};
118 };
119
120 /// \brief Contains required information for a single fetch/update operation.
122 FetchUpdateArgs() = default;
124 FetchUpdateArgs(FetchUpdateArgs &&fua) noexcept;
125 FetchUpdateArgs(DistributionKey_t d, std::span<RAkeyRequest> rs, bool is_async = false);
128
129 /// \brief A `daos_key_t` is a type alias of `d_iov_t`. This type stores a pointer and a length.
130 /// In order for `fDistributionKey` to point to memory that we own, `fDkey` holds the distribution key.
132 /// \brief `fRequests` is a sequential container assumed to remain valid throughout the fetch/update operation,
133 /// holding a list of `RAkeyRequest`-typed elements.
134 std::span<RAkeyRequest> fRequests{};
135
136 /// \brief The distribution key, as used by the `daos_obj_{fetch,update}` functions.
138 std::vector<daos_iod_t> fIods{};
139 std::vector<d_sg_list_t> fSgls{};
140 std::optional<daos_event_t> fEvent{};
141 };
142
143 RDaosObject() = delete;
144 /// Provides low-level access to an object. If `cid` is OC_UNKNOWN, the user is responsible for
145 /// calling `daos_obj_generate_oid()` to fill the reserved bits in `oid` before calling this constructor.
147 ~RDaosObject();
148
149 int Fetch(FetchUpdateArgs &args);
150 int Update(FetchUpdateArgs &args);
151};
152
153/**
154 \class RDaosContainer
155 \brief A RDaosContainer provides read/write access to objects in a given container.
156 */
158 friend class RDaosObject;
159public:
163
164 /// \brief A pair of <object ID, distribution key> that can be used to issue a fetch/update request for multiple
165 /// attribute keys.
169
170 inline bool operator==(const ROidDkeyPair &other) const
171 {
172 return this->oid.lo == other.oid.lo && this->oid.hi == other.oid.hi && this->dkey == other.dkey;
173 }
174
175 struct Hash {
176 auto operator()(const ROidDkeyPair &x) const
177 {
178 /// Implementation borrowed from `boost::hash_combine`. Comparable to initial seeding with `oid.hi` followed
179 /// by two subsequent hash calls for `oid.lo` and `dkey`.
180 auto seed = std::hash<uint64_t>{}(x.oid.hi);
181 seed ^= std::hash<uint64_t>{}(x.oid.lo) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
182 seed ^= std::hash<DistributionKey_t>{}(x.dkey) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
183 return seed;
184 }
185 };
186 };
187
188 /// \brief Describes a read/write operation on multiple attribute keys under the same object ID and distribution key,
189 /// see the `ReadV`/`WriteV` functions.
190 struct RWOperation {
191 RWOperation() = default;
192 RWOperation(daos_obj_id_t o, DistributionKey_t d, std::vector<RDaosObject::RAkeyRequest> &&rs)
193 : fOid(o), fDistributionKey(d), fDataRequests(std::move(rs))
194 {
195 for (unsigned i = 0; i < fDataRequests.size(); i++)
196 fIndices.emplace(fDataRequests[i].fAkey, i);
197 };
198 explicit RWOperation(ROidDkeyPair &k) : fOid(k.oid), fDistributionKey(k.dkey){};
201 std::vector<RDaosObject::RAkeyRequest> fDataRequests{};
202 std::unordered_map<AttributeKey_t, unsigned> fIndices{};
203
205 {
206 auto [it, ret] = fIndices.emplace(attr, fDataRequests.size());
207 unsigned attrIndex = it->second;
208
209 if (attrIndex == fDataRequests.size()) {
210 fDataRequests.emplace_back(attr, std::initializer_list<d_iov_t>{iov});
211 } else {
212 fDataRequests[attrIndex].fIovs.emplace_back(iov);
213 }
214 }
215
216 void Insert(AttributeKey_t attr, std::vector<d_iov_t> &iovs)
217 {
218 auto [it, ret] = fIndices.emplace(attr, fDataRequests.size());
219 unsigned attrIndex = it->second;
220
221 if (attrIndex == fDataRequests.size()) {
222 fDataRequests.emplace_back(attr, iovs);
223 } else {
224 fDataRequests[attrIndex].fIovs.insert(std::end(fDataRequests[attrIndex].fIovs),
225 std::make_move_iterator(std::begin(iovs)),
226 std::make_move_iterator(std::end(iovs)));
227 }
228 }
229 };
230
231 using MultiObjectRWOperation_t = std::unordered_map<ROidDkeyPair, RWOperation, ROidDkeyPair::Hash>;
232
233 std::string GetContainerUuid();
234
235private:
238 std::string fContainerLabel{};
239 std::shared_ptr<RDaosPool> fPool;
241
242 /**
243 \brief Perform a vector read/write operation on different objects.
244 \param map A `MultiObjectRWOperation_t` that describes read/write operations to perform.
245 \param cid The `daos_oclass_id_t` used to qualify OIDs.
246 \param fn Either `&RDaosObject::Fetch` (read) or `&RDaosObject::Update` (write).
247 \return 0 if the operation succeeded; a negative DAOS error number otherwise.
248 */
250 int (RDaosObject::*fn)(RDaosObject::FetchUpdateArgs &));
251
252public:
253 RDaosContainer(std::shared_ptr<RDaosPool> pool, std::string_view containerId, bool create = false);
255
258
259 /**
260 \brief Read data from a single object attribute key to the given buffer.
261 \param buffer The address of a buffer that has capacity for at least `length` bytes.
262 \param length Length of the buffer.
263 \param oid A 128-bit DAOS object identifier.
264 \param dkey The distribution key used for this operation.
265 \param akey The attribute key used for this operation.
266 \param cid An object class ID.
267 \return 0 if the operation succeeded; a negative DAOS error number otherwise.
268 */
269 int ReadSingleAkey(void *buffer, std::size_t length, daos_obj_id_t oid,
271 int ReadSingleAkey(void *buffer, std::size_t length, daos_obj_id_t oid,
273 { return ReadSingleAkey(buffer, length, oid, dkey, akey, fDefaultObjectClass); }
274
275 /**
276 \brief Write the given buffer to a single object attribute key.
277 \param buffer The address of the source buffer.
278 \param length Length of the buffer.
279 \param oid A 128-bit DAOS object identifier.
280 \param dkey The distribution key used for this operation.
281 \param akey The attribute key used for this operation.
282 \param cid An object class ID.
283 \return 0 if the operation succeeded; a negative DAOS error number otherwise.
284 */
285 int WriteSingleAkey(const void *buffer, std::size_t length, daos_obj_id_t oid,
287 int WriteSingleAkey(const void *buffer, std::size_t length, daos_obj_id_t oid,
289 { return WriteSingleAkey(buffer, length, oid, dkey, akey, fDefaultObjectClass); }
290
291 /**
292 \brief Perform a vector read operation on multiple objects.
293 \param map A `MultiObjectRWOperation_t` that describes read operations to perform.
294 \param cid An object class ID.
295 \return Number of operations that could not complete.
296 */
299
300 /**
301 \brief Perform a vector write operation on multiple objects.
302 \param map A `MultiObjectRWOperation_t` that describes write operations to perform.
303 \param cid An object class ID.
304 \return Number of operations that could not complete.
305 */
307 {
308 return VectorReadWrite(map, cid, &RDaosObject::Update);
309 }
311};
312
313} // namespace Internal
314
315} // namespace Experimental
316} // namespace ROOT
317
318#endif
#define d(i)
Definition RSha256.hxx:102
#define a(i)
Definition RSha256.hxx:99
virtual RooAbsTestStatistic * create(const char *name, const char *title, RooAbsReal &real, RooAbsData &data, const RooArgSet &projDeps, Configuration const &cfg)=0
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
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
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
char name[80]
Definition TGX11.cxx:110
A RDaosContainer provides read/write access to objects in a given container.
Definition RDaos.hxx:157
int ReadSingleAkey(void *buffer, std::size_t length, daos_obj_id_t oid, DistributionKey_t dkey, AttributeKey_t akey)
Definition RDaos.hxx:271
void SetDefaultObjectClass(const ObjClassId_t cid)
Definition RDaos.hxx:257
RDaosObject::DistributionKey_t DistributionKey_t
Definition RDaos.hxx:160
int ReadV(MultiObjectRWOperation_t &map)
Definition RDaos.hxx:298
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
int WriteV(MultiObjectRWOperation_t &map, ObjClassId_t cid)
Perform a vector write operation on multiple objects.
Definition RDaos.hxx:306
int WriteV(MultiObjectRWOperation_t &map)
Definition RDaos.hxx:310
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
int ReadV(MultiObjectRWOperation_t &map, ObjClassId_t cid)
Perform a vector read operation on multiple objects.
Definition RDaos.hxx:297
int WriteSingleAkey(const void *buffer, std::size_t length, daos_obj_id_t oid, DistributionKey_t dkey, AttributeKey_t akey)
Definition RDaos.hxx:287
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
A RDaosPool provides access to containers in a specific DAOS pool.
Definition RDaos.hxx:66
std::unique_ptr< RDaosEventQueue > fEventQueue
Definition RDaos.hxx:72
RDaosPool(const RDaosPool &)=delete
RDaosPool & operator=(const RDaosPool &)=delete
This file is a reduced version of daos_xxx.h headers that provides (simplified) declarations for use ...
int daos_oclass_name2id(const char *name)
@ OC_SX
Definition daos.h:129
@ OC_UNKNOWN
Definition daos.h:109
uint16_t daos_oclass_id_t
Definition daos.h:135
Double_t x[n]
Definition legend1.C:17
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
A pair of <object ID, distribution key> that can be used to issue a fetch/update request for multiple...
Definition RDaos.hxx:166
bool operator==(const ROidDkeyPair &other) const
Definition RDaos.hxx:170
Describes a read/write operation on multiple attribute keys under the same object ID and distribution...
Definition RDaos.hxx:190
void Insert(AttributeKey_t attr, std::vector< d_iov_t > &iovs)
Definition RDaos.hxx:216
std::unordered_map< AttributeKey_t, unsigned > fIndices
Definition RDaos.hxx:202
RWOperation(daos_obj_id_t o, DistributionKey_t d, std::vector< RDaosObject::RAkeyRequest > &&rs)
Definition RDaos.hxx:192
void Insert(AttributeKey_t attr, const d_iov_t &iov)
Definition RDaos.hxx:204
std::vector< RDaosObject::RAkeyRequest > fDataRequests
Definition RDaos.hxx:201
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
FetchUpdateArgs & operator=(const FetchUpdateArgs &)=delete
DistributionKey_t fDkey
A daos_key_t is a type alias of d_iov_t.
Definition RDaos.hxx:131
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:108
Contains an attribute key and the associated IOVs for a single scatter-gather I/O request.
Definition RDaos.hxx:112
RAkeyRequest(const AttributeKey_t a, const std::vector< d_iov_t > &iovs)
Definition RDaos.hxx:116
RAkeyRequest(const AttributeKey_t a, std::vector< d_iov_t > &&iovs)
Definition RDaos.hxx:117
iovec for memory buffer
Definition daos.h:37
Event and event queue.
Definition daos.h:79
Generic handle for various DAOS components like container, object, etc.
Definition daos.h:59
uint64_t hi
Definition daos.h:147
uint64_t lo
Definition daos.h:146