OmniSciDB  eb3a3d0a03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  *
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  */
22 #pragma once
24 #include <map>
25 #include <mutex>
26 #include <unordered_map>
27 #include <unordered_set>
28 #include <vector>
30 #include "DataMgr/Chunk/Chunk.h"
31 #include "DataMgr/MemoryLevel.h"
32 #include "FragmentDefaultValues.h"
36 #include "Shared/types.h"
38 class Executor;
40 namespace Data_Namespace {
41 class DataMgr;
42 }
44 namespace Fragmenter_Namespace {
54  public:
58  const std::vector<int> chunkKeyPrefix,
59  std::vector<Chunk_NS::Chunk>& chunkVec,
60  Data_Namespace::DataMgr* dataMgr,
62  const int physicalTableId,
63  const int shard,
64  const size_t maxFragmentRows = DEFAULT_FRAGMENT_ROWS,
65  const size_t maxChunkSize = DEFAULT_MAX_CHUNK_SIZE,
66  const size_t pageSize = DEFAULT_PAGE_SIZE /*default 1MB*/,
67  const size_t maxRows = DEFAULT_MAX_ROWS,
69  const bool uses_foreign_storage = false);
71  ~InsertOrderFragmenter() override;
77  size_t getNumFragments() override;
85  // virtual void getFragmentsForQuery(QueryInfo &queryInfo, const void *predicate = 0);
95  void insertData(InsertData& insert_data_struct) override;
97  void insertDataNoCheckpoint(InsertData& insert_data_struct) override;
99  void dropFragmentsToSize(const size_t maxRows) override;
102  const int fragment_id,
103  const std::shared_ptr<ChunkMetadata> metadata) override;
105  void updateChunkStats(const ColumnDescriptor* cd,
106  std::unordered_map</*fragment_id*/ int, ChunkStats>& stats_map,
107  std::optional<Data_Namespace::MemoryLevel> memory_level) override;
109  FragmentInfo* getFragmentInfo(const int fragment_id) const override;
114  inline int getFragmenterId() override { return chunkKeyPrefix_.back(); }
115  inline std::vector<int> getChunkKeyPrefix() const { return chunkKeyPrefix_; }
119  inline std::string getFragmenterType() override { return fragmenterType_; }
120  size_t getNumRows() override { return numTuples_; }
121  void setNumRows(const size_t numTuples) override { numTuples_ = numTuples; }
123  std::optional<ChunkUpdateStats> updateColumn(
124  const Catalog_Namespace::Catalog* catalog,
125  const TableDescriptor* td,
126  const ColumnDescriptor* cd,
127  const int fragment_id,
128  const std::vector<uint64_t>& frag_offsets,
129  const std::vector<ScalarTargetValue>& rhs_values,
130  const SQLTypeInfo& rhs_type,
131  const Data_Namespace::MemoryLevel memory_level,
132  UpdelRoll& updel_roll) override;
134  void updateColumns(const Catalog_Namespace::Catalog* catalog,
135  const TableDescriptor* td,
136  const int fragmentId,
137  const std::vector<TargetMetaInfo> sourceMetaInfo,
138  const std::vector<const ColumnDescriptor*> columnDescriptors,
139  const RowDataProvider& sourceDataProvider,
140  const size_t indexOffFragmentOffsetColumn,
141  const Data_Namespace::MemoryLevel memoryLevel,
142  UpdelRoll& updelRoll,
143  Executor* executor) override;
145  void updateColumn(const Catalog_Namespace::Catalog* catalog,
146  const TableDescriptor* td,
147  const ColumnDescriptor* cd,
148  const int fragment_id,
149  const std::vector<uint64_t>& frag_offsets,
150  const ScalarTargetValue& rhs_value,
151  const SQLTypeInfo& rhs_type,
152  const Data_Namespace::MemoryLevel memory_level,
153  UpdelRoll& updel_roll) override;
155  void updateColumnMetadata(const ColumnDescriptor* cd,
156  FragmentInfo& fragment,
157  std::shared_ptr<Chunk_NS::Chunk> chunk,
158  const UpdateValuesStats& update_values_stats,
159  const SQLTypeInfo& rhs_type,
160  UpdelRoll& updel_roll) override;
162  void updateMetadata(const Catalog_Namespace::Catalog* catalog,
163  const MetaDataKey& key,
164  UpdelRoll& updel_roll) override;
166  void compactRows(const Catalog_Namespace::Catalog* catalog,
167  const TableDescriptor* td,
168  const int fragment_id,
169  const std::vector<uint64_t>& frag_offsets,
170  const Data_Namespace::MemoryLevel memory_level,
171  UpdelRoll& updel_roll) override;
173  const std::vector<uint64_t> getVacuumOffsets(
174  const std::shared_ptr<Chunk_NS::Chunk>& chunk) override;
177  const FragmentInfo& fragment,
178  const Data_Namespace::MemoryLevel memory_level);
180  void dropColumns(const std::vector<int>& columnIds) override;
182  bool hasDeletedRows(const int delete_column_id) override;
184  void resetSizesFromFragments() override;
186  protected:
187  std::vector<int> chunkKeyPrefix_;
188  std::map<int, Chunk_NS::Chunk>
190  std::deque<std::unique_ptr<FragmentInfo>>
192  // int currentInsertBufferFragmentId_;
195  const int physicalTableId_;
196  const int shard_;
198  size_t pageSize_; /* Page size in bytes of each page making up a given chunk - passed to
199  BufferMgr in createChunk() */
200  size_t numTuples_;
203  size_t maxRows_;
204  std::string fragmenterType_;
206  fragmentInfoMutex_; // to prevent read-write conflicts for fragmentInfoVec_
208  insertMutex_; // to prevent race conditions on insert - only one insert statement
209  // should be going to a table at a time
214  std::unordered_map<int, size_t> varLenColInfo_;
215  std::shared_ptr<std::mutex> mutex_access_inmem_states;
227  void deleteFragments(const std::vector<int>& dropFragIds);
230  void getChunkMetadata();
232  void lockInsertCheckpointData(const InsertData& insertDataStruct);
233  void insertDataImpl(InsertData& insert_data);
234  void addColumns(const InsertData& insertDataStruct);
238  // FIX-ME: Temporary lock; needs removing.
239  mutable std::mutex temp_mutex_;
241  FragmentInfo& getFragmentInfoFromId(const int fragment_id);
243  auto vacuum_fixlen_rows(const FragmentInfo& fragment,
244  const std::shared_ptr<Chunk_NS::Chunk>& chunk,
245  const std::vector<uint64_t>& frag_offsets);
246  auto vacuum_varlen_rows(const FragmentInfo& fragment,
247  const std::shared_ptr<Chunk_NS::Chunk>& chunk,
248  const std::vector<uint64_t>& frag_offsets);
250  private:
251  bool isAddingNewColumns(const InsertData& insert_data) const;
252  void dropFragmentsToSizeNoInsertLock(const size_t max_rows);
254 };
256 } // namespace Fragmenter_Namespace
void dropFragmentsToSizeNoInsertLock(const size_t max_rows)
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:102
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)
std::shared_ptr< std::mutex > mutex_access_inmem_states
std::optional< ChunkUpdateStats > 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
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 insertData(InsertData &insert_data_struct) override
appends data onto the most recently occuring fragment, creating a new one if necessary ...
void updateColumnChunkMetadata(const ColumnDescriptor *cd, const int fragment_id, const std::shared_ptr< ChunkMetadata > metadata) override
Updates the metadata for a column chunk.
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
void addColumns(const InsertData &insertDataStruct)
Used by Fragmenter classes to store info about each fragment - the fragment id and number of tuples(r...
Definition: Fragmenter.h:77
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...
Executor(const ExecutorId id, Data_Namespace::DataMgr *data_mgr, 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:150
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.
void updateChunkStats(const ColumnDescriptor *cd, std::unordered_map< int, ChunkStats > &stats_map, std::optional< Data_Namespace::MemoryLevel > memory_level) override
Update chunk stats.
auto getChunksForAllColumns(const TableDescriptor *td, const FragmentInfo &fragment, const Data_Namespace::MemoryLevel memory_level)
bool isAddingNewColumns(const InsertData &insert_data) const
std::unordered_map< int, size_t > varLenColInfo_
size_t getNumFragments() override
returns the number of fragments in a table
void updateColumnMetadata(const ColumnDescriptor *cd, FragmentInfo &fragment, std::shared_ptr< Chunk_NS::Chunk > chunk, const UpdateValuesStats &update_values_stats, const SQLTypeInfo &rhs_type, UpdelRoll &updel_roll) override
The data to be inserted using the fragment manager.
Definition: Fragmenter.h:59
void insertDataNoCheckpoint(InsertData &insert_data_struct) override
Given data wrapped in an InsertData struct, inserts it into the correct partitions No locks and check...
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.
boost::variant< int64_t, double, float, NullableString > ScalarTargetValue
Definition: TargetValue.h:156