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