OmniSciDB  95562058bd
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
InsertOrderFragmenter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 #pragma once
23 
24 #include <map>
25 #include <mutex>
26 #include <unordered_map>
27 #include <vector>
28 
29 #include "DataMgr/Chunk/Chunk.h"
30 #include "DataMgr/MemoryLevel.h"
31 #include "FragmentDefaultValues.h"
35 #include "Shared/types.h"
36 
37 class Executor;
38 
39 namespace Data_Namespace {
40 class DataMgr;
41 }
42 
43 namespace Fragmenter_Namespace {
44 
53  public:
55 
57  const std::vector<int> chunkKeyPrefix,
58  std::vector<Chunk_NS::Chunk>& chunkVec,
59  Data_Namespace::DataMgr* dataMgr,
61  const int physicalTableId,
62  const int shard,
63  const size_t maxFragmentRows = DEFAULT_FRAGMENT_ROWS,
64  const size_t maxChunkSize = DEFAULT_MAX_CHUNK_SIZE,
65  const size_t pageSize = DEFAULT_PAGE_SIZE /*default 1MB*/,
66  const size_t maxRows = DEFAULT_MAX_ROWS,
68  const bool uses_foreign_storage = false);
69 
70  ~InsertOrderFragmenter() override;
77  // virtual void getFragmentsForQuery(QueryInfo &queryInfo, const void *predicate = 0);
79 
87  void insertData(InsertData& insertDataStruct) override;
88 
89  void insertDataNoCheckpoint(InsertData& insertDataStruct) override;
90 
91  void dropFragmentsToSize(const size_t maxRows) override;
92 
94  const int fragment_id,
95  const std::shared_ptr<ChunkMetadata> metadata) override;
96 
97  void updateChunkStats(
98  const ColumnDescriptor* cd,
99  std::unordered_map</*fragment_id*/ int, ChunkStats>& stats_map) override;
100 
101  FragmentInfo* getFragmentInfo(const int fragment_id) const override;
102 
106  inline int getFragmenterId() override { return chunkKeyPrefix_.back(); }
107  inline std::vector<int> getChunkKeyPrefix() const { return chunkKeyPrefix_; }
111  inline std::string getFragmenterType() override { return fragmenterType_; }
112  size_t getNumRows() override { return numTuples_; }
113  void setNumRows(const size_t numTuples) override { numTuples_ = numTuples; }
114 
115  void updateColumn(const Catalog_Namespace::Catalog* catalog,
116  const TableDescriptor* td,
117  const ColumnDescriptor* cd,
118  const int fragment_id,
119  const std::vector<uint64_t>& frag_offsets,
120  const std::vector<ScalarTargetValue>& rhs_values,
121  const SQLTypeInfo& rhs_type,
122  const Data_Namespace::MemoryLevel memory_level,
123  UpdelRoll& updel_roll) override;
124 
125  void updateColumns(const Catalog_Namespace::Catalog* catalog,
126  const TableDescriptor* td,
127  const int fragmentId,
128  const std::vector<TargetMetaInfo> sourceMetaInfo,
129  const std::vector<const ColumnDescriptor*> columnDescriptors,
130  const RowDataProvider& sourceDataProvider,
131  const size_t indexOffFragmentOffsetColumn,
132  const Data_Namespace::MemoryLevel memoryLevel,
133  UpdelRoll& updelRoll,
134  Executor* executor) override;
135 
136  void updateColumn(const Catalog_Namespace::Catalog* catalog,
137  const TableDescriptor* td,
138  const ColumnDescriptor* cd,
139  const int fragment_id,
140  const std::vector<uint64_t>& frag_offsets,
141  const ScalarTargetValue& rhs_value,
142  const SQLTypeInfo& rhs_type,
143  const Data_Namespace::MemoryLevel memory_level,
144  UpdelRoll& updel_roll) override;
145 
146  void updateColumnMetadata(const ColumnDescriptor* cd,
147  FragmentInfo& fragment,
148  std::shared_ptr<Chunk_NS::Chunk> chunk,
149  const bool null,
150  const double dmax,
151  const double dmin,
152  const int64_t lmax,
153  const int64_t lmin,
154  const SQLTypeInfo& rhs_type,
155  UpdelRoll& updel_roll) override;
156 
157  void updateMetadata(const Catalog_Namespace::Catalog* catalog,
158  const MetaDataKey& key,
159  UpdelRoll& updel_roll) override;
160 
161  void compactRows(const Catalog_Namespace::Catalog* catalog,
162  const TableDescriptor* td,
163  const int fragment_id,
164  const std::vector<uint64_t>& frag_offsets,
165  const Data_Namespace::MemoryLevel memory_level,
166  UpdelRoll& updel_roll) override;
167 
168  const std::vector<uint64_t> getVacuumOffsets(
169  const std::shared_ptr<Chunk_NS::Chunk>& chunk) override;
170 
172  const FragmentInfo& fragment,
173  const Data_Namespace::MemoryLevel memory_level);
174 
175  void dropColumns(const std::vector<int>& columnIds) override;
176 
177  bool hasDeletedRows(const int delete_column_id) override;
178 
179  protected:
180  std::vector<int> chunkKeyPrefix_;
181  std::map<int, Chunk_NS::Chunk>
183  std::deque<std::unique_ptr<FragmentInfo>>
185  // int currentInsertBufferFragmentId_;
188  const int physicalTableId_;
189  const int shard_;
191  size_t pageSize_; /* Page size in bytes of each page making up a given chunk - passed to
192  BufferMgr in createChunk() */
193  size_t numTuples_;
196  size_t maxRows_;
197  std::string fragmenterType_;
199  fragmentInfoMutex_; // to prevent read-write conflicts for fragmentInfoVec_
201  insertMutex_; // to prevent race conditions on insert - only one insert statement
202  // should be going to a table at a time
207  std::unordered_map<int, size_t> varLenColInfo_;
208  std::shared_ptr<std::mutex> mutex_access_inmem_states;
209 
220  void deleteFragments(const std::vector<int>& dropFragIds);
221 
222  void getChunkMetadata();
223 
224  void lockInsertCheckpointData(const InsertData& insertDataStruct);
225  void insertDataImpl(InsertData& insertDataStruct);
226  void replicateData(const InsertData& insertDataStruct);
227 
230  // FIX-ME: Temporary lock; needs removing.
231  mutable std::mutex temp_mutex_;
232 
233  FragmentInfo& getFragmentInfoFromId(const int fragment_id);
234 
235  auto vacuum_fixlen_rows(const FragmentInfo& fragment,
236  const std::shared_ptr<Chunk_NS::Chunk>& chunk,
237  const std::vector<uint64_t>& frag_offsets);
238  auto vacuum_varlen_rows(const FragmentInfo& fragment,
239  const std::shared_ptr<Chunk_NS::Chunk>& chunk,
240  const std::vector<uint64_t>& frag_offsets);
241 };
242 
243 } // namespace Fragmenter_Namespace
void updateMetadata(const Catalog_Namespace::Catalog *catalog, const MetaDataKey &key, UpdelRoll &updel_roll) override
void dropColumns(const std::vector< int > &columnIds) override
FragmentInfo & getFragmentInfoFromId(const int fragment_id)
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:97
TableInfo getFragmentsForQuery() override
returns (inside QueryInfo) object all ids and row sizes of fragments
InsertOrderFragmenter & operator=(const InsertOrderFragmenter &)
std::pair< const TableDescriptor *, Fragmenter_Namespace::FragmentInfo * > MetaDataKey
Definition: UpdelRoll.h:40
std::deque< std::unique_ptr< FragmentInfo > > fragmentInfoVec_
void dropFragmentsToSize(const size_t maxRows) override
Will truncate table to less than maxRows by dropping fragments.
InsertOrderFragmenter(const std::vector< int > chunkKeyPrefix, std::vector< Chunk_NS::Chunk > &chunkVec, Data_Namespace::DataMgr *dataMgr, Catalog_Namespace::Catalog *catalog, const int physicalTableId, const int shard, const size_t maxFragmentRows=DEFAULT_FRAGMENT_ROWS, const size_t maxChunkSize=DEFAULT_MAX_CHUNK_SIZE, const size_t pageSize=DEFAULT_PAGE_SIZE, const size_t maxRows=DEFAULT_MAX_ROWS, const Data_Namespace::MemoryLevel defaultInsertLevel=Data_Namespace::DISK_LEVEL, const bool uses_foreign_storage=false)
void insertData(InsertData &insertDataStruct) override
appends data onto the most recently occuring fragment, creating a new one if necessary ...
std::shared_ptr< std::mutex > mutex_access_inmem_states
#define DEFAULT_MAX_CHUNK_SIZE
void updateColumn(const Catalog_Namespace::Catalog *catalog, const TableDescriptor *td, const ColumnDescriptor *cd, const int fragment_id, const std::vector< uint64_t > &frag_offsets, const std::vector< ScalarTargetValue > &rhs_values, const SQLTypeInfo &rhs_type, const Data_Namespace::MemoryLevel memory_level, UpdelRoll &updel_roll) override
void updateColumns(const Catalog_Namespace::Catalog *catalog, const TableDescriptor *td, const int fragmentId, const std::vector< TargetMetaInfo > sourceMetaInfo, const std::vector< const ColumnDescriptor * > columnDescriptors, const RowDataProvider &sourceDataProvider, const size_t indexOffFragmentOffsetColumn, const Data_Namespace::MemoryLevel memoryLevel, UpdelRoll &updelRoll, Executor *executor) override
void insertDataImpl(InsertData &insertDataStruct)
The InsertOrderFragmenter is a child class of AbstractFragmenter, and fragments data in insert order...
auto vacuum_fixlen_rows(const FragmentInfo &fragment, const std::shared_ptr< Chunk_NS::Chunk > &chunk, const std::vector< uint64_t > &frag_offsets)
void updateColumnChunkMetadata(const ColumnDescriptor *cd, const int fragment_id, const std::shared_ptr< ChunkMetadata > metadata) override
Updates the metadata for a column chunk.
void insertDataNoCheckpoint(InsertData &insertDataStruct) override
Given data wrapped in an InsertData struct, inserts it into the correct partitions No locks and check...
#define DEFAULT_MAX_ROWS
std::string getFragmenterType() override
get fragmenter&#39;s type (as string
const std::vector< uint64_t > getVacuumOffsets(const std::shared_ptr< Chunk_NS::Chunk > &chunk) override
std::shared_timed_mutex mapd_shared_mutex
Used by Fragmenter classes to store info about each fragment - the fragment id and number of tuples(r...
Definition: Fragmenter.h:78
void deleteFragments(const std::vector< int > &dropFragIds)
void setNumRows(const size_t numTuples) override
specifies the content in-memory of a row in the column metadata table
FragmentInfo * createNewFragment(const Data_Namespace::MemoryLevel memory_level=Data_Namespace::DISK_LEVEL)
creates new fragment, calling createChunk() method of BufferMgr to make a new chunk for each column o...
#define DEFAULT_PAGE_SIZE
void updateChunkStats(const ColumnDescriptor *cd, std::unordered_map< int, ChunkStats > &stats_map) override
Update chunk stats.
void lockInsertCheckpointData(const InsertData &insertDataStruct)
void compactRows(const Catalog_Namespace::Catalog *catalog, const TableDescriptor *td, const int fragment_id, const std::vector< uint64_t > &frag_offsets, const Data_Namespace::MemoryLevel memory_level, UpdelRoll &updel_roll) override
FragmentInfo * getFragmentInfo(const int fragment_id) const override
Retrieve the fragment info object for an individual fragment for editing.
#define DEFAULT_FRAGMENT_ROWS
auto getChunksForAllColumns(const TableDescriptor *td, const FragmentInfo &fragment, const Data_Namespace::MemoryLevel memory_level)
std::unordered_map< int, size_t > varLenColInfo_
The data to be inserted using the fragment manager.
Definition: Fragmenter.h:59
void replicateData(const InsertData &insertDataStruct)
Executor(const ExecutorId id, const size_t block_size_x, const size_t grid_size_x, const size_t max_gpu_slab_size, const std::string &debug_dir, const std::string &debug_file)
Definition: Execute.cpp:131
specifies the content in-memory of a row in the table metadata table
int getFragmenterId() override
get fragmenter&#39;s id
std::map< int, Chunk_NS::Chunk > columnMap_
auto vacuum_varlen_rows(const FragmentInfo &fragment, const std::shared_ptr< Chunk_NS::Chunk > &chunk, const std::vector< uint64_t > &frag_offsets)
bool hasDeletedRows(const int delete_column_id) override
Iterates through chunk metadata to return whether any rows have been deleted.
void updateColumnMetadata(const ColumnDescriptor *cd, FragmentInfo &fragment, std::shared_ptr< Chunk_NS::Chunk > chunk, const bool null, const double dmax, const double dmin, const int64_t lmax, const int64_t lmin, const SQLTypeInfo &rhs_type, UpdelRoll &updel_roll) override
boost::variant< int64_t, double, float, NullableString > ScalarTargetValue
Definition: TargetValue.h:156