OmniSciDB  eb3a3d0a03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UpdelRoll.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 #ifndef UPDELROLL_H
17 #define UPDELROLL_H
18 
19 #include <map>
20 #include <mutex>
21 #include <set>
22 #include <utility>
23 
24 #include "DataMgr/Chunk/Chunk.h"
25 #include "DataMgr/ChunkMetadata.h"
26 #include "DataMgr/MemoryLevel.h"
27 
28 namespace Fragmenter_Namespace {
29 class InsertOrderFragmenter;
30 class FragmentInfo;
31 } // namespace Fragmenter_Namespace
32 
33 namespace Catalog_Namespace {
34 class Catalog;
35 }
36 
37 struct TableDescriptor;
38 
39 using MetaDataKey =
40  std::pair<const TableDescriptor*, Fragmenter_Namespace::FragmentInfo*>;
41 
42 // this roll records stuff that need to be roll back/forw after upd/del fails or finishes
43 struct UpdelRoll {
45  if (dirty_chunks.size()) {
46  cancelUpdate();
47  }
48  }
49 
50  // on aggregater it's possible that updateColumn is never called but
51  // commitUpdate is still called, so this nullptr is a protection
55 
56  bool is_varlen_update = false;
58 
59  void cancelUpdate();
60 
61  // Commits/checkpoints data and metadata updates. A boolean that indicates whether or
62  // not data update actually occurred is returned.
63  bool commitUpdate();
64 
65  // Writes chunks at the CPU memory level to storage without checkpointing at the storage
66  // level.
67  void stageUpdate();
68 
69  void addDirtyChunk(std::shared_ptr<Chunk_NS::Chunk> chunk, int fragment_id);
70 
71  std::shared_ptr<ChunkMetadata> getChunkMetadata(
72  const MetaDataKey& key,
73  int32_t column_id,
74  Fragmenter_Namespace::FragmentInfo& fragment_info);
75 
77 
78  size_t getNumTuple(const MetaDataKey& key) const;
79 
80  void setNumTuple(const MetaDataKey& key, size_t num_tuple);
81 
82  private:
84 
86  Fragmenter_Namespace::FragmentInfo& fragment_info);
87 
88  // Used to guard internal data structures that track chunk/chunk metadata updates
90 
91  // chunks changed during this query
92  std::map<ChunkKey, std::shared_ptr<Chunk_NS::Chunk>> dirty_chunks;
93 
94  // new FragmentInfo.numTuples
95  std::map<MetaDataKey, size_t> num_tuples;
96 
97  // new FragmentInfo.ChunkMetadata;
98  std::map<MetaDataKey, ChunkMetadataMap> chunk_metadata_map_per_fragment;
99 };
100 
101 #endif
Data_Namespace::MemoryLevel memoryLevel
Definition: UpdelRoll.h:54
bool is_varlen_update
Definition: UpdelRoll.h:56
void setNumTuple(const MetaDataKey &key, size_t num_tuple)
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:102
const TableDescriptor * table_descriptor
Definition: UpdelRoll.h:57
std::pair< const TableDescriptor *, Fragmenter_Namespace::FragmentInfo * > MetaDataKey
Definition: UpdelRoll.h:40
void cancelUpdate()
void addDirtyChunk(std::shared_ptr< Chunk_NS::Chunk > chunk, int fragment_id)
mapd_shared_mutex chunk_update_tracker_mutex
Definition: UpdelRoll.h:89
~UpdelRoll()
Definition: UpdelRoll.h:44
void updateFragmenterAndCleanupChunks()
std::map< int, std::shared_ptr< ChunkMetadata >> ChunkMetadataMap
std::map< MetaDataKey, ChunkMetadataMap > chunk_metadata_map_per_fragment
Definition: UpdelRoll.h:98
std::map< MetaDataKey, size_t > num_tuples
Definition: UpdelRoll.h:95
bool commitUpdate()
void stageUpdate()
const Catalog_Namespace::Catalog * catalog
Definition: UpdelRoll.h:52
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:77
ChunkMetadataMap getChunkMetadataMap(const MetaDataKey &key) const
void initializeUnsetMetadata(const TableDescriptor *td, Fragmenter_Namespace::FragmentInfo &fragment_info)
int logicalTableId
Definition: UpdelRoll.h:53
std::shared_ptr< ChunkMetadata > getChunkMetadata(const MetaDataKey &key, int32_t column_id, Fragmenter_Namespace::FragmentInfo &fragment_info)
size_t getNumTuple(const MetaDataKey &key) const
std::map< ChunkKey, std::shared_ptr< Chunk_NS::Chunk > > dirty_chunks
Definition: UpdelRoll.h:92