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 <ROOT/RStringView.hxx>
20#include <ROOT/TypeTraits.hxx>
21
22#include <daos.h>
23// Avoid depending on `gurt/common.h` as the only required declaration is `d_rank_list_free()`.
24// Also, this header file is known to provide macros that conflict with std::min()/std::max().
25extern "C" void d_rank_list_free(d_rank_list_t *rank_list);
26
27#include <cstdint>
28#include <functional>
29#include <memory>
30#include <string>
31#include <type_traits>
32#include <vector>
33
34namespace ROOT {
35
36namespace Experimental {
37namespace Detail {
38class RDaosContainer;
39
40/**
41 \class RDaosPool
42 \brief A RDaosPool provides access to containers in a specific DAOS pool.
43 */
44class RDaosPool {
45 friend class RDaosContainer;
46private:
48 uuid_t fPoolUuid{};
49
50public:
51 RDaosPool(const RDaosPool&) = delete;
52 RDaosPool(std::string_view poolUuid, std::string_view serviceReplicas);
53 ~RDaosPool();
54
55 RDaosPool& operator=(const RDaosPool&) = delete;
56};
57
58/**
59 \class RDaosObject
60 \brief Provides low-level access to DAOS objects in a container.
61 */
63private:
65public:
66 using DistributionKey_t = std::uint64_t;
67 using AttributeKey_t = std::uint64_t;
68
69 /// \brief Wrap around a `daos_oclass_id_t`. An object class describes the schema of data distribution
70 /// and protection.
71 struct ObjClassId {
73
74 ObjClassId(const ObjClassId&) = default;
76 ObjClassId(const std::string &name) : fCid(daos_oclass_name2id(name.data())) {}
77
78 bool IsUnknown() const { return fCid == OC_UNKNOWN; }
79 std::string ToString() const;
80
81 /// This limit is currently not defined in any header and any call to
82 /// `daos_oclass_id2name()` within DAOS uses a stack-allocated buffer
83 /// whose length varies from 16 to 50, e.g. `https://github.com/daos-stack/daos/blob/master/src/utils/daos_dfs_hdlr.c#L78`.
84 /// As discussed with the development team, 64 is a reasonable limit.
85 static constexpr std::size_t kOCNameMaxLength = 64;
86 };
87
88 /// \brief Contains required information for a single fetch/update operation.
90 FetchUpdateArgs() = default;
93 FetchUpdateArgs(DistributionKey_t &d, AttributeKey_t &a, std::vector<d_iov_t> &v, daos_event_t *p = nullptr);
95
96 /// \brief A `daos_key_t` is a type alias of `d_iov_t`. This type stores a pointer and a length.
97 /// In order for `fDistributionKey` and `fIods` to point to memory that we own, `fDkey` and
98 /// `fAkey` store a copy of the distribution and attribute key, respectively.
101
102 /// \brief The distribution key, as used by the `daos_obj_{fetch,update}` functions.
106 std::vector<d_iov_t> fIovs{};
107 daos_event_t *fEv = nullptr;
108 };
109
110 RDaosObject() = delete;
111 /// Provides low-level access to an object. If `cid` is OC_UNKNOWN, the user is responsible for
112 /// calling `daos_obj_generate_id()` to fill the reserved bits in `oid` before calling this constructor.
114 ~RDaosObject();
115
116 int Fetch(FetchUpdateArgs &args);
117 int Update(FetchUpdateArgs &args);
118};
119
120/**
121 \class RDaosContainer
122 \brief A RDaosContainer provides read/write access to objects in a given container.
123 */
125 friend class RDaosObject;
126public:
130
131 /// \brief Describes a read/write operation on multiple objects; see the `ReadV`/`WriteV` functions.
132 struct RWOperation {
133 RWOperation() = default;
139 std::vector<d_iov_t> fIovs{};
140 };
141
142private:
144 std::size_t fSize;
145 std::unique_ptr<daos_event_t[]> fEvs;
147 DaosEventQueue(std::size_t size);
149 /**
150 \brief Wait for all events in this event queue to complete.
151 \return Number of events still in the queue. This should be 0 on success.
152 */
153 int Poll();
154 };
155
158 std::shared_ptr<RDaosPool> fPool;
160
161 /**
162 \brief Perform a vector read/write operation on different objects.
163 \param vec A `std::vector<RWOperation>` that describes read/write operations to perform.
164 \param cid The `daos_oclass_id_t` used to qualify OIDs.
165 \param fn Either `std::mem_fn<&RDaosObject::Fetch>` (read) or `std::mem_fn<&RDaosObject::Update>` (write).
166 \return Number of requests that did not complete; this should be 0 after a successful call.
167 */
168 template <typename Fn>
169 int VectorReadWrite(std::vector<RWOperation> &vec, ObjClassId_t cid, Fn fn) {
170 int ret;
171 DaosEventQueue eventQueue(vec.size());
172 {
173 std::vector<std::tuple<std::unique_ptr<RDaosObject>, RDaosObject::FetchUpdateArgs>> requests{};
174 requests.reserve(vec.size());
175 for (size_t i = 0; i < vec.size(); ++i) {
176 requests.push_back(std::make_tuple(std::unique_ptr<RDaosObject>(new RDaosObject(*this, vec[i].fOid, cid.fCid)),
178 vec[i].fDistributionKey, vec[i].fAttributeKey,
179 vec[i].fIovs, &eventQueue.fEvs[i]}));
180 fn(std::get<0>(requests.back()).get(), std::get<1>(requests.back()));
181 }
182 ret = eventQueue.Poll();
183 }
184 return ret;
185 }
186
187public:
188 RDaosContainer(std::shared_ptr<RDaosPool> pool, std::string_view containerUuid, bool create = false);
190
193
194 /**
195 \brief Read data from a single object attribute key to the given buffer.
196 \param buffer The address of a buffer that has capacity for at least `length` bytes.
197 \param length Length of the buffer.
198 \param oid A 128-bit DAOS object identifier.
199 \param dkey The distribution key used for this operation.
200 \param akey The attribute key used for this operation.
201 \param cid An object class ID.
202 \return 0 if the operation succeeded; a negative DAOS error number otherwise.
203 */
204 int ReadSingleAkey(void *buffer, std::size_t length, daos_obj_id_t oid,
206 int ReadSingleAkey(void *buffer, std::size_t length, daos_obj_id_t oid,
208 { return ReadSingleAkey(buffer, length, oid, dkey, akey, fDefaultObjectClass); }
209
210 /**
211 \brief Write the given buffer to a single object attribute key.
212 \param buffer The address of the source buffer.
213 \param length Length of the buffer.
214 \param oid A 128-bit DAOS object identifier.
215 \param dkey The distribution key used for this operation.
216 \param akey The attribute key used for this operation.
217 \param cid An object class ID.
218 \return 0 if the operation succeeded; a negative DAOS error number otherwise.
219 */
220 int WriteSingleAkey(const void *buffer, std::size_t length, daos_obj_id_t oid,
222 int WriteSingleAkey(const void *buffer, std::size_t length, daos_obj_id_t oid,
224 { return WriteSingleAkey(buffer, length, oid, dkey, akey, fDefaultObjectClass); }
225
226 /**
227 \brief Perform a vector read operation on (possibly) multiple objects.
228 \param vec A `std::vector<RWOperation>` that describes read operations to perform.
229 \param cid An object class ID.
230 \return Number of operations that could not complete.
231 */
232 int ReadV(std::vector<RWOperation> &vec, ObjClassId_t cid)
233 { return VectorReadWrite(vec, cid, std::mem_fn(&RDaosObject::Fetch)); }
234 int ReadV(std::vector<RWOperation> &vec) { return ReadV(vec, fDefaultObjectClass); }
235
236 /**
237 \brief Perform a vector write operation on (possibly) multiple objects.
238 \param vec A `std::vector<RWOperation>` that describes write operations to perform.
239 \param cid An object class ID.
240 \return Number of operations that could not complete.
241 */
242 int WriteV(std::vector<RWOperation> &vec, ObjClassId_t cid)
243 { return VectorReadWrite(vec, cid, std::mem_fn(&RDaosObject::Update)); }
244 int WriteV(std::vector<RWOperation> &vec) { return WriteV(vec, fDefaultObjectClass); }
245};
246
247} // namespace Detail
248
249} // namespace Experimental
250} // namespace ROOT
251
252#endif
void d_rank_list_free(d_rank_list_t *rank_list)
#define d(i)
Definition RSha256.hxx:102
#define a(i)
Definition RSha256.hxx:99
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
char name[80]
Definition TGX11.cxx:110
A RDaosContainer provides read/write access to objects in a given container.
Definition RDaos.hxx:124
void SetDefaultObjectClass(const ObjClassId_t cid)
Definition RDaos.hxx:192
std::shared_ptr< RDaosPool > fPool
Definition RDaos.hxx:158
ObjClassId_t GetDefaultObjectClass() const
Definition RDaos.hxx:191
int WriteSingleAkey(const void *buffer, std::size_t length, daos_obj_id_t oid, DistributionKey_t dkey, AttributeKey_t akey)
Definition RDaos.hxx:222
int ReadV(std::vector< RWOperation > &vec)
Definition RDaos.hxx:234
int WriteV(std::vector< RWOperation > &vec)
Definition RDaos.hxx:244
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:166
RDaosObject::ObjClassId ObjClassId_t
Definition RDaos.hxx:129
RDaosObject::DistributionKey_t DistributionKey_t
Definition RDaos.hxx:127
int ReadSingleAkey(void *buffer, std::size_t length, daos_obj_id_t oid, DistributionKey_t dkey, AttributeKey_t akey)
Definition RDaos.hxx:206
RDaosObject::AttributeKey_t AttributeKey_t
Definition RDaos.hxx:128
int WriteV(std::vector< RWOperation > &vec, ObjClassId_t cid)
Perform a vector write operation on (possibly) multiple objects.
Definition RDaos.hxx:242
int ReadV(std::vector< RWOperation > &vec, ObjClassId_t cid)
Perform a vector read operation on (possibly) multiple objects.
Definition RDaos.hxx:232
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:176
int VectorReadWrite(std::vector< RWOperation > &vec, ObjClassId_t cid, Fn fn)
Perform a vector read/write operation on different objects.
Definition RDaos.hxx:169
Provides low-level access to DAOS objects in a container.
Definition RDaos.hxx:62
int Update(FetchUpdateArgs &args)
Definition RDaos.cxx:106
int Fetch(FetchUpdateArgs &args)
Definition RDaos.cxx:98
A RDaosPool provides access to containers in a specific DAOS pool.
Definition RDaos.hxx:44
RDaosPool & operator=(const RDaosPool &)=delete
RDaosPool(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)
uint16_t daos_oclass_id_t
Definition daos.h:133
@ OC_SX
Definition daos.h:127
@ OC_UNKNOWN
Definition daos.h:107
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
int Poll()
Wait for all events in this event queue to complete.
Definition RDaos.cxx:130
Describes a read/write operation on multiple objects; see the ReadV/WriteV functions.
Definition RDaos.hxx:132
RWOperation(daos_obj_id_t o, DistributionKey_t d, AttributeKey_t a, std::vector< d_iov_t > &v)
Definition RDaos.hxx:134
Contains required information for a single fetch/update operation.
Definition RDaos.hxx:89
FetchUpdateArgs & operator=(const FetchUpdateArgs &)=delete
DistributionKey_t fDkey
A daos_key_t is a type alias of d_iov_t.
Definition RDaos.hxx:99
daos_key_t fDistributionKey
The distribution key, as used by the daos_obj_{fetch,update} functions.
Definition RDaos.hxx:103
Wrap around a daos_oclass_id_t.
Definition RDaos.hxx:71
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:85
iovec for memory buffer
Definition daos.h:37
Scatter/gather list for memory buffers.
Definition daos.h:48
Event and event queue.
Definition daos.h:77
Generic handle for various DAOS components like container, object, etc.
Definition daos.h:63