OmniSciDB  2e3a973ef4
ForeignStorageMgr.h
Go to the documentation of this file.
1 
2 /*
3  * Copyright 2020 OmniSci, Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include <shared_mutex>
21 
23 #include "ForeignDataWrapper.h"
25 
26 using namespace Data_Namespace;
27 
28 class PostEvictionRefreshException : public std::runtime_error {
29  public:
33  PostEvictionRefreshException(const std::runtime_error& exception)
34  : std::runtime_error(""), original_exception_(exception){};
35 
36  std::runtime_error getOriginalException() { return original_exception_; }
37 
38  private:
39  std::runtime_error original_exception_;
40 };
41 
42 namespace foreign_storage {
43 
44 // For testing purposes only
46  public:
47  virtual void setParentWrapper(
48  std::shared_ptr<ForeignDataWrapper> parent_data_wrapper) = 0;
49 };
50 
52  public:
54 
55  AbstractBuffer* createBuffer(const ChunkKey& chunk_key,
56  const size_t page_size,
57  const size_t initial_size) override;
58  void deleteBuffer(const ChunkKey& chunk_key, const bool purge) override;
59  void deleteBuffersWithPrefix(const ChunkKey& chunk_key_prefix,
60  const bool purge) override;
61  AbstractBuffer* getBuffer(const ChunkKey& chunk_key, const size_t num_bytes) override;
62  void fetchBuffer(const ChunkKey& chunk_key,
63  AbstractBuffer* destination_buffer,
64  const size_t num_bytes) override;
65  AbstractBuffer* putBuffer(const ChunkKey& chunk_key,
66  AbstractBuffer* source_buffer,
67  const size_t num_bytes) override;
68  /*
69  Obtains chunk-metadata relating to a prefix. Will create and use new
70  datawrappers if none are found for the given prefix.
71  */
72  void getChunkMetadataVecForKeyPrefix(ChunkMetadataVector& chunk_metadata,
73  const ChunkKey& chunk_key_prefix) override;
74  bool isBufferOnDevice(const ChunkKey& chunk_key) override;
75  std::string printSlabs() override;
76  void clearSlabs() override;
77  size_t getMaxSize() override;
78  size_t getInUseSize() override;
79  size_t getAllocated() override;
80  bool isAllocationCapped() override;
81  void checkpoint() override;
82  void checkpoint(const int db_id, const int tb_id) override;
83  AbstractBuffer* alloc(const size_t num_bytes) override;
84  void free(AbstractBuffer* buffer) override;
85  MgrType getMgrType() override;
86  std::string getStringMgrType() override;
87  size_t getNumChunks() override;
88  void removeTableRelatedDS(const int db_id, const int table_id) override;
89  bool hasDataWrapperForChunk(const ChunkKey& chunk_key);
90 
91  // For testing, is datawrapper state recovered from disk
92  bool isDatawrapperRestored(const ChunkKey& chunk_key);
93  void setDataWrapper(const ChunkKey& table_key,
94  std::shared_ptr<MockForeignDataWrapper> data_wrapper);
95 
96  virtual void refreshTable(const ChunkKey& table_key, const bool evict_cached_entries);
97 
98  protected:
99  bool createDataWrapperIfNotExists(const ChunkKey& chunk_key);
100  std::shared_ptr<ForeignDataWrapper> getDataWrapper(const ChunkKey& chunk_key);
101  bool fetchBufferIfTempBufferMapEntryExists(const ChunkKey& chunk_key,
102  AbstractBuffer* destination_buffer,
103  const size_t num_bytes);
104  void createAndPopulateDataWrapperIfNotExists(const ChunkKey& chunk_key);
105  std::map<ChunkKey, AbstractBuffer*> allocateTempBuffersForChunks(
106  const std::set<ChunkKey>& chunk_keys);
107  void clearTempChunkBufferMapEntriesForTable(const ChunkKey& table_key);
108 
109  std::shared_mutex data_wrapper_mutex_;
110  std::map<ChunkKey, std::shared_ptr<ForeignDataWrapper>> data_wrapper_map_;
111 
112  // TODO: Remove below map, which is used to temporarily hold chunk buffers,
113  // when buffer mgr interface is updated to accept multiple buffers in one call
114  std::map<ChunkKey, std::unique_ptr<AbstractBuffer>> temp_chunk_buffer_map_;
115  std::shared_mutex temp_chunk_buffer_map_mutex_;
116 };
117 
118 std::vector<ChunkKey> get_keys_vec_from_table(const ChunkKey& destination_chunk_key);
119 std::set<ChunkKey> get_keys_set_from_table(const ChunkKey& destination_chunk_key);
120 } // namespace foreign_storage
std::runtime_error getOriginalException()
PostEvictionRefreshException(const std::runtime_error &exception)
std::shared_mutex temp_chunk_buffer_map_mutex_
An AbstractBuffer is a unit of data management for a data manager.
std::map< ChunkKey, std::shared_ptr< ForeignDataWrapper > > data_wrapper_map_
std::vector< ChunkKey > get_keys_vec_from_table(const ChunkKey &destination_chunk_key)
std::set< ChunkKey > get_keys_set_from_table(const ChunkKey &destination_chunk_key)
std::runtime_error original_exception_
std::vector< int > ChunkKey
Definition: types.h:37
std::map< ChunkKey, std::unique_ptr< AbstractBuffer > > temp_chunk_buffer_map_
std::vector< std::pair< ChunkKey, std::shared_ptr< ChunkMetadata > >> ChunkMetadataVector