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