OmniSciDB  8a228a1076
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  int64_t replicate_count =
67  0;
68  std::vector<bool> bypass; // bypass corresponding columnIds[]
69 };
70 
78 class FragmentInfo {
79  public:
81  : fragmentId(-1)
82  , shadowNumTuples(0)
83  , physicalTableId(-1)
84  , shard(-1)
85  , resultSet(nullptr)
86  , numTuples(0)
87  , synthesizedNumTuplesIsValid(false)
88  , synthesizedMetadataIsValid(false) {}
89 
90  void setChunkMetadataMap(const ChunkMetadataMap& chunk_metadata_map) {
91  this->chunkMetadataMap = chunk_metadata_map;
92  }
93 
94  void setChunkMetadata(const int col, std::shared_ptr<ChunkMetadata> chunkMetadata) {
95  chunkMetadataMap[col] = chunkMetadata;
96  }
97 
98  const ChunkMetadataMap& getChunkMetadataMap() const;
99 
100  const ChunkMetadataMap& getChunkMetadataMapPhysical() const { return chunkMetadataMap; }
101 
102  size_t getNumTuples() const;
103 
104  size_t getPhysicalNumTuples() const { return numTuples; }
105 
106  bool isEmptyPhysicalFragment() const { return physicalTableId >= 0 && !numTuples; }
107 
108  void setPhysicalNumTuples(const size_t physNumTuples) { numTuples = physNumTuples; }
109 
110  void invalidateChunkMetadataMap() const { synthesizedMetadataIsValid = false; };
111  void invalidateNumTuples() const { synthesizedNumTuplesIsValid = false; }
112 
113  // for unit tests
114  static void setUnconditionalVacuum(const double unconditionalVacuum) {
115  unconditionalVacuum_ = unconditionalVacuum;
116  }
117 
120  std::vector<int> deviceIds;
122  int shard;
125  mutable std::shared_ptr<std::mutex> resultSetMutex;
126 
127  private:
128  mutable size_t numTuples;
132 
133  friend class InsertOrderFragmenter;
134  static bool unconditionalVacuum_;
135 };
136 
146 class TableInfo {
147  public:
148  TableInfo() : numTuples(0) {}
149 
150  size_t getNumTuples() const;
151 
152  size_t getNumTuplesUpperBound() const;
153 
154  size_t getPhysicalNumTuples() const { return numTuples; }
155 
156  void setPhysicalNumTuples(const size_t physNumTuples) { numTuples = physNumTuples; }
157 
158  size_t getFragmentNumTuplesUpperBound() const;
159 
160  std::vector<int> chunkKeyPrefix;
161  std::vector<FragmentInfo> fragments;
162 
163  private:
164  mutable size_t numTuples;
165 };
166 
167 } // namespace Fragmenter_Namespace
168 
169 #endif // FRAGMENTER_H
static void setUnconditionalVacuum(const double unconditionalVacuum)
Definition: Fragmenter.h:114
std::map< int, std::shared_ptr< ChunkMetadata > > ChunkMetadataMap
void setChunkMetadata(const int col, std::shared_ptr< ChunkMetadata > chunkMetadata)
Definition: Fragmenter.h:94
const ChunkMetadataMap & getChunkMetadataMapPhysical() const
Definition: Fragmenter.h:100
std::shared_ptr< std::mutex > resultSetMutex
Definition: Fragmenter.h:125
std::vector< FragmentInfo > fragments
Definition: Fragmenter.h:161
The InsertOrderFragmenter is a child class of AbstractFragmenter, and fragments data in insert order...
std::vector< int > chunkKeyPrefix
Definition: Fragmenter.h:160
int tableId
identifies the database into which the data is being inserted
Definition: Fragmenter.h:61
size_t numRows
a vector of column ids for the row(s) being inserted
Definition: Fragmenter.h:63
std::vector< bool > bypass
count to replicate values of column(s); used only for ALTER ADD column
Definition: Fragmenter.h:68
Used by Fragmenter classes to store info about each fragment - the fragment id and number of tuples(r...
Definition: Fragmenter.h:78
size_t getPhysicalNumTuples() const
Definition: Fragmenter.h:154
std::vector< DataBlockPtr > data
the number of rows being inserted
Definition: Fragmenter.h:64
void setPhysicalNumTuples(const size_t physNumTuples)
Definition: Fragmenter.h:156
void setPhysicalNumTuples(const size_t physNumTuples)
Definition: Fragmenter.h:108
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:123
void setChunkMetadataMap(const ChunkMetadataMap &chunk_metadata_map)
Definition: Fragmenter.h:90