OmniSciDB  8fa3bf436f
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 
101  size_t getNumTuples() const;
102 
103  size_t getPhysicalNumTuples() const { return numTuples; }
104 
105  bool isEmptyPhysicalFragment() const { return physicalTableId >= 0 && !numTuples; }
106 
107  void setPhysicalNumTuples(const size_t physNumTuples) { numTuples = physNumTuples; }
108 
111 
112  // for unit tests
113  static void setUnconditionalVacuum(const double unconditionalVacuum) {
114  unconditionalVacuum_ = unconditionalVacuum;
115  }
116 
119  std::vector<int> deviceIds;
121  int shard;
124  mutable std::shared_ptr<std::mutex> resultSetMutex;
125 
126  private:
127  mutable size_t numTuples;
131 
132  friend class InsertOrderFragmenter;
133  static bool unconditionalVacuum_;
134 };
135 
145 class TableInfo {
146  public:
148 
149  size_t getNumTuples() const;
150 
151  size_t getNumTuplesUpperBound() const;
152 
153  size_t getPhysicalNumTuples() const { return numTuples; }
154 
155  void setPhysicalNumTuples(const size_t physNumTuples) { numTuples = physNumTuples; }
156 
157  size_t getFragmentNumTuplesUpperBound() const;
158 
159  std::vector<int> chunkKeyPrefix;
160  std::vector<FragmentInfo> fragments;
161 
162  private:
163  mutable size_t numTuples;
164 };
165 
166 } // namespace Fragmenter_Namespace
167 
168 #endif // FRAGMENTER_H
static void setUnconditionalVacuum(const double unconditionalVacuum)
Definition: Fragmenter.h:113
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:103
std::shared_ptr< std::mutex > resultSetMutex
Definition: Fragmenter.h:124
std::vector< FragmentInfo > fragments
Definition: Fragmenter.h:160
The InsertOrderFragmenter is a child class of AbstractFragmenter, and fragments data in insert order...
std::vector< int > chunkKeyPrefix
Definition: Fragmenter.h:159
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:153
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:109
std::vector< DataBlockPtr > data
the number of rows being inserted
Definition: Fragmenter.h:64
bool g_enable_watchdog false
Definition: Execute.cpp:76
void setPhysicalNumTuples(const size_t physNumTuples)
Definition: Fragmenter.h:155
void setPhysicalNumTuples(const size_t physNumTuples)
Definition: Fragmenter.h:107
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:122
void setChunkMetadataMap(const ChunkMetadataMap &chunk_metadata_map)
Definition: Fragmenter.h:89