Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RPageStorageDaos.cxx
Go to the documentation of this file.
1/// \file RPageStorageDaos.cxx
2/// \ingroup NTuple
3/// \author Javier Lopez-Gomez <j.lopez@cern.ch>
4/// \date 2020-11-03
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#include <ROOT/RCluster.hxx>
17#include <ROOT/RLogger.hxx>
19#include <ROOT/RNTupleModel.hxx>
22#include <ROOT/RNTupleTypes.hxx>
23#include <ROOT/RNTupleUtils.hxx>
24#include <ROOT/RNTupleZip.hxx>
25#include <ROOT/RPage.hxx>
27#include <ROOT/RPagePool.hxx>
28#include <ROOT/RDaos.hxx>
30
31#include <RVersion.h>
32#include <TError.h>
33
34#include <algorithm>
35#include <cstdio>
36#include <cstdlib>
37#include <cstring>
38#include <limits>
39#include <utility>
40#include <regex>
41#include <cassert>
42
43namespace {
52
53/// \brief RNTuple page-DAOS mappings
54enum EDaosMapping { kOidPerCluster, kOidPerPage };
55
56struct RDaosKey {
57 daos_obj_id_t fOid;
58 DistributionKey_t fDkey;
59 AttributeKey_t fAkey;
60};
61
62/// \brief Pre-defined keys for object store. `kDistributionKeyDefault` is the distribution key for metadata and
63/// pagelist values; optionally it can be used for ntuple pages (if under the `kOidPerPage` mapping strategy).
64/// `kAttributeKeyDefault` is the attribute key for ntuple pages under `kOidPerPage`.
65/// `kAttributeKey{Anchor,Header,Footer}` are the respective attribute keys for anchor/header/footer metadata elements.
66static constexpr DistributionKey_t kDistributionKeyDefault = 0x5a3c69f0cafe4a11;
67static constexpr AttributeKey_t kAttributeKeyDefault = 0x4243544b53444229;
68static constexpr AttributeKey_t kAttributeKeyAnchor = 0x4243544b5344422a;
69static constexpr AttributeKey_t kAttributeKeyHeader = 0x4243544b5344422b;
70static constexpr AttributeKey_t kAttributeKeyFooter = 0x4243544b5344422c;
71
72/// \brief Pre-defined 64 LSb of the OIDs for ntuple metadata (holds anchor/header/footer) and clusters' pagelists.
73static constexpr decltype(daos_obj_id_t::lo) kOidLowMetadata = -1;
74static constexpr decltype(daos_obj_id_t::lo) kOidLowPageList = -2;
75
76static constexpr daos_oclass_id_t kCidMetadata = OC_SX;
77
78static constexpr EDaosMapping kDefaultDaosMapping = kOidPerCluster;
79
80template <EDaosMapping mapping>
82 long unsigned columnId, long unsigned pageCount)
83{
84 if constexpr (mapping == kOidPerCluster) {
85 return RDaosKey{daos_obj_id_t{static_cast<decltype(daos_obj_id_t::lo)>(clusterId),
86 static_cast<decltype(daos_obj_id_t::hi)>(ntplId)},
87 static_cast<DistributionKey_t>(columnId), static_cast<AttributeKey_t>(pageCount)};
88 } else if constexpr (mapping == kOidPerPage) {
89 return RDaosKey{daos_obj_id_t{static_cast<decltype(daos_obj_id_t::lo)>(pageCount),
90 static_cast<decltype(daos_obj_id_t::hi)>(ntplId)},
92 }
93}
94
95struct RDaosURI {
96 /// \brief Label of the DAOS pool
97 std::string fPoolLabel;
98 /// \brief Label of the container for this RNTuple
99 std::string fContainerLabel;
100};
101
102/**
103 \brief Parse a DAOS RNTuple URI of the form 'daos://pool_id/container_id'.
104*/
105RDaosURI ParseDaosURI(std::string_view uri)
106{
107 std::regex re("daos://([^/]+)/(.+)");
108 std::cmatch m;
109 if (!std::regex_match(uri.data(), m, re))
110 throw ROOT::RException(R__FAIL("Invalid DAOS pool URI."));
111 return {m[1], m[2]};
112}
113
114/// \brief Helper structure concentrating the functionality required to locate an ntuple within a DAOS container.
115/// It includes a hashing function that converts the RNTuple's name into a 32-bit identifier; this value is used to
116/// index the subspace for the ntuple among all objects in the container. A zero-value hash value is reserved for
117/// storing any future metadata related to container-wide management; a zero-index ntuple is thus disallowed and
118/// remapped to "1". Once the index is computed, `InitNTupleDescriptorBuilder()` can be called to return a
119/// partially-filled builder with the ntuple's anchor, header and footer, lacking only pagelists. Upon that call,
120/// a copy of the anchor is stored in `fAnchor`.
121struct RDaosContainerNTupleLocator {
122 std::string fName{};
123 ntuple_index_t fIndex{};
124 std::optional<ROOT::Experimental::Internal::RDaosNTupleAnchor> fAnchor;
125 static const ntuple_index_t kReservedIndex = 0;
126
127 RDaosContainerNTupleLocator() = default;
128 explicit RDaosContainerNTupleLocator(const std::string &ntupleName) : fName(ntupleName), fIndex(Hash(ntupleName)){};
129
130 bool IsValid() { return fAnchor.has_value() && fAnchor->fNBytesHeader; }
131 [[nodiscard]] ntuple_index_t GetIndex() const { return fIndex; };
132 static ntuple_index_t Hash(const std::string &ntupleName)
133 {
134 // Convert string to numeric representation via `std::hash`.
135 uint64_t h = std::hash<std::string>{}(ntupleName);
136 // Fold the hash into 32-bit using `boost::hash_combine()` algorithm and magic number.
137 auto seed = static_cast<uint32_t>(h >> 32);
138 seed ^= static_cast<uint32_t>(h & 0xffffffff) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
139 auto hash = static_cast<ntuple_index_t>(seed);
140 return (hash == kReservedIndex) ? kReservedIndex + 1 : hash;
141 }
142
145 {
146 std::unique_ptr<unsigned char[]> buffer, zipBuffer;
147 auto &anchor = fAnchor.emplace();
148 int err;
149
151 daos_obj_id_t oidMetadata{kOidLowMetadata, static_cast<decltype(daos_obj_id_t::hi)>(this->GetIndex())};
152
154 if ((err = cont.ReadSingleAkey(buffer.get(), anchorSize, oidMetadata, kDistributionKeyDefault,
156 return err;
157 }
158
159 anchor.Deserialize(buffer.get(), anchorSize).Unwrap();
160
161 builder.SetVersion(anchor.fVersionEpoch, anchor.fVersionMajor, anchor.fVersionMinor, anchor.fVersionPatch);
162 builder.SetOnDiskHeaderSize(anchor.fNBytesHeader);
163 buffer = MakeUninitArray<unsigned char>(anchor.fLenHeader);
165 if ((err = cont.ReadSingleAkey(zipBuffer.get(), anchor.fNBytesHeader, oidMetadata, kDistributionKeyDefault,
167 return err;
168 RNTupleDecompressor::Unzip(zipBuffer.get(), anchor.fNBytesHeader, anchor.fLenHeader, buffer.get());
169 RNTupleSerializer::DeserializeHeader(buffer.get(), anchor.fLenHeader, builder);
170
171 builder.AddToOnDiskFooterSize(anchor.fNBytesFooter);
172 buffer = MakeUninitArray<unsigned char>(anchor.fLenFooter);
174 if ((err = cont.ReadSingleAkey(zipBuffer.get(), anchor.fNBytesFooter, oidMetadata, kDistributionKeyDefault,
176 return err;
177 RNTupleDecompressor::Unzip(zipBuffer.get(), anchor.fNBytesFooter, anchor.fLenFooter, buffer.get());
178 RNTupleSerializer::DeserializeFooter(buffer.get(), anchor.fLenFooter, builder);
179
180 return 0;
181 }
182
183 static std::pair<RDaosContainerNTupleLocator, ROOT::Internal::RNTupleDescriptorBuilder>
185 {
186 auto result = std::make_pair(RDaosContainerNTupleLocator(ntupleName), ROOT::Internal::RNTupleDescriptorBuilder());
187
188 auto &loc = result.first;
189 auto &builder = result.second;
190
191 if (int err = loc.InitNTupleDescriptorBuilder(cont, builder); !err) {
192 if (ntupleName.empty() || ntupleName != builder.GetDescriptor().GetName()) {
193 // Hash already taken by a differently-named ntuple.
194 throw ROOT::RException(
195 R__FAIL("LocateNTuple: ntuple name '" + ntupleName + "' unavailable in this container."));
196 }
197 }
198 return result;
199 }
200};
201
202} // anonymous namespace
203
204////////////////////////////////////////////////////////////////////////////////
205
223
226{
227 if (bufSize < 32)
228 return R__FAIL("DAOS anchor too short");
229
230 auto bytes = reinterpret_cast<const unsigned char *>(buffer);
232 if (fVersionAnchor != RDaosNTupleAnchor().fVersionAnchor) {
233 return R__FAIL("unsupported DAOS anchor version: " + std::to_string(fVersionAnchor));
234 }
235
245 if (!result)
246 return R__FORWARD_ERROR(result);
247 return result.Unwrap() + 32;
248}
249
254
255////////////////////////////////////////////////////////////////////////////////
256
258 const ROOT::RNTupleWriteOptions &options)
259 : RPagePersistentSink(ntupleName, options), fURI(uri)
260{
261 static std::once_flag once;
262 std::call_once(once, []() {
263 R__LOG_WARNING(ROOT::Internal::NTupleLog()) << "The DAOS backend is experimental and still under development. "
264 << "Do not store real data with this version of RNTuple!";
265 });
266 EnableDefaultMetrics("RPageSinkDaos");
267}
268
270
272{
273 auto opts = dynamic_cast<RNTupleWriteOptionsDaos *>(fOptions.get());
274 fNTupleAnchor.fObjClass = opts ? opts->GetObjectClass() : RNTupleWriteOptionsDaos().GetObjectClass();
275 auto oclass = RDaosObject::ObjClassId(fNTupleAnchor.fObjClass);
276 if (oclass.IsUnknown())
277 throw ROOT::RException(R__FAIL("Unknown object class " + fNTupleAnchor.fObjClass));
278
279 auto args = ParseDaosURI(fURI);
280 auto pool = std::make_shared<RDaosPool>(args.fPoolLabel);
281
282 fDaosContainer = std::make_unique<RDaosContainer>(pool, args.fContainerLabel, /*create =*/true);
283 fDaosContainer->SetDefaultObjectClass(oclass);
284
285 auto [locator, _] = RDaosContainerNTupleLocator::LocateNTuple(*fDaosContainer, fNTupleName);
286 fNTupleIndex = locator.GetIndex();
287
289 auto szZipHeader =
290 RNTupleCompressor::Zip(serializedHeader, length, GetWriteOptions().GetCompression(), zipBuffer.get());
291 WriteNTupleHeader(zipBuffer.get(), szZipHeader, length);
292}
293
296{
297 auto element = columnHandle.fColumn->GetElement();
299 {
300 Detail::RNTupleAtomicTimer timer(fCounters->fTimeWallZip, fCounters->fTimeCpuZip);
301 sealedPage = SealPage(page, *element);
302 }
303
304 fCounters->fSzZip.Add(page.GetNBytes());
305 return CommitSealedPageImpl(columnHandle.fPhysicalId, sealedPage);
306}
307
311{
312 auto pageId = fPageId.fetch_add(1);
313 ROOT::DescriptorId_t clusterId = fDescriptorBuilder.GetDescriptor().GetNActiveClusters();
314
315 {
316 Detail::RNTupleAtomicTimer timer(fCounters->fTimeWallWrite, fCounters->fTimeCpuWrite);
318 fDaosContainer->WriteSingleAkey(sealedPage.GetBuffer(), sealedPage.GetBufferSize(), daosKey.fOid, daosKey.fDkey,
319 daosKey.fAkey);
320 }
321
324 result.SetNBytesOnStorage(sealedPage.GetDataSize());
326 fCounters->fNPageCommitted.Inc();
327 fCounters->fSzWritePayload.Add(sealedPage.GetBufferSize());
328 fNBytesCurrentCluster += sealedPage.GetBufferSize();
329 return result;
330}
331
332std::vector<ROOT::RNTupleLocator>
333ROOT::Experimental::Internal::RPageSinkDaos::CommitSealedPageVImpl(std::span<RPageStorage::RSealedPageGroup> ranges,
334 const std::vector<bool> &mask)
335{
337 std::vector<RNTupleLocator> locators;
338 auto nPages = mask.size();
339 locators.reserve(nPages);
340
341 ROOT::DescriptorId_t clusterId = fDescriptorBuilder.GetDescriptor().GetNActiveClusters();
342 int64_t payloadSz = 0;
343
344 /// Aggregate batch of requests by object ID and distribution key, determined by the ntuple-DAOS mapping
345 for (auto &range : ranges) {
346 for (auto sealedPageIt = range.fFirst; sealedPageIt != range.fLast; ++sealedPageIt) {
348
349 const auto pageId = fPageId.fetch_add(1);
350
352 d_iov_set(&pageIov, const_cast<void *>(s.GetBuffer()), s.GetBufferSize());
353
354 RDaosKey daosKey =
355 GetPageDaosKey<kDefaultDaosMapping>(fNTupleIndex, clusterId, range.fPhysicalColumnId, pageId);
358 it->second.Insert(daosKey.fAkey, pageIov);
359
362 locator.SetNBytesOnStorage(s.GetDataSize());
364 locators.push_back(locator);
365
367 }
368 }
369 fNBytesCurrentCluster += payloadSz;
370
371 {
372 Detail::RNTupleAtomicTimer timer(fCounters->fTimeWallWrite, fCounters->fTimeCpuWrite);
373 if (int err = fDaosContainer->WriteV(writeRequests))
374 throw ROOT::RException(R__FAIL("WriteV: error" + std::string(d_errstr(err))));
375 }
376
377 fCounters->fNPageCommitted.Add(nPages);
378 fCounters->fSzWritePayload.Add(payloadSz);
379
380 return locators;
381}
382
384{
385 return std::exchange(fNBytesCurrentCluster, 0);
386}
387
390 std::uint32_t length)
391{
393 auto szPageListZip =
394 RNTupleCompressor::Zip(serializedPageList, length, GetWriteOptions().GetCompression(), bufPageListZip.get());
395
396 auto offsetData = fClusterGroupId.fetch_add(1);
397 fDaosContainer->WriteSingleAkey(
399 daos_obj_id_t{kOidLowPageList, static_cast<decltype(daos_obj_id_t::hi)>(fNTupleIndex)}, kDistributionKeyDefault,
403 result.SetNBytesOnStorage(szPageListZip);
405 fCounters->fSzWritePayload.Add(static_cast<int64_t>(szPageListZip));
406 return result;
407}
408
410 std::uint32_t length)
411{
413 auto szFooterZip =
414 RNTupleCompressor::Zip(serializedFooter, length, GetWriteOptions().GetCompression(), bufFooterZip.get());
415 WriteNTupleFooter(bufFooterZip.get(), szFooterZip, length);
416 WriteNTupleAnchor();
417}
418
420{
421 fDaosContainer->WriteSingleAkey(
422 data, nbytes, daos_obj_id_t{kOidLowMetadata, static_cast<decltype(daos_obj_id_t::hi)>(fNTupleIndex)},
424 fNTupleAnchor.fLenHeader = lenHeader;
425 fNTupleAnchor.fNBytesHeader = nbytes;
426}
427
429{
430 fDaosContainer->WriteSingleAkey(
431 data, nbytes, daos_obj_id_t{kOidLowMetadata, static_cast<decltype(daos_obj_id_t::hi)>(fNTupleIndex)},
433 fNTupleAnchor.fLenFooter = lenFooter;
434 fNTupleAnchor.fNBytesFooter = nbytes;
435}
436
438{
441 fNTupleAnchor.Serialize(buffer.get());
442 fDaosContainer->WriteSingleAkey(
443 buffer.get(), ntplSize, daos_obj_id_t{kOidLowMetadata, static_cast<decltype(daos_obj_id_t::hi)>(fNTupleIndex)},
445}
446
447std::unique_ptr<ROOT::Internal::RPageSink>
449 const ROOT::RNTupleWriteOptions & /*opts*/) const
450{
451 throw ROOT::RException(R__FAIL("cloning a DAOS sink is not implemented yet"));
452}
453
454////////////////////////////////////////////////////////////////////////////////
455
457 const ROOT::RNTupleReadOptions &options)
458 : RPageSource(ntupleName, options), fURI(uri)
459{
460 EnableDefaultMetrics("RPageSourceDaos");
461
462 auto args = ParseDaosURI(uri);
463 auto pool = std::make_shared<RDaosPool>(args.fPoolLabel);
464 fDaosContainer = std::make_unique<RDaosContainer>(pool, args.fContainerLabel);
465}
466
468{
469 fClusterPool.StopBackgroundThread();
470}
471
474{
476 std::unique_ptr<unsigned char[]> buffer, zipBuffer;
477
478 auto [locator, descBuilder] = RDaosContainerNTupleLocator::LocateNTuple(*fDaosContainer, fNTupleName);
479 if (!locator.IsValid())
480 throw ROOT::RException(
481 R__FAIL("Attach: requested ntuple '" + fNTupleName + "' is not present in DAOS container."));
482
483 auto oclass = RDaosObject::ObjClassId(locator.fAnchor->fObjClass);
484 if (oclass.IsUnknown())
485 throw ROOT::RException(R__FAIL("Attach: unknown object class " + locator.fAnchor->fObjClass));
486
487 fDaosContainer->SetDefaultObjectClass(oclass);
488 fNTupleIndex = locator.GetIndex();
490
491 auto desc = descBuilder.MoveDescriptor();
492
493 for (const auto &cgDesc : desc.GetClusterGroupIterable()) {
494 buffer = MakeUninitArray<unsigned char>(cgDesc.GetPageListLength());
495 zipBuffer = MakeUninitArray<unsigned char>(cgDesc.GetPageListLocator().GetNBytesOnStorage());
496 fDaosContainer->ReadSingleAkey(
497 zipBuffer.get(), cgDesc.GetPageListLocator().GetNBytesOnStorage(), oidPageList, kDistributionKeyDefault,
498 cgDesc.GetPageListLocator().GetPosition<RNTupleLocatorObject64>().GetLocation(), kCidMetadata);
499 RNTupleDecompressor::Unzip(zipBuffer.get(), cgDesc.GetPageListLocator().GetNBytesOnStorage(),
500 cgDesc.GetPageListLength(), buffer.get());
501
502 RNTupleSerializer::DeserializePageList(buffer.get(), cgDesc.GetPageListLength(), cgDesc.GetId(), desc, mode);
503 }
504
505 return desc;
506}
507
509{
510 return fDaosContainer->GetDefaultObjectClass().ToString();
511}
512
516{
517 const auto clusterId = localIndex.GetClusterId();
518
520 {
521 auto descriptorGuard = GetSharedDescriptorGuard();
522 const auto &clusterDescriptor = descriptorGuard->GetClusterDescriptor(clusterId);
523 pageInfo = clusterDescriptor.GetPageRange(physicalColumnId).Find(localIndex.GetIndexInCluster());
524 }
525
526 sealedPage.SetBufferSize(pageInfo.GetLocator().GetNBytesOnStorage() + pageInfo.HasChecksum() * kNBytesPageChecksum);
527 sealedPage.SetNElements(pageInfo.GetNElements());
528 sealedPage.SetHasChecksum(pageInfo.HasChecksum());
529 if (!sealedPage.GetBuffer())
530 return;
531
532 if (pageInfo.GetLocator().GetType() == RNTupleLocator::kTypePageZero) {
533 assert(!pageInfo.HasChecksum());
534 memcpy(const_cast<void *>(sealedPage.GetBuffer()), ROOT::Internal::RPage::GetPageZeroBuffer(),
535 sealedPage.GetBufferSize());
536 return;
537 }
538
539 RDaosKey daosKey =
541 pageInfo.GetLocator().GetPosition<RNTupleLocatorObject64>().GetLocation());
542 fDaosContainer->ReadSingleAkey(const_cast<void *>(sealedPage.GetBuffer()), sealedPage.GetBufferSize(), daosKey.fOid,
543 daosKey.fDkey, daosKey.fAkey);
544
545 sealedPage.VerifyChecksumIfEnabled().ThrowOnError();
546}
547
551{
552 const auto columnId = columnHandle.fPhysicalId;
553 const auto clusterId = clusterInfo.fClusterId;
554 const auto &pageInfo = clusterInfo.fPageInfo;
555
556 const auto element = columnHandle.fColumn->GetElement();
557 const auto elementSize = element->GetSize();
558 const auto elementInMemoryType = element->GetIdentifier().fInMemoryType;
559
560 if (pageInfo.GetLocator().GetType() == RNTupleLocator::kTypePageZero) {
561 auto pageZero = fPageAllocator->NewPage(elementSize, pageInfo.GetNElements());
562 pageZero.GrowUnchecked(pageInfo.GetNElements());
563 memset(pageZero.GetBuffer(), 0, pageZero.GetNBytes());
564 pageZero.SetWindow(clusterInfo.fColumnOffset + pageInfo.GetFirstElementIndex(),
566 return fPagePool.RegisterPage(std::move(pageZero),
568 }
569
571 sealedPage.SetNElements(pageInfo.GetNElements());
572 sealedPage.SetHasChecksum(pageInfo.HasChecksum());
573 sealedPage.SetBufferSize(pageInfo.GetLocator().GetNBytesOnStorage() + pageInfo.HasChecksum() * kNBytesPageChecksum);
574 std::unique_ptr<unsigned char[]> directReadBuffer; // only used if cluster pool is turned off
575
576 if (fOptions.GetClusterCache() == ROOT::RNTupleReadOptions::EClusterCache::kOff) {
579 fNTupleIndex, clusterId, columnId, pageInfo.GetLocator().GetPosition<RNTupleLocatorObject64>().GetLocation());
580 fDaosContainer->ReadSingleAkey(directReadBuffer.get(), sealedPage.GetBufferSize(), daosKey.fOid, daosKey.fDkey,
581 daosKey.fAkey);
582 fCounters->fNPageRead.Inc();
583 fCounters->fNRead.Inc();
584 fCounters->fSzReadPayload.Add(sealedPage.GetBufferSize());
585 sealedPage.SetBuffer(directReadBuffer.get());
586 } else {
587 if (!fCurrentCluster || (fCurrentCluster->GetId() != clusterId) || !fCurrentCluster->ContainsColumn(columnId))
588 fCurrentCluster = fClusterPool.GetCluster(clusterId, fActivePhysicalColumns.ToColumnSet());
589 R__ASSERT(fCurrentCluster->ContainsColumn(columnId));
590
593 if (!cachedPageRef.Get().IsNull())
594 return cachedPageRef;
595
597 auto onDiskPage = fCurrentCluster->GetOnDiskPage(key);
598 R__ASSERT(onDiskPage && (sealedPage.GetBufferSize() == onDiskPage->GetSize()));
599 sealedPage.SetBuffer(onDiskPage->GetAddress());
600 }
601
603 {
604 Detail::RNTupleAtomicTimer timer(fCounters->fTimeWallUnzip, fCounters->fTimeCpuUnzip);
605 newPage = UnsealPage(sealedPage, *element).Unwrap();
606 fCounters->fSzUnzip.Add(elementSize * pageInfo.GetNElements());
607 }
608
609 newPage.SetWindow(clusterInfo.fColumnOffset + pageInfo.GetFirstElementIndex(),
611 fCounters->fNPageUnsealed.Inc();
612 return fPagePool.RegisterPage(std::move(newPage), ROOT::Internal::RPagePool::RKey{columnId, elementInMemoryType});
613}
614
615std::unique_ptr<ROOT::Internal::RPageSource> ROOT::Experimental::Internal::RPageSourceDaos::CloneImpl() const
616{
617 auto clone = new RPageSourceDaos(fNTupleName, fURI, fOptions);
618 return std::unique_ptr<RPageSourceDaos>(clone);
619}
620
621std::vector<std::unique_ptr<RCluster>>
623{
625 ROOT::DescriptorId_t fClusterId = 0;
626 ROOT::DescriptorId_t fColumnId = 0;
627 ROOT::NTupleSize_t fPageNo = 0;
628 std::uint64_t fPageId = 0;
629 std::uint64_t fDataSize = 0; // page payload
630 std::uint64_t fBufferSize = 0; // page payload + checksum (if available)
631 };
632
633 // Prepares read requests for a single cluster; `readRequests` is modified by this function. Requests are coalesced
634 // by OID and distribution key.
635 // TODO(jalopezg): this may be a private member function; that, however, requires additional changes given that
636 // `RDaosContainer::MultiObjectRWOperation_t` cannot be forward-declared
639 auto clusterId = clusterKey.fClusterId;
640 std::vector<RDaosSealedPageLocator> onDiskPages;
641
642 unsigned clusterBufSz = 0, nPages = 0;
643 auto pageZeroMap = std::make_unique<ROOT::Internal::ROnDiskPageMap>();
644 PrepareLoadCluster(
648 const auto &pageLocator = pageInfo.GetLocator();
649 const auto pageId = pageLocator.GetPosition<RNTupleLocatorObject64>().GetLocation();
650 const auto pageBufferSize = pageLocator.GetNBytesOnStorage() + pageInfo.HasChecksum() * kNBytesPageChecksum;
652 pageLocator.GetNBytesOnStorage(), pageBufferSize});
653
654 ++nPages;
656 });
657
658 auto clusterBuffer = new unsigned char[clusterBufSz];
659 auto pageMap =
660 std::make_unique<ROOT::Internal::ROnDiskPageMapHeap>(std::unique_ptr<unsigned char[]>(clusterBuffer));
661
662 // Fill the cluster page map and the read requests for the RDaosContainer::ReadV() call
663 for (const auto &sealedLoc : onDiskPages) {
665 pageMap->Register(key, ROOT::Internal::ROnDiskPage(clusterBuffer, sealedLoc.fBufferSize));
666
667 // Prepare new read request batched up by object ID and distribution key
668 d_iov_t iov;
669 d_iov_set(&iov, clusterBuffer, sealedLoc.fBufferSize);
670
671 RDaosKey daosKey = GetPageDaosKey<kDefaultDaosMapping>(fNTupleIndex, sealedLoc.fClusterId, sealedLoc.fColumnId,
672 sealedLoc.fPageId);
675 itReq->second.Insert(daosKey.fAkey, iov);
676
677 clusterBuffer += sealedLoc.fBufferSize;
678 }
679 fCounters->fNPageRead.Add(nPages);
680 fCounters->fSzReadPayload.Add(clusterBufSz);
681
682 auto cluster = std::make_unique<RCluster>(clusterId);
683 cluster->Adopt(std::move(pageMap));
684 cluster->Adopt(std::move(pageZeroMap));
685 for (auto colId : clusterKey.fPhysicalColumnSet)
686 cluster->SetColumnAvailable(colId);
687 return cluster;
688 };
689
690 fCounters->fNClusterLoaded.Add(clusterKeys.size());
691
692 std::vector<std::unique_ptr<ROOT::Internal::RCluster>> clusters;
694 for (auto key : clusterKeys) {
695 clusters.emplace_back(fnPrepareSingleCluster(key, readRequests));
696 }
697
698 {
699 Detail::RNTupleAtomicTimer timer(fCounters->fTimeWallRead, fCounters->fTimeCpuRead);
700 if (int err = fDaosContainer->ReadV(readRequests))
701 throw ROOT::RException(R__FAIL("ReadV: error" + std::string(d_errstr(err))));
702 }
703 fCounters->fNReadV.Inc();
704 fCounters->fNRead.Add(readRequests.size());
705
706 return clusters;
707}
708
710{
711 R__LOG_WARNING(ROOT::Internal::NTupleLog()) << "DAOS-backed sources have no associated StreamerInfo to load.";
712}
#define R__FORWARD_ERROR(res)
Short-hand to return an RResult<T> in an error state (i.e. after checking)
Definition RError.hxx:304
#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:300
#define R__LOG_WARNING(...)
Definition RLogger.hxx:358
#define h(i)
Definition RSha256.hxx:106
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
#define R__ASSERT(e)
Checks condition e and reports a fatal error if it's false.
Definition TError.h:125
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 mask
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 result
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 mode
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 Atom_t Int_t ULong_t ULong_t bytes
UInt_t Hash(const TString &s)
Definition TString.h:503
#define _(A, B)
Definition cfortran.h:108
A RDaosContainer provides read/write access to objects in a given container.
Definition RDaos.hxx:157
RDaosObject::DistributionKey_t DistributionKey_t
Definition RDaos.hxx:160
std::unordered_map< ROidDkeyPair, RWOperation, ROidDkeyPair::Hash > MultiObjectRWOperation_t
Definition RDaos.hxx:231
RDaosObject::AttributeKey_t AttributeKey_t
Definition RDaos.hxx:161
RNTupleLocator CommitPageImpl(ColumnHandle_t columnHandle, const ROOT::Internal::RPage &page) final
std::vector< RNTupleLocator > CommitSealedPageVImpl(std::span< RPageStorage::RSealedPageGroup > ranges, const std::vector< bool > &mask) final
Vector commit of preprocessed pages.
void WriteNTupleFooter(const void *data, size_t nbytes, size_t lenFooter)
std::uint64_t StageClusterImpl() final
Returns the number of bytes written to storage (excluding metadata)
RNTupleLocator CommitClusterGroupImpl(unsigned char *serializedPageList, std::uint32_t length) final
Returns the locator of the page list envelope of the given buffer that contains the serialized page l...
void WriteNTupleHeader(const void *data, size_t nbytes, size_t lenHeader)
void InitImpl(unsigned char *serializedHeader, std::uint32_t length) final
std::unique_ptr< ROOT::Internal::RPageSink > CloneWithDifferentName(std::string_view name, const ROOT::RNTupleWriteOptions &opts) const final
RPageSinkDaos(std::string_view ntupleName, std::string_view uri, const ROOT::RNTupleWriteOptions &options)
RNTupleLocator CommitSealedPageImpl(ROOT::DescriptorId_t physicalColumnId, const RPageStorage::RSealedPage &sealedPage) final
Storage provider that reads ntuple pages from a DAOS container.
void LoadStreamerInfo() final
Forces the loading of ROOT StreamerInfo from the underlying file.
std::string GetObjectClass() const
Return the object class used for user data OIDs in this ntuple.
std::unique_ptr< RPageSource > CloneImpl() const final
The cloned page source creates a new connection to the pool/container.
ROOT::Internal::RPageRef LoadPageImpl(ColumnHandle_t columnHandle, const RClusterInfo &clusterInfo, ROOT::NTupleSize_t idxInCluster) final
std::vector< std::unique_ptr< ROOT::Internal::RCluster > > LoadClusters(std::span< ROOT::Internal::RCluster::RKey > clusterKeys) final
Populates all the pages of the given cluster ids and columns; it is possible that some columns do not...
void LoadSealedPage(ROOT::DescriptorId_t physicalColumnId, RNTupleLocalIndex localIndex, RSealedPage &sealedPage) final
Read the packed and compressed bytes of a page into the memory buffer provided by sealedPage.
std::unique_ptr< RDaosContainer > fDaosContainer
A container that stores object data (header/footer, pages, etc.)
RPageSourceDaos(std::string_view ntupleName, std::string_view uri, const ROOT::RNTupleReadOptions &options)
ROOT::RNTupleDescriptor AttachImpl(ROOT::Internal::RNTupleSerializer::EDescriptorDeserializeMode mode) final
LoadStructureImpl() has been called before AttachImpl() is called
DAOS-specific user-tunable settings for storing ntuples.
An in-memory subset of the packed and compressed pages of a cluster.
Definition RCluster.hxx:148
Helper class to compress data blocks in the ROOT compression frame format.
static std::size_t Zip(const void *from, std::size_t nbytes, int compression, void *to)
Returns the size of the compressed data, written into the provided output buffer.
Helper class to uncompress data blocks in the ROOT compression frame format.
static void Unzip(const void *from, size_t nbytes, size_t dataLen, void *to)
The nbytes parameter provides the size ls of the from buffer.
A helper class for piece-wise construction of an RNTupleDescriptor.
void SetVersion(std::uint16_t versionEpoch, std::uint16_t versionMajor, std::uint16_t versionMinor, std::uint16_t versionPatch)
const RNTupleDescriptor & GetDescriptor() const
void AddToOnDiskFooterSize(std::uint64_t size)
The real footer size also include the page list envelopes.
A helper class for serializing and deserialization of the RNTuple binary format.
static RResult< std::uint32_t > DeserializeString(const void *buffer, std::uint64_t bufSize, std::string &val)
static std::uint32_t SerializeUInt32(std::uint32_t val, void *buffer)
static std::uint32_t DeserializeUInt32(const void *buffer, std::uint32_t &val)
static std::uint32_t SerializeUInt16(std::uint16_t val, void *buffer)
static RResult< void > DeserializePageList(const void *buffer, std::uint64_t bufSize, ROOT::DescriptorId_t clusterGroupId, RNTupleDescriptor &desc, EDescriptorDeserializeMode mode)
static std::uint32_t SerializeString(const std::string &val, void *buffer)
static std::uint32_t DeserializeUInt16(const void *buffer, std::uint16_t &val)
static std::uint32_t DeserializeUInt64(const void *buffer, std::uint64_t &val)
static std::uint32_t SerializeUInt64(std::uint64_t val, void *buffer)
A page as being stored on disk, that is packed and compressed.
Definition RCluster.hxx:41
Base class for a sink with a physical storage backend.
void EnableDefaultMetrics(const std::string &prefix)
Enables the default set of metrics provided by RPageSink.
Reference to a page stored in the page pool.
Abstract interface to read data from an ntuple.
void EnableDefaultMetrics(const std::string &prefix)
Enables the default set of metrics provided by RPageSource.
Stores information about the cluster in which this page resides.
Definition RPage.hxx:53
A page is a slice of a column that is mapped into memory.
Definition RPage.hxx:44
static const void * GetPageZeroBuffer()
Return a pointer to the page zero buffer used if there is no on-disk data for a particular deferred c...
Definition RPage.cxx:23
Base class for all ROOT issued exceptions.
Definition RError.hxx:79
The on-storage metadata of an RNTuple.
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
RNTupleLocator payload that is common for object stores using 64bit location information.
std::uint64_t GetLocation() const
Generic information about the physical location of data.
Common user-tunable settings for reading RNTuples.
Common user-tunable settings for storing RNTuples.
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
Definition RError.hxx:198
const char * d_errstr(int rc)
static void d_iov_set(d_iov_t *iov, void *buf, size_t size)
Definition daos.h:50
uint16_t daos_oclass_id_t
Definition daos.h:135
@ OC_SX
Definition daos.h:129
ROOT::RLogChannel & NTupleLog()
Log channel for RNTuple diagnostics.
std::unique_ptr< T[]> MakeUninitArray(std::size_t size)
Make an array of default-initialized elements.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
A pair of <object ID, distribution key> that can be used to issue a fetch/update request for multiple...
Definition RDaos.hxx:166
Describes a read/write operation on multiple attribute keys under the same object ID and distribution...
Definition RDaos.hxx:190
Entry point for an RNTuple in a DAOS container.
std::uint32_t fNBytesFooter
The size of the compressed ntuple footer.
std::uint64_t fVersionAnchor
Allows for evolving the struct in future versions.
std::string fObjClass
The object class for user data OIDs, e.g. SX
std::uint16_t fVersionEpoch
Version of the binary format supported by the writer.
RResult< std::uint32_t > Deserialize(const void *buffer, std::uint32_t bufSize)
std::uint32_t fLenHeader
The size of the uncompressed ntuple header.
std::uint32_t fLenFooter
The size of the uncompressed ntuple footer.
std::uint32_t fNBytesHeader
The size of the compressed ntuple header.
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
The identifiers that specifies the content of a (partial) cluster.
Definition RCluster.hxx:152
On-disk pages within a page source are identified by the column and page number.
Definition RCluster.hxx:51
Summarizes cluster-level information that are necessary to load a certain page.
A sealed page contains the bytes of a page as written to storage (packed & compressed).
Information about a single page in the context of a cluster's page range.
iovec for memory buffer
Definition daos.h:37
uint64_t hi
Definition daos.h:147
uint64_t lo
Definition daos.h:146
TMarker m
Definition textangle.C:8