OmniSciDB  06b3bd477c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 <vector>
29 #include "DataMgr/Chunk/Chunk.h"
30 #include "DataMgr/MemoryLevel.h"
31 #include "FragmentDefaultValues.h"
35 #include "Shared/types.h"
37 class Executor;
39 namespace Data_Namespace {
40 class DataMgr;
41 }
43 namespace Fragmenter_Namespace {
53  public:
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);
70  ~InsertOrderFragmenter() override;
77  // virtual void getFragmentsForQuery(QueryInfo &queryInfo, const void *predicate = 0);
87  void insertData(InsertData& insertDataStruct) override;
89  void insertDataNoCheckpoint(InsertData& insertDataStruct) override;
91  void dropFragmentsToSize(const size_t maxRows) override;
93  void updateChunkStats(
94  const ColumnDescriptor* cd,
95  std::unordered_map</*fragment_id*/ int, ChunkStats>& stats_map) override;
97  FragmentInfo* getFragmentInfo(const int fragment_id) const override;
102  inline int getFragmenterId() override { return chunkKeyPrefix_.back(); }
103  inline std::vector<int> getChunkKeyPrefix() const { return chunkKeyPrefix_; }
107  inline std::string getFragmenterType() override { return fragmenterType_; }
108  size_t getNumRows() override { return numTuples_; }
109  void setNumRows(const size_t numTuples) override { numTuples_ = numTuples; }
111  static void updateColumn(const Catalog_Namespace::Catalog* catalog,
112  const std::string& tab_name,
113  const std::string& col_name,
114  const int fragment_id,
115  const std::vector<uint64_t>& frag_offsets,
116  const std::vector<ScalarTargetValue>& rhs_values,
117  const SQLTypeInfo& rhs_type,
118  const Data_Namespace::MemoryLevel memory_level,
119  UpdelRoll& updel_roll);
121  void updateColumn(const Catalog_Namespace::Catalog* catalog,
122  const TableDescriptor* td,
123  const ColumnDescriptor* cd,
124  const int fragment_id,
125  const std::vector<uint64_t>& frag_offsets,
126  const std::vector<ScalarTargetValue>& rhs_values,
127  const SQLTypeInfo& rhs_type,
128  const Data_Namespace::MemoryLevel memory_level,
129  UpdelRoll& updel_roll) override;
131  void updateColumns(const Catalog_Namespace::Catalog* catalog,
132  const TableDescriptor* td,
133  const int fragmentId,
134  const std::vector<TargetMetaInfo> sourceMetaInfo,
135  const std::vector<const ColumnDescriptor*> columnDescriptors,
136  const RowDataProvider& sourceDataProvider,
137  const size_t indexOffFragmentOffsetColumn,
138  const Data_Namespace::MemoryLevel memoryLevel,
139  UpdelRoll& updelRoll,
140  Executor* executor) override;
142  void updateColumn(const Catalog_Namespace::Catalog* catalog,
143  const TableDescriptor* td,
144  const ColumnDescriptor* cd,
145  const int fragment_id,
146  const std::vector<uint64_t>& frag_offsets,
147  const ScalarTargetValue& rhs_value,
148  const SQLTypeInfo& rhs_type,
149  const Data_Namespace::MemoryLevel memory_level,
150  UpdelRoll& updel_roll) override;
152  void updateColumnMetadata(const ColumnDescriptor* cd,
153  FragmentInfo& fragment,
154  std::shared_ptr<Chunk_NS::Chunk> chunk,
155  const bool null,
156  const double dmax,
157  const double dmin,
158  const int64_t lmax,
159  const int64_t lmin,
160  const SQLTypeInfo& rhs_type,
161  UpdelRoll& updel_roll) override;
163  void updateMetadata(const Catalog_Namespace::Catalog* catalog,
164  const MetaDataKey& key,
165  UpdelRoll& updel_roll) override;
167  void compactRows(const Catalog_Namespace::Catalog* catalog,
168  const TableDescriptor* td,
169  const int fragment_id,
170  const std::vector<uint64_t>& frag_offsets,
171  const Data_Namespace::MemoryLevel memory_level,
172  UpdelRoll& updel_roll) override;
174  const std::vector<uint64_t> getVacuumOffsets(
175  const std::shared_ptr<Chunk_NS::Chunk>& chunk) override;
178  const FragmentInfo& fragment,
179  const Data_Namespace::MemoryLevel memory_level);
181  void dropColumns(const std::vector<int>& columnIds) override;
183  bool hasDeletedRows(const int delete_column_id) override;
185  protected:
186  std::vector<int> chunkKeyPrefix_;
187  std::map<int, Chunk_NS::Chunk>
189  std::deque<std::unique_ptr<FragmentInfo>>
191  // int currentInsertBufferFragmentId_;
194  const int physicalTableId_;
195  const int shard_;
197  size_t pageSize_; /* Page size in bytes of each page making up a given chunk - passed to
198  BufferMgr in createChunk() */
199  size_t numTuples_;
202  size_t maxRows_;
203  std::string fragmenterType_;
205  fragmentInfoMutex_; // to prevent read-write conflicts for fragmentInfoVec_
207  insertMutex_; // to prevent race conditions on insert - only one insert statement
208  // should be going to a table at a time
213  std::unordered_map<int, size_t> varLenColInfo_;
214  std::shared_ptr<std::mutex> mutex_access_inmem_states;
226  void deleteFragments(const std::vector<int>& dropFragIds);
228  void getChunkMetadata();
230  void lockInsertCheckpointData(const InsertData& insertDataStruct);
231  void insertDataImpl(InsertData& insertDataStruct);
232  void replicateData(const InsertData& insertDataStruct);
236  // FIX-ME: Temporary lock; needs removing.
237  mutable std::mutex temp_mutex_;
239  FragmentInfo& getFragmentInfoFromId(const int fragment_id);
241  auto vacuum_fixlen_rows(const FragmentInfo& fragment,
242  const std::shared_ptr<Chunk_NS::Chunk>& chunk,
243  const std::vector<uint64_t>& frag_offsets);
244  auto vacuum_varlen_rows(const FragmentInfo& fragment,
245  const std::shared_ptr<Chunk_NS::Chunk>& chunk,
246  const std::vector<uint64_t>& frag_offsets);
247 };
249 } // 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:86
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
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 insertDataNoCheckpoint(InsertData &insertDataStruct) override
Given data wrapped in an InsertData struct, inserts it into the correct partitions No locks and check...
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...
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.
auto getChunksForAllColumns(const TableDescriptor *td, const FragmentInfo &fragment, const Data_Namespace::MemoryLevel memory_level)
static void updateColumn(const Catalog_Namespace::Catalog *catalog, const std::string &tab_name, const std::string &col_name, 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)
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:129
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