Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RPageSinkBuf.hxx
Go to the documentation of this file.
1/// \file ROOT/RPageSinkBuf.hxx
2/// \author Jakob Blomer <jblomer@cern.ch>
3/// \author Max Orok <maxwellorok@gmail.com>
4/// \author Javier Lopez-Gomez <javier.lopez.gomez@cern.ch>
5/// \date 2021-03-17
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_RPageSinkBuf
16#define ROOT_RPageSinkBuf
17
19#include <ROOT/RPageStorage.hxx>
20
21#include <atomic>
22#include <cstddef>
23#include <deque>
24#include <functional>
25#include <iterator>
26#include <memory>
27#include <tuple>
28
29namespace ROOT {
30namespace Internal {
31
32// clang-format off
33/**
34\class ROOT::Internal::RPageSinkBuf
35\ingroup NTuple
36\brief Wrapper sink that coalesces cluster column page writes
37*/
38// clang-format on
39class RPageSinkBuf : public RPageSink {
40 /// A buffered column. The column is not responsible for RPage memory management (i.e. ReservePage),
41 /// which is handled by the enclosing RPageSinkBuf.
42 class RColumnBuf {
43 public:
44 struct RPageZipItem {
46 // Compression scratch buffer for fSealedPage.
47 std::unique_ptr<unsigned char[]> fBuf;
49 bool IsSealed() const { return fSealedPage != nullptr; }
50 };
51
52 RColumnBuf() = default;
53 RColumnBuf(const RColumnBuf&) = delete;
54 RColumnBuf& operator=(const RColumnBuf&) = delete;
55 RColumnBuf(RColumnBuf &&) = default;
58
59 /// Returns a reference to the newly buffered page. The reference remains
60 /// valid until DropBufferedPages().
62 {
63 // Safety: Insertion at the end of a deque never invalidates references
64 // to existing elements.
65 return fBufferedPages.emplace_back();
66 }
67 bool IsEmpty() const { return fBufferedPages.empty(); }
68 bool HasSealedPagesOnly() const { return fBufferedPages.size() == fSealedPages.size(); }
70
71 void DropBufferedPages();
72
73 // The returned reference points to a default-constructed RSealedPage. It can be used
74 // to fill in data after sealing.
76 {
77 return fSealedPages.emplace_back();
78 }
79
80 private:
81 /// Using a deque guarantees that element iterators are never invalidated
82 /// by appends to the end of the iterator by BufferPage.
83 std::deque<RPageZipItem> fBufferedPages;
84 /// Pages that have been already sealed by a concurrent task. A vector commit can be issued if all
85 /// buffered pages have been sealed.
86 /// Note that each RSealedPage refers to the same buffer as `fBufferedPages[i].fBuf` for some value of `i`, and
87 /// thus owned by RPageZipItem
89 };
90
91 /// I/O performance counters that get registered in fMetrics
100 std::unique_ptr<RCounters> fCounters;
101 /// The inner sink, responsible for actually performing I/O.
102 std::unique_ptr<RPageSink> fInnerSink;
103 /// The buffered page sink maintains a copy of the RNTupleModel for the inner sink.
104 /// For the unbuffered case, the RNTupleModel is instead managed by a RNTupleWriter.
105 std::unique_ptr<ROOT::RNTupleModel> fInnerModel;
106 /// The sum of uncompressed bytes in buffered pages. Used to heuristically reduce the memory usage.
107 std::atomic<std::size_t> fBufferedUncompressed = 0;
108 /// Vector of buffered column pages. Indexed by column id.
109 std::vector<RColumnBuf> fBufferedColumns;
110 /// Columns committed as suppressed are stored and passed to the inner sink at cluster commit
111 std::vector<DescriptorId_t> fSuppressedColumns;
114 RNTupleTaskScheduler *fTaskScheduler = nullptr; ///< For parallel page compression
115
116 void WaitForAllTasks();
117 void ConnectFields(const std::vector<ROOT::RFieldBase *> &fields, ROOT::NTupleSize_t firstEntry);
118 void FlushClusterImpl(const std::function<void(void)> &FlushClusterFn);
119
120 void InitImpl(ROOT::RNTupleModel &model) final;
122
123public:
124 explicit RPageSinkBuf(std::unique_ptr<RPageSink> inner);
125 RPageSinkBuf(const RPageSinkBuf&) = delete;
126 RPageSinkBuf& operator=(const RPageSinkBuf&) = delete;
128 RPageSinkBuf &operator=(RPageSinkBuf &&) = delete;
129 ~RPageSinkBuf() override;
130
131 void SetTaskScheduler(RNTupleTaskScheduler *taskScheduler) final { fTaskScheduler = taskScheduler; }
132
133 DescriptorId_t AddColumn(ROOT::DescriptorId_t fieldId, const RColumn &column) final;
134
135 const ROOT::RNTupleDescriptor &GetDescriptor() const final;
136
137 void UpdateSchema(const RNTupleModelChangeset &changeset, ROOT::NTupleSize_t firstEntry) final;
138 void UpdateExtraTypeInfo(const ROOT::RExtraTypeInfoDescriptor &extraTypeInfo) final;
139
140 void CommitSuppressedColumn(DescriptorId_t physicalColumnId) final;
141 void CommitPage(DescriptorId_t physicalColumnId, const RColumnElementBase &elem, const RPage &page) final;
142 void CommitSealedPage(ROOT::DescriptorId_t physicalColumnId, const RSealedPage &sealedPage) final;
143 void CommitSealedPageV(std::span<RSealedPageGroup> ranges) final;
144 std::uint64_t CommitCluster(ROOT::NTupleSize_t nNewEntries) final;
145 RStagedCluster StageCluster(ROOT::NTupleSize_t nNewEntries) final;
146 void CommitStagedClusters(std::span<RStagedCluster> clusters) final;
147 void CommitClusterGroup() final;
148 void CommitAttributeSet(std::string_view attrSetName, const RNTupleLink &attrAnchorInfo) final;
149
150 RPage ReservePage(RWriteColumn &column, std::size_t nElements) final;
151
152 std::unique_ptr<RPageSink> CloneAsHidden(std::string_view name, const RNTupleWriteOptions &opts) const final;
153}; // RPageSinkBuf
154
155} // namespace Internal
156} // namespace ROOT
157
158#endif
char name[80]
Definition TGX11.cxx:142
A thread-safe integral performance counter.
A non thread-safe integral performance counter.
A column element encapsulates the translation between basic C++ types and their column representation...
A column is a storage-backed array of a simple, fixed-size type, from which pages can be mapped into ...
Definition RColumn.hxx:40
The interface of a task scheduler to schedule page (de)compression tasks.
std::deque< RPageZipItem > fBufferedPages
Using a deque guarantees that element iterators are never invalidated by appends to the end of the it...
RColumnBuf & operator=(const RColumnBuf &)=delete
RColumnBuf & operator=(RColumnBuf &&)=default
SealedPageSequence_t fSealedPages
Pages that have been already sealed by a concurrent task.
RPageZipItem & BufferPage()
Returns a reference to the newly buffered page.
const SealedPageSequence_t & GetSealedPages() const
RColumnBuf(const RColumnBuf &)=delete
Wrapper sink that coalesces cluster column page writes.
std::unique_ptr< RPageSink > CloneAsHidden(std::string_view name, const RNTupleWriteOptions &opts) const final
Creates a new sink with the same underlying storage as this but writing to a different RNTuple named ...
void CommitStagedClusters(std::span< RStagedCluster > clusters) final
Commit staged clusters, logically appending them to the ntuple descriptor.
std::unique_ptr< RCounters > fCounters
ROOT::DescriptorId_t fNColumns
std::uint64_t CommitCluster(ROOT::NTupleSize_t nNewEntries) final
Finalize the current cluster and create a new one for the following data.
std::atomic< std::size_t > fBufferedUncompressed
The sum of uncompressed bytes in buffered pages. Used to heuristically reduce the memory usage.
void SetTaskScheduler(RNTupleTaskScheduler *taskScheduler) final
void UpdateSchema(const RNTupleModelChangeset &changeset, ROOT::NTupleSize_t firstEntry) final
Incorporate incremental changes to the model into the ntuple descriptor.
void FlushClusterImpl(const std::function< void(void)> &FlushClusterFn)
RNTupleTaskScheduler * fTaskScheduler
For parallel page compression.
std::vector< DescriptorId_t > fSuppressedColumns
Columns committed as suppressed are stored and passed to the inner sink at cluster commit.
void CommitSealedPage(ROOT::DescriptorId_t physicalColumnId, const RSealedPage &sealedPage) final
Write a preprocessed page to storage. The column must have been added before.
void CommitPage(DescriptorId_t physicalColumnId, const RColumnElementBase &elem, const RPage &page) final
Write a page to the storage. The column must have been added before.
ROOT::DescriptorId_t fNFields
void CommitSuppressedColumn(DescriptorId_t physicalColumnId) final
Commits a suppressed column for the current cluster.
void CommitAttributeSet(std::string_view attrSetName, const RNTupleLink &attrAnchorInfo) final
Adds the given anchor information (name + locator) into the main RNTuple's descriptor as an attribute...
RNTupleLink CommitDatasetImpl() final
const ROOT::RNTupleDescriptor & GetDescriptor() const final
Return the RNTupleDescriptor being constructed.
RPage ReservePage(RWriteColumn &column, std::size_t nElements) final
Get a new, empty page for the given column that can be filled with up to nElements; nElements must be...
void UpdateExtraTypeInfo(const ROOT::RExtraTypeInfoDescriptor &extraTypeInfo) final
Adds an extra type information record to schema.
std::unique_ptr< ROOT::RNTupleModel > fInnerModel
The buffered page sink maintains a copy of the RNTupleModel for the inner sink.
std::vector< RColumnBuf > fBufferedColumns
Vector of buffered column pages. Indexed by column id.
DescriptorId_t AddColumn(ROOT::DescriptorId_t fieldId, const RColumn &column) final
Add a column belonging to a certain field to the descriptor and return its on-disk ID.
RStagedCluster StageCluster(ROOT::NTupleSize_t nNewEntries) final
Stage the current cluster and create a new one for the following data.
void CommitClusterGroup() final
Write out the page locations (page list envelope) for all the committed clusters since the last call ...
void InitImpl(ROOT::RNTupleModel &model) final
void CommitSealedPageV(std::span< RSealedPageGroup > ranges) final
Write a vector of preprocessed pages to storage. The corresponding columns must have been added befor...
std::unique_ptr< RPageSink > fInnerSink
The inner sink, responsible for actually performing I/O.
void ConnectFields(const std::vector< ROOT::RFieldBase * > &fields, ROOT::NTupleSize_t firstEntry)
Abstract interface to write data into an ntuple.
A page is a slice of a column that is mapped into memory.
Definition RPage.hxx:43
Field specific extra type information from the header / extenstion header.
The on-storage metadata of an RNTuple.
The RNTupleModel encapulates the schema of an RNTuple.
Common user-tunable settings for storing RNTuples.
std::deque< RSealedPage > SealedPageSequence_t
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.
The incremental changes to a RNTupleModel
I/O performance counters that get registered in fMetrics.
ROOT::Experimental::Detail::RNTupleTickCounter< ROOT::Experimental::Detail::RNTupleAtomicCounter > & fTimeCpuZip
ROOT::Experimental::Detail::RNTupleTickCounter< ROOT::Experimental::Detail::RNTuplePlainCounter > & fTimeCpuCriticalSection
ROOT::Experimental::Detail::RNTupleAtomicCounter & fTimeWallZip
ROOT::Experimental::Detail::RNTuplePlainCounter & fParallelZip
ROOT::Experimental::Detail::RNTuplePlainCounter & fTimeWallCriticalSection
A range of sealed pages referring to the same column that can be used for vector commit.
A sealed page contains the bytes of a page as written to storage (packed & compressed).