OmniSciDB  21ac014ffc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Fragmenter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 
17 #ifndef FRAGMENTER_H
18 #define FRAGMENTER_H
19 
20 #include <deque>
21 #include <list>
22 #include <map>
23 #include <mutex>
24 #include "../Catalog/ColumnDescriptor.h"
25 #include "../DataMgr/ChunkMetadata.h"
26 #include "../Shared/mapd_shared_mutex.h"
27 #include "../Shared/types.h"
28 
29 namespace Data_Namespace {
30 class AbstractBuffer;
31 }
32 
33 class ResultSet;
34 
35 namespace Fragmenter_Namespace {
36 class InsertOrderFragmenter;
37 
45  INSERT_ORDER = 0 // these values persist in catalog. make explicit
46 };
47 
59 struct InsertData {
60  int databaseId;
61  int tableId;
62  std::vector<int> columnIds;
63  size_t numRows;
64  std::vector<DataBlockPtr> data;
65  std::vector<bool> is_default;
67 };
69 
77 class FragmentInfo {
78  public:
80  : fragmentId(-1)
81  , shadowNumTuples(0)
82  , physicalTableId(-1)
83  , shard(-1)
84  , resultSet(nullptr)
85  , numTuples(0)
88 
89  void setChunkMetadataMap(const ChunkMetadataMap& chunk_metadata_map) {
90  this->chunkMetadataMap = chunk_metadata_map;
91  }
92 
93  void setChunkMetadata(const int col, std::shared_ptr<ChunkMetadata> chunkMetadata) {
94  chunkMetadataMap[col] = chunkMetadata;
95  }
96 
98 
100 
102 
103  size_t getNumTuples() const;
104 
105  size_t getPhysicalNumTuples() const { return numTuples; }
106 
107  bool isEmptyPhysicalFragment() const { return physicalTableId >= 0 && !numTuples; }
108 
109  void setPhysicalNumTuples(const size_t physNumTuples) { numTuples = physNumTuples; }
110 
113 
114  // for unit tests
115  static void setUnconditionalVacuum(const double unconditionalVacuum) {
116  unconditionalVacuum_ = unconditionalVacuum;
117  }
118 
121  std::vector<int> deviceIds;
123  int shard;
126  mutable std::shared_ptr<std::mutex> resultSetMutex;
127 
128  private:
129  mutable size_t numTuples;
133 
134  friend class InsertOrderFragmenter;
135  static bool unconditionalVacuum_;
136 };
137 
147 class TableInfo {
148  public:
150 
151  size_t getNumTuples() const;
152 
153  size_t getNumTuplesUpperBound() const;
154 
155  size_t getPhysicalNumTuples() const { return numTuples; }
156 
157  void setPhysicalNumTuples(const size_t physNumTuples) { numTuples = physNumTuples; }
158 
159  size_t getFragmentNumTuplesUpperBound() const;
160 
161  std::vector<int> chunkKeyPrefix;
162  std::vector<FragmentInfo> fragments;
163 
164  private:
165  mutable size_t numTuples;
166 };
167 
168 } // namespace Fragmenter_Namespace
169 
170 #endif // FRAGMENTER_H
static void setUnconditionalVacuum(const double unconditionalVacuum)
Definition: Fragmenter.h:115
ChunkMetadataMap getChunkMetadataMapPhysicalCopy() const
void setChunkMetadata(const int col, std::shared_ptr< ChunkMetadata > chunkMetadata)
Definition: Fragmenter.h:93
const ChunkMetadataMap & getChunkMetadataMapPhysical() const
Definition: Fragmenter.h:99
std::vector< bool > is_default
Definition: Fragmenter.h:66
size_t getPhysicalNumTuples() const
Definition: Fragmenter.h:105
std::shared_ptr< std::mutex > resultSetMutex
Definition: Fragmenter.h:126
std::vector< FragmentInfo > fragments
Definition: Fragmenter.h:162
The InsertOrderFragmenter is a child class of AbstractFragmenter, and fragments data in insert order...
std::vector< int > chunkKeyPrefix
Definition: Fragmenter.h:161
int tableId
identifies the database into which the data is being inserted
Definition: Fragmenter.h:61
std::map< int, std::shared_ptr< ChunkMetadata >> ChunkMetadataMap
size_t getPhysicalNumTuples() const
Definition: Fragmenter.h:155
size_t numRows
a vector of column ids for the row(s) being inserted
Definition: Fragmenter.h:63
Used by Fragmenter classes to store info about each fragment - the fragment id and number of tuples(r...
Definition: Fragmenter.h:77
size_t getFragmentNumTuplesUpperBound() const
const ChunkMetadataMap & getChunkMetadataMap() const
void invalidateChunkMetadataMap() const
Definition: Fragmenter.h:111
std::vector< DataBlockPtr > data
the number of rows being inserted
Definition: Fragmenter.h:64
bool g_enable_watchdog false
Definition: Execute.cpp:75
void setPhysicalNumTuples(const size_t physNumTuples)
Definition: Fragmenter.h:157
void setPhysicalNumTuples(const size_t physNumTuples)
Definition: Fragmenter.h:109
The data to be inserted using the fragment manager.
Definition: Fragmenter.h:59
std::vector< int > columnIds
identifies the table into which the data is being inserted
Definition: Fragmenter.h:62
ChunkMetadataMap shadowChunkMetadataMap
Definition: Fragmenter.h:124
void setChunkMetadataMap(const ChunkMetadataMap &chunk_metadata_map)
Definition: Fragmenter.h:89