Skip to content

Commit 89deeb0

Browse files
jalopezg-gitjblomer
authored andcommitted
[ntuple] DAOS support: applied minor changes from the code review
1 parent b5e8f43 commit 89deeb0

File tree

6 files changed

+85
-46
lines changed

6 files changed

+85
-46
lines changed

tree/ntuple/v7/inc/ROOT/RDaos.hxx

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/// is welcome!
77

88
/*************************************************************************
9-
* Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
9+
* Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
1010
* All rights reserved. *
1111
* *
1212
* For the licensing terms see $ROOTSYS/LICENSE. *
@@ -43,13 +43,14 @@ class RDaosPool {
4343
friend class RDaosContainer;
4444
private:
4545
daos_handle_t fPoolHandle{};
46-
daos_pool_info_t fPoolInfo{};
4746
uuid_t fPoolUuid{};
4847

4948
public:
50-
RDaosPool() = delete;
49+
RDaosPool(const RDaosPool&) = delete;
5150
RDaosPool(std::string_view poolUuid, std::string_view serviceReplicas);
5251
~RDaosPool();
52+
53+
RDaosPool& operator=(const RDaosPool&) = delete;
5354
};
5455

5556
/**
@@ -85,9 +86,15 @@ public:
8586
FetchUpdateArgs(const FetchUpdateArgs&) = delete;
8687
FetchUpdateArgs(FetchUpdateArgs&& fua);
8788
FetchUpdateArgs(DistributionKey_t &d, AttributeKey_t &a, std::vector<d_iov_t> &v, daos_event_t *p = nullptr);
89+
FetchUpdateArgs& operator=(const FetchUpdateArgs&) = delete;
8890

91+
/// \brief A `daos_key_t` is a type alias of `d_iov_t`. This type stores a pointer and a length.
92+
/// In order for `fDistributionKey` and `fIods` to point to memory that we own, `fDkey` and
93+
/// `fAkey` store a copy of the distribution and attribute key, respectively.
8994
DistributionKey_t fDkey{};
9095
AttributeKey_t fAkey{};
96+
97+
/// \brief The distribution key, as used by the `daos_obj_{fetch,update}` functions.
9198
daos_key_t fDistributionKey{};
9299
daos_iod_t fIods[1] = {};
93100
d_sg_list_t fSgls[1] = {};
@@ -130,19 +137,24 @@ private:
130137
daos_handle_t fQueue;
131138
DaosEventQueue(std::size_t size);
132139
~DaosEventQueue();
140+
/**
141+
\brief Wait for all events in this event queue to complete.
142+
\return Number of events still in the queue. This should be 0 on success.
143+
*/
133144
int Poll();
134145
};
135146

136147
daos_handle_t fContainerHandle{};
137-
daos_cont_info_t fContainerInfo{};
138148
uuid_t fContainerUuid{};
139149
std::shared_ptr<RDaosPool> fPool;
140150
/// OID that will be used by the next call to `WriteObject(const void *, std::size_t, DKeyT, AKeyT)`.
141151
daos_obj_id_t fSequentialWrOid{};
142152

143-
/** \brief Perform a vector read/write operation on different objects.
153+
/**
154+
\brief Perform a vector read/write operation on different objects.
144155
\param vec A `std::vector<RWOperation>` that describes read/write operations to perform.
145156
\param fn Either `std::mem_fn<&RDaosObject::Fetch>` (read) or `std::mem_fn<&RDaosObject::Update>` (write).
157+
\return Number of requests that did not complete; this should be 0 after a successful call.
146158
*/
147159
template <typename Fn, typename DKeyT, typename AKeyT>
148160
int VectorReadWrite(std::vector<RWOperation<DKeyT, AKeyT>> &vec, Fn fn) {
@@ -168,7 +180,15 @@ public:
168180
RDaosContainer(std::shared_ptr<RDaosPool> pool, std::string_view containerUuid, bool create = false);
169181
~RDaosContainer();
170182

171-
/** \brief Read data from an object in this container to the given buffer. */
183+
/**
184+
\brief Read data from an object in this container to the given buffer.
185+
\param oid A 128-bit DAOS object identifier.
186+
\param buffer The address of a buffer that has capacity for at least `length` bytes.
187+
\param length Length of the buffer.
188+
\param dkey The distribution key used for this operation.
189+
\param akey The attribute key used for this operation.
190+
\return 0 if the operation succeeded; a negative DAOS error number otherwise.
191+
*/
172192
template <typename DKeyT, typename AKeyT>
173193
int ReadObject(daos_obj_id_t oid, void *buffer, std::size_t length, DKeyT dkey, AKeyT akey)
174194
{
@@ -178,7 +198,15 @@ public:
178198
return RDaosObject<DKeyT, AKeyT>(*this, oid).Fetch(args);
179199
}
180200

181-
/** \brief Write the given buffer to an object in this container. */
201+
/**
202+
\brief Write the given buffer to an object in this container.
203+
\param oid A 128-bit DAOS object identifier.
204+
\param buffer The address of the source buffer.
205+
\param length Length of the buffer.
206+
\param dkey The distribution key used for this operation.
207+
\param akey The attribute key used for this operation.
208+
\return 0 if the operation succeeded; a negative DAOS error number otherwise.
209+
*/
182210
template <typename DKeyT, typename AKeyT>
183211
int WriteObject(daos_obj_id_t oid, const void *buffer, std::size_t length, DKeyT dkey, AKeyT akey)
184212
{
@@ -188,7 +216,14 @@ public:
188216
return RDaosObject<DKeyT, AKeyT>(*this, oid).Update(args);
189217
}
190218

191-
/** \brief Write the given buffer to an object in this container and return a generated OID. */
219+
/**
220+
\brief Write the given buffer to an object in this container and return a generated OID.
221+
\param buffer The address of the source buffer.
222+
\param length Length of the buffer.
223+
\param dkey The distribution key used for this operation.
224+
\param akey The attribute key used for this operation.
225+
\return A `std::tuple<>` that contains the generated OID and a DAOS error number (0 if the operation succeeded).
226+
*/
192227
template <typename DKeyT, typename AKeyT>
193228
std::tuple<daos_obj_id_t, int> WriteObject(const void *buffer, std::size_t length, DKeyT dkey, AKeyT akey)
194229
{
@@ -198,14 +233,20 @@ public:
198233
return ret;
199234
}
200235

201-
/** \brief Perform a vector read operation on (possibly) multiple objects.
202-
\param vec A `std::vector<RWOperation>` that describes read operations to perform. */
236+
/**
237+
\brief Perform a vector read operation on (possibly) multiple objects.
238+
\param vec A `std::vector<RWOperation>` that describes read operations to perform.
239+
\return Number of operations that could not complete.
240+
*/
203241
template <typename DKeyT, typename AKeyT>
204242
int ReadV(std::vector<RWOperation<DKeyT, AKeyT>> &vec)
205243
{ return VectorReadWrite(vec, std::mem_fn(&RDaosObject<DKeyT, AKeyT>::Fetch)); }
206244

207-
/** \brief Perform a vector write operation on (possibly) multiple objects.
208-
\param vec A `std::vector<RWOperation>` that describes write operations to perform. */
245+
/**
246+
\brief Perform a vector write operation on (possibly) multiple objects.
247+
\param vec A `std::vector<RWOperation>` that describes write operations to perform.
248+
\return Number of operations that could not complete.
249+
*/
209250
template <typename DKeyT, typename AKeyT>
210251
int WriteV(std::vector<RWOperation<DKeyT, AKeyT>> &vec)
211252
{ return VectorReadWrite(vec, std::mem_fn(&RDaosObject<DKeyT, AKeyT>::Update)); }

tree/ntuple/v7/src/RDaos.cxx

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*************************************************************************/
1515

1616
#include <ROOT/RDaos.hxx>
17+
#include <ROOT/RError.hxx>
1718

1819
#include <numeric>
1920
#include <stdexcept>
@@ -24,10 +25,11 @@ ROOT::Experimental::Detail::RDaosPool::RDaosPool(std::string_view poolUuid, std:
2425
SvcRAII(std::string_view ranks) { rankList = daos_rank_list_parse(ranks.data(), "_"); }
2526
~SvcRAII() { d_rank_list_free(rankList); }
2627
} Svc(serviceReplicas);
28+
daos_pool_info_t poolInfo{};
2729

2830
uuid_parse(poolUuid.data(), fPoolUuid);
29-
if (int err = daos_pool_connect(fPoolUuid, nullptr, Svc.rankList, DAOS_PC_RW, &fPoolHandle, &fPoolInfo, nullptr))
30-
throw std::runtime_error("daos_pool_connect: error: " + std::string(d_errstr(err)));
31+
if (int err = daos_pool_connect(fPoolUuid, nullptr, Svc.rankList, DAOS_PC_RW, &fPoolHandle, &poolInfo, nullptr))
32+
throw RException(R__FAIL("daos_pool_connect: error: " + std::string(d_errstr(err))));
3133
}
3234

3335
ROOT::Experimental::Detail::RDaosPool::~RDaosPool() {
@@ -77,7 +79,7 @@ ROOT::Experimental::Detail::RDaosObject<DKeyT, AKeyT>::RDaosObject(RDaosContaine
7779
ofeats |= DAOS_OF_AKEY_UINT64;
7880
daos_obj_generate_id(&oid, ofeats /*| DAOS_OF_ARRAY_BYTE*/, cid, 0);
7981
if (int err = daos_obj_open(container.fContainerHandle, oid, DAOS_OO_RW, &fObjectHandle, nullptr))
80-
throw std::runtime_error("daos_obj_open: error: " + std::string(d_errstr(err)));
82+
throw RException(R__FAIL("daos_obj_open: error: " + std::string(d_errstr(err))));
8183
}
8284

8385
template <typename DKeyT, typename AKeyT>
@@ -139,14 +141,16 @@ ROOT::Experimental::Detail::RDaosContainer::RDaosContainer(std::shared_ptr<RDaos
139141
std::string_view containerUuid, bool create)
140142
: fPool(pool)
141143
{
144+
daos_cont_info_t containerInfo{};
145+
142146
uuid_parse(containerUuid.data(), fContainerUuid);
143147
if (create) {
144148
if (int err = daos_cont_create(fPool->fPoolHandle, fContainerUuid, nullptr, nullptr))
145-
throw std::runtime_error("daos_cont_create: error: " + std::string(d_errstr(err)));
149+
throw RException(R__FAIL("daos_cont_create: error: " + std::string(d_errstr(err))));
146150
}
147151
if (int err = daos_cont_open(fPool->fPoolHandle, fContainerUuid, DAOS_COO_RW,
148-
&fContainerHandle, &fContainerInfo, nullptr))
149-
throw std::runtime_error("daos_cont_open: error: " + std::string(d_errstr(err)));
152+
&fContainerHandle, &containerInfo, nullptr))
153+
throw RException(R__FAIL("daos_cont_open: error: " + std::string(d_errstr(err))));
150154
}
151155

152156
ROOT::Experimental::Detail::RDaosContainer::~RDaosContainer() {

tree/ntuple/v7/src/RPageStorage.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ std::unique_ptr<ROOT::Experimental::Detail::RPageSource> ROOT::Experimental::Det
6868
#ifdef R__ENABLE_DAOS
6969
return std::make_unique<RPageSourceDaos>(ntupleName, location, options);
7070
#else
71-
throw std::runtime_error("This RNTuple build does not support DAOS.");
71+
throw RException(R__FAIL("This RNTuple build does not support DAOS."));
7272
#endif
7373

7474
return std::make_unique<RPageSourceFile>(ntupleName, location, options);
@@ -160,7 +160,7 @@ std::unique_ptr<ROOT::Experimental::Detail::RPageSink> ROOT::Experimental::Detai
160160
#ifdef R__ENABLE_DAOS
161161
realSink = std::make_unique<RPageSinkDaos>(ntupleName, location, options);
162162
#else
163-
throw std::runtime_error("This RNTuple build does not support DAOS.");
163+
throw RException(R__FAIL("This RNTuple build does not support DAOS."));
164164
#endif
165165
} else {
166166
realSink = std::make_unique<RPageSinkFile>(ntupleName, location, options);

tree/ntuple/v7/src/libdaos_mock/libdaos_mock.cxx

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/// is welcome!
77

88
/*************************************************************************
9-
* Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
9+
* Copyright (C) 1995-2021, Rene Brun and Fons Rademakers. *
1010
* All rights reserved. *
1111
* *
1212
* For the licensing terms see $ROOTSYS/LICENSE. *
@@ -84,6 +84,7 @@ int RDaosFakeObject::Fetch(daos_key_t *dkey, unsigned int nr, daos_iod_t *iods,
8484
|| sgls[0].sg_nr != 1)
8585
return -DER_INVAL;
8686

87+
std::lock_guard<std::mutex> lock(fMutexStorage);
8788
auto it = fStorage.find(GetKey(dkey, &iods[0].iod_name));
8889
if (it == fStorage.end())
8990
return -DER_INVAL;
@@ -99,6 +100,7 @@ int RDaosFakeObject::Update(daos_key_t *dkey, unsigned int nr, daos_iod_t *iods,
99100
|| sgls[0].sg_nr != 1)
100101
return -DER_INVAL;
101102

103+
std::lock_guard<std::mutex> lock(fMutexStorage);
102104
auto &data = fStorage[GetKey(dkey, &iods[0].iod_name)];
103105
d_iov_t &iov = sgls[0].sg_iovs[0];
104106
data.assign(reinterpret_cast<char *>(iov.iov_buf), iov.iov_buf_len);
@@ -186,18 +188,12 @@ indirection layer is added in order to detect the use of invalidated handles.
186188
// clang-format on
187189
class RDaosHandle {
188190
private:
189-
static constexpr uint32_t kCookieMagic = 0xfee1dead;
190-
static constexpr uint32_t kCookiePoison = 0x00001000;
191-
192-
/// \brief Wrapper over a `void *` that helps to detect the use of invalid handles.
193-
/// A pointer is considered valid only if the magic number matches; this magic
194-
/// number is clobbered on destruction.
191+
/// \brief Wrapper over a `void *` that may help to detect the use of invalid handles.
195192
struct Cookie {
196-
Cookie(void *p) : fMagic(kCookieMagic), fPointer(p) {}
197-
~Cookie() { fMagic = kCookiePoison; }
198-
void *GetPointer() { return (fMagic == kCookieMagic) ? fPointer : nullptr; }
193+
Cookie(void *p) : fPointer(p) {}
194+
~Cookie() { fPointer = nullptr; }
195+
void *GetPointer() { return fPointer; }
199196

200-
uint32_t fMagic;
201197
void *fPointer;
202198
};
203199

@@ -251,7 +247,7 @@ const char *d_errstr(int rc)
251247

252248

253249
int daos_cont_create(daos_handle_t poh, const uuid_t uuid, daos_prop_t *cont_prop,
254-
daos_event_t *ev)
250+
daos_event_t *ev)
255251
{
256252
(void)cont_prop;
257253
(void)ev;
@@ -266,7 +262,7 @@ int daos_cont_create(daos_handle_t poh, const uuid_t uuid, daos_prop_t *cont_pro
266262
}
267263

268264
int daos_cont_open(daos_handle_t poh, const uuid_t uuid, unsigned int flags,
269-
daos_handle_t *coh, daos_cont_info_t *info, daos_event_t *ev)
265+
daos_handle_t *coh, daos_cont_info_t *info, daos_event_t *ev)
270266
{
271267
(void)flags;
272268
(void)info;
@@ -310,7 +306,7 @@ int daos_eq_destroy(daos_handle_t eqh, int flags)
310306
}
311307

312308
int daos_eq_poll(daos_handle_t eqh, int wait_running,
313-
int64_t timeout, unsigned int nevents, daos_event_t **events)
309+
int64_t timeout, unsigned int nevents, daos_event_t **events)
314310
{
315311
(void)eqh;
316312
(void)wait_running;
@@ -338,7 +334,7 @@ int daos_event_fini(daos_event_t *ev)
338334

339335

340336
int daos_obj_open(daos_handle_t coh, daos_obj_id_t oid, unsigned int mode,
341-
daos_handle_t *oh, daos_event_t *ev)
337+
daos_handle_t *oh, daos_event_t *ev)
342338
{
343339
(void)ev;
344340

@@ -358,8 +354,8 @@ int daos_obj_close(daos_handle_t oh, daos_event_t *ev)
358354
}
359355

360356
int daos_obj_fetch(daos_handle_t oh, daos_handle_t th, uint64_t flags,
361-
daos_key_t *dkey, unsigned int nr, daos_iod_t *iods,
362-
d_sg_list_t *sgls, daos_iom_t *ioms, daos_event_t *ev)
357+
daos_key_t *dkey, unsigned int nr, daos_iod_t *iods,
358+
d_sg_list_t *sgls, daos_iom_t *ioms, daos_event_t *ev)
363359
{
364360
(void)th;
365361
(void)flags;
@@ -373,8 +369,8 @@ int daos_obj_fetch(daos_handle_t oh, daos_handle_t th, uint64_t flags,
373369
}
374370

375371
int daos_obj_update(daos_handle_t oh, daos_handle_t th, uint64_t flags,
376-
daos_key_t *dkey, unsigned int nr, daos_iod_t *iods,
377-
d_sg_list_t *sgls, daos_event_t *ev)
372+
daos_key_t *dkey, unsigned int nr, daos_iod_t *iods,
373+
d_sg_list_t *sgls, daos_event_t *ev)
378374
{
379375
(void)th;
380376
(void)flags;
@@ -391,8 +387,8 @@ int daos_obj_update(daos_handle_t oh, daos_handle_t th, uint64_t flags,
391387

392388

393389
int daos_pool_connect(const uuid_t uuid, const char *grp,
394-
const d_rank_list_t *svc, unsigned int flags,
395-
daos_handle_t *poh, daos_pool_info_t *info, daos_event_t *ev)
390+
const d_rank_list_t *svc, unsigned int flags,
391+
daos_handle_t *poh, daos_pool_info_t *info, daos_event_t *ev)
396392
{
397393
(void)grp;
398394
(void)svc;

tree/ntuple/v7/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ if(daos OR daos_mock)
5252
set(daos_test_pool 1b245c52-765e-449d-80b1-8dce93bafc4b)
5353
endif()
5454
set_property(SOURCE ntuple_storage_daos.cxx
55-
APPEND PROPERTY COMPILE_OPTIONS -DR__DAOS_TEST_POOL="${daos_test_pool}")
55+
APPEND PROPERTY COMPILE_OPTIONS -DR__DAOS_TEST_POOL="${daos_test_pool}")
5656

5757
ROOT_ADD_GTEST(ntuple_storage_daos ntuple_storage_daos.cxx LIBRARIES ROOTDataFrame ROOTNTuple MathCore CustomStruct)
5858
endif()

tree/ntuple/v7/test/ntuple_storage_daos.cxx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ TEST(RNTuple, Basics)
99

1010
{
1111
RNTupleWriteOptions options;
12-
options.SetContainerFormat(ENTupleContainerFormat::kBare);
13-
auto ntuple = RNTupleWriter::Recreate(std::move(model), "f", daosUri, options);
12+
auto ntuple = RNTupleWriter::Recreate(std::move(model), "ntuple", daosUri, options);
1413
ntuple->Fill();
1514
ntuple->CommitCluster();
1615
*wrPt = 24.0;
@@ -42,8 +41,7 @@ TEST(RNTuple, Extended)
4241
double chksumWrite = 0.0;
4342
{
4443
RNTupleWriteOptions options;
45-
options.SetContainerFormat(ENTupleContainerFormat::kBare);
46-
auto ntuple = RNTupleWriter::Recreate(std::move(model), "f", daosUri, options);
44+
auto ntuple = RNTupleWriter::Recreate(std::move(model), "ntuple", daosUri, options);
4745
constexpr unsigned int nEvents = 32000;
4846
for (unsigned int i = 0; i < nEvents; ++i) {
4947
auto nVec = 1 + floor(rnd.Rndm() * 1000.);

0 commit comments

Comments
 (0)