Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RPageStorageDaos.hxx
Go to the documentation of this file.
1/// \file ROOT/RPageStorageDaos.hxx
2/// \ingroup NTuple ROOT7
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#ifndef ROOT7_RPageStorageDaos
17#define ROOT7_RPageStorageDaos
18
19#include <ROOT/RError.hxx>
20#include <ROOT/RPageStorage.hxx>
22#include <ROOT/RNTupleZip.hxx>
23#include <ROOT/RStringView.hxx>
24
25#include <array>
26#include <atomic>
27#include <cstdio>
28#include <memory>
29#include <string>
30#include <optional>
31
32namespace ROOT {
33namespace Experimental {
34namespace Detail {
35
36class RCluster;
37class RClusterPool;
38class RPageAllocatorHeap;
39class RPagePool;
40class RDaosPool;
41class RDaosContainer;
42
43using ntuple_index_t = std::uint32_t;
44
45// clang-format off
46/**
47\class ROOT::Experimental::Detail::RDaosNTupleAnchor
48\ingroup NTuple
49\brief Entry point for an RNTuple in a DAOS container. It encodes essential
50information to read the ntuple; currently, it contains (un)compressed size of
51the header/footer blobs and the object class for user data OIDs.
52The length of a serialized anchor cannot be greater than the value returned by the `GetSize` function.
53*/
54// clang-format on
56 /// Allows for evolving the struct in future versions
57 std::uint32_t fVersion = 0;
58 /// The size of the compressed ntuple header
59 std::uint32_t fNBytesHeader = 0;
60 /// The size of the uncompressed ntuple header
61 std::uint32_t fLenHeader = 0;
62 /// The size of the compressed ntuple footer
63 std::uint32_t fNBytesFooter = 0;
64 /// The size of the uncompressed ntuple footer
65 std::uint32_t fLenFooter = 0;
66 /// The object class for user data OIDs, e.g. `SX`
67 std::string fObjClass{};
68
69 bool operator ==(const RDaosNTupleAnchor &other) const {
70 return fVersion == other.fVersion &&
72 fLenHeader == other.fLenHeader &&
74 fLenFooter == other.fLenFooter &&
75 fObjClass == other.fObjClass;
76 }
77
78 std::uint32_t Serialize(void *buffer) const;
79 RResult<std::uint32_t> Deserialize(const void *buffer, std::uint32_t bufSize);
80
81 static std::uint32_t GetSize();
82};
83
84// clang-format off
85/**
86\class ROOT::Experimental::Detail::RDaosContainerNTupleLocator
87\ingroup NTuple
88\brief Helper structure concentrating the functionality required to locate an ntuple within a DAOS container.
89It includes a hashing function that converts the RNTuple's name into a 32-bit identifier; this value is used to index
90the subspace for the ntuple among all objects in the container. A zero-value hash value is reserved for storing any
91future metadata related to container-wide management; a zero-index ntuple is thus disallowed and remapped to "1".
92Once the index is computed, `InitNTupleDescriptorBuilder()` can be called to return a partially-filled builder with
93the ntuple's anchor, header and footer, lacking only pagelists. Upon that call, a copy of the anchor is stored in `fAnchor`.
94*/
95// clang-format on
97 std::string fName{};
99 std::optional<ROOT::Experimental::Detail::RDaosNTupleAnchor> fAnchor;
101
103 explicit RDaosContainerNTupleLocator(const std::string &ntupleName) : fName(ntupleName), fIndex(Hash(ntupleName)){};
104
105 bool IsValid() { return fAnchor.has_value() && fAnchor->fNBytesHeader; }
106 [[nodiscard]] ntuple_index_t GetIndex() const { return fIndex; };
107 static ntuple_index_t Hash(const std::string &ntupleName)
108 {
109 // Convert string to numeric representation via `std::hash`.
110 std::size_t h = std::hash<std::string>{}(ntupleName);
111 // Fold `std::size_t` bits into 32-bit using `boost::hash_combine()` algorithm and magic number.
112 auto seed = static_cast<uint32_t>(h >> 32);
113 seed ^= static_cast<uint32_t>(h & 0xffffffff) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
114 auto hash = static_cast<ntuple_index_t>(seed);
115 return (hash == kReservedIndex) ? kReservedIndex + 1 : hash;
116 }
117
119 RNTupleDescriptorBuilder &builder);
120
121 static std::pair<RDaosContainerNTupleLocator, RNTupleDescriptorBuilder>
122 LocateNTuple(RDaosContainer &cont, const std::string &ntupleName, RNTupleDecompressor &decompressor);
123};
124
125// clang-format off
126/**
127\class ROOT::Experimental::Detail::RPageSinkDaos
128\ingroup NTuple
129\brief Storage provider that writes ntuple pages to into a DAOS container
130
131Currently, an object is allocated for ntuple metadata (anchor/header/footer).
132Objects can correspond to pages or clusters of pages depending on the RNTuple-DAOS mapping strategy.
133*/
134// clang-format on
135class RPageSinkDaos : public RPageSink {
136private:
137 std::unique_ptr<RPageAllocatorHeap> fPageAllocator;
138
139 /// \brief Underlying DAOS container. An internal `std::shared_ptr` keep the pool connection alive.
140 /// ISO C++ ensures the correct destruction order, i.e., `~RDaosContainer` is invoked first
141 /// (which calls `daos_cont_close()`; the destructor for the `std::shared_ptr<RDaosPool>` is invoked
142 /// after (which calls `daos_pool_disconect()`).
143 std::unique_ptr<RDaosContainer> fDaosContainer;
144 /// Page identifier for the next committed page; it is automatically incremented in `CommitSealedPageImpl()`
145 std::atomic<std::uint64_t> fPageId{0};
146 /// Cluster group counter for the next committed cluster pagelist; incremented in `CommitClusterGroupImpl()`
147 std::atomic<std::uint64_t> fClusterGroupId{0};
148 /// \brief A URI to a DAOS pool of the form 'daos://pool-label/container-label'
149 std::string fURI;
150 /// Tracks the number of bytes committed to the current cluster
151 std::uint64_t fNBytesCurrentCluster{0};
152
155
156protected:
157 void CreateImpl(const RNTupleModel &model, unsigned char *serializedHeader, std::uint32_t length) final;
158 RNTupleLocator CommitPageImpl(ColumnHandle_t columnHandle, const RPage &page) final;
160 std::vector<RNTupleLocator> CommitSealedPageVImpl(std::span<RPageStorage::RSealedPageGroup> ranges) final;
161 std::uint64_t CommitClusterImpl(NTupleSize_t nEntries) final;
162 RNTupleLocator CommitClusterGroupImpl(unsigned char *serializedPageList, std::uint32_t length) final;
163 void CommitDatasetImpl(unsigned char *serializedFooter, std::uint32_t length) final;
164 void WriteNTupleHeader(const void *data, size_t nbytes, size_t lenHeader);
165 void WriteNTupleFooter(const void *data, size_t nbytes, size_t lenFooter);
166 void WriteNTupleAnchor();
167
168public:
169 RPageSinkDaos(std::string_view ntupleName, std::string_view uri, const RNTupleWriteOptions &options);
170 ~RPageSinkDaos() override;
171
172 RPage ReservePage(ColumnHandle_t columnHandle, std::size_t nElements) final;
173 void ReleasePage(RPage &page) final;
174};
175
176// clang-format off
177/**
178\class ROOT::Experimental::Detail::RPageAllocatorDaos
179\ingroup NTuple
180\brief Manages pages read from a DAOS container
181*/
182// clang-format on
184public:
185 static RPage NewPage(ColumnId_t columnId, void *mem, std::size_t elementSize, std::size_t nElements);
186 static void DeletePage(const RPage &page);
187};
188
189// clang-format off
190/**
191\class ROOT::Experimental::Detail::RPageSourceDaos
192\ingroup NTuple
193\brief Storage provider that reads ntuple pages from a DAOS container
194*/
195// clang-format on
197private:
198 /// Summarizes cluster-level information that are necessary to populate a certain page.
199 /// Used by PopulatePageFromCluster().
202 /// Location of the page on disk
204 /// The first element number of the page's column in the given cluster
205 std::uint64_t fColumnOffset = 0;
206 };
207
209
210 /// Populated pages might be shared; the memory buffer is managed by the RPageAllocatorDaos
211 std::unique_ptr<RPageAllocatorDaos> fPageAllocator;
212 // TODO: the page pool should probably be handled by the base class.
213 /// The page pool might, at some point, be used by multiple page sources
214 std::shared_ptr<RPagePool> fPagePool;
215 /// The last cluster from which a page got populated. Points into fClusterPool->fPool
217 /// A container that stores object data (header/footer, pages, etc.)
218 std::unique_ptr<RDaosContainer> fDaosContainer;
219 /// A URI to a DAOS pool of the form 'daos://pool-label/container-label'
220 std::string fURI;
221 /// The cluster pool asynchronously preloads the next few clusters
222 std::unique_ptr<RClusterPool> fClusterPool;
223
225
226 RPage PopulatePageFromCluster(ColumnHandle_t columnHandle, const RClusterInfo &clusterInfo,
227 ClusterSize_t::ValueType idxInCluster);
228
229protected:
231 void UnzipClusterImpl(RCluster *cluster) final;
232
233public:
234 RPageSourceDaos(std::string_view ntupleName, std::string_view uri, const RNTupleReadOptions &options);
235 /// The cloned page source creates a new connection to the pool/container.
236 /// The meta-data (header and footer) is reread and parsed by the clone.
237 std::unique_ptr<RPageSource> Clone() const final;
238 ~RPageSourceDaos() override;
239
240 RPage PopulatePage(ColumnHandle_t columnHandle, NTupleSize_t globalIndex) final;
241 RPage PopulatePage(ColumnHandle_t columnHandle, const RClusterIndex &clusterIndex) final;
242 void ReleasePage(RPage &page) final;
243
244 void LoadSealedPage(DescriptorId_t columnId, const RClusterIndex &clusterIndex, RSealedPage &sealedPage) final;
245
246 std::vector<std::unique_ptr<RCluster>> LoadClusters(std::span<RCluster::RKey> clusterKeys) final;
247
248 /// Return the object class used for user data OIDs in this ntuple.
249 std::string GetObjectClass() const;
250};
251
252} // namespace Detail
253
254} // namespace Experimental
255} // namespace ROOT
256
257#endif
#define h(i)
Definition RSha256.hxx:106
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
An in-memory subset of the packed and compressed pages of a cluster.
Definition RCluster.hxx:154
A RDaosContainer provides read/write access to objects in a given container.
Definition RDaos.hxx:149
Helper class to uncompress data blocks in the ROOT compression frame format.
Manages pages read from a DAOS container.
static RPage NewPage(ColumnId_t columnId, void *mem, std::size_t elementSize, std::size_t nElements)
Storage provider that writes ntuple pages to into a DAOS container.
void ReleasePage(RPage &page) final
Every page store needs to be able to free pages it handed out.
RNTupleLocator CommitSealedPageImpl(DescriptorId_t columnId, const RPageStorage::RSealedPage &sealedPage) final
std::uint64_t fNBytesCurrentCluster
Tracks the number of bytes committed to the current cluster.
void WriteNTupleFooter(const void *data, size_t nbytes, size_t lenFooter)
void WriteNTupleHeader(const void *data, size_t nbytes, size_t lenHeader)
std::string fURI
A URI to a DAOS pool of the form 'daos://pool-label/container-label'.
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...
std::uint64_t CommitClusterImpl(NTupleSize_t nEntries) final
Returns the number of bytes written to storage (excluding metadata)
void CommitDatasetImpl(unsigned char *serializedFooter, std::uint32_t length) final
RNTupleLocator CommitPageImpl(ColumnHandle_t columnHandle, const RPage &page) final
std::atomic< std::uint64_t > fClusterGroupId
Cluster group counter for the next committed cluster pagelist; incremented in CommitClusterGroupImpl(...
void CreateImpl(const RNTupleModel &model, unsigned char *serializedHeader, std::uint32_t length) final
std::vector< RNTupleLocator > CommitSealedPageVImpl(std::span< RPageStorage::RSealedPageGroup > ranges) final
Vector commit of preprocessed pages.
RPage ReservePage(ColumnHandle_t columnHandle, std::size_t nElements) final
Get a new, empty page for the given column that can be filled with up to nElements.
std::atomic< std::uint64_t > fPageId
Page identifier for the next committed page; it is automatically incremented in CommitSealedPageImpl(...
std::unique_ptr< RDaosContainer > fDaosContainer
Underlying DAOS container.
std::unique_ptr< RPageAllocatorHeap > fPageAllocator
Abstract interface to write data into an ntuple.
Storage provider that reads ntuple pages from a DAOS container.
std::unique_ptr< RDaosContainer > fDaosContainer
A container that stores object data (header/footer, pages, etc.)
void LoadSealedPage(DescriptorId_t columnId, const RClusterIndex &clusterIndex, RSealedPage &sealedPage) final
Read the packed and compressed bytes of a page into the memory buffer provided by selaedPage.
void ReleasePage(RPage &page) final
Every page store needs to be able to free pages it handed out.
std::string fURI
A URI to a DAOS pool of the form 'daos://pool-label/container-label'.
void UnzipClusterImpl(RCluster *cluster) final
std::vector< std::unique_ptr< RCluster > > LoadClusters(std::span< RCluster::RKey > clusterKeys) final
Populates all the pages of the given cluster ids and columns; it is possible that some columns do not...
RPage PopulatePage(ColumnHandle_t columnHandle, NTupleSize_t globalIndex) final
Allocates and fills a page that contains the index-th element.
RPage PopulatePageFromCluster(ColumnHandle_t columnHandle, const RClusterInfo &clusterInfo, ClusterSize_t::ValueType idxInCluster)
RCluster * fCurrentCluster
The last cluster from which a page got populated. Points into fClusterPool->fPool.
std::string GetObjectClass() const
Return the object class used for user data OIDs in this ntuple.
std::shared_ptr< RPagePool > fPagePool
The page pool might, at some point, be used by multiple page sources.
std::unique_ptr< RPageAllocatorDaos > fPageAllocator
Populated pages might be shared; the memory buffer is managed by the RPageAllocatorDaos.
std::unique_ptr< RClusterPool > fClusterPool
The cluster pool asynchronously preloads the next few clusters.
std::unique_ptr< RPageSource > Clone() const final
The cloned page source creates a new connection to the pool/container.
Abstract interface to read data from an ntuple.
RColumnHandle ColumnHandle_t
The column handle identifies a column with the current open page storage.
A page is a slice of a column that is mapped into memory.
Definition RPage.hxx:41
Addresses a column element or field item relative to a particular cluster, instead of a global NTuple...
A helper class for piece-wise construction of an RNTupleDescriptor.
The on-storage meta-data of an ntuple.
The RNTupleModel encapulates the schema of an ntuple.
Common user-tunable settings for reading ntuples.
Common user-tunable settings for storing ntuples.
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:207
std::uint64_t NTupleSize_t
Integer type long enough to hold the maximum number of entries in a column.
std::uint64_t DescriptorId_t
Distriniguishes elements of the same type within a descriptor, e.g. different fields.
std::int64_t ColumnId_t
Uniquely identifies a physical column within the scope of the current process, used to tag pages.
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.
Helper structure concentrating the functionality required to locate an ntuple within a DAOS container...
std::optional< ROOT::Experimental::Detail::RDaosNTupleAnchor > fAnchor
static ntuple_index_t Hash(const std::string &ntupleName)
int InitNTupleDescriptorBuilder(RDaosContainer &cont, RNTupleDecompressor &decompressor, RNTupleDescriptorBuilder &builder)
static std::pair< RDaosContainerNTupleLocator, RNTupleDescriptorBuilder > LocateNTuple(RDaosContainer &cont, const std::string &ntupleName, RNTupleDecompressor &decompressor)
Entry point for an RNTuple in a DAOS container.
std::uint32_t fNBytesFooter
The size of the compressed ntuple footer.
std::uint32_t fNBytesHeader
The size of the compressed ntuple header.
std::string fObjClass
The object class for user data OIDs, e.g. SX
std::uint32_t fVersion
Allows for evolving the struct in future versions.
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 Serialize(void *buffer) const
bool operator==(const RDaosNTupleAnchor &other) const
std::uint32_t fLenFooter
The size of the uncompressed ntuple footer.
Summarizes cluster-level information that are necessary to populate a certain page.
RClusterDescriptor::RPageRange::RPageInfoExtended fPageInfo
Location of the page on disk.
std::uint64_t fColumnOffset
The first element number of the page's column in the given cluster.
A sealed page contains the bytes of a page as written to storage (packed & compressed).
Generic information about the physical location of data.