OmniSciDB  085a039ca4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ForeignStorageInterface.h
Go to the documentation of this file.
1 /*
2  * Copyright 2020 OmniSci, 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 #pragma once
18 
19 #include "Catalog/CatalogFwd.h"
21 #include "LockMgr/LockMgr.h"
22 
23 #include <atomic>
24 #include <unordered_map>
25 
29  const std::vector<int8_t> buff;
30 };
31 
33  public:
35 
36  virtual void append(const std::vector<ForeignStorageColumnBuffer>& column_buffers) = 0;
37  virtual void read(const ChunkKey& chunk_key,
38  const SQLTypeInfo& sql_type,
39  int8_t* dest,
40  const size_t num_bytes) = 0;
41  virtual int8_t* tryZeroCopy(const ChunkKey& chunk_key,
42  const SQLTypeInfo& sql_type,
43  const size_t num_bytes) {
44  return nullptr;
45  }
46  virtual void prepareTable(const int /*db_id*/,
47  const std::string& type,
48  TableDescriptor& /*td*/,
49  std::list<ColumnDescriptor>& /*cols*/) {}
50  virtual void registerTable(Catalog_Namespace::Catalog* catalog,
51  std::pair<int, int> table_key,
52  const std::string& type,
53  const TableDescriptor& td,
54  const std::list<ColumnDescriptor>& cols,
55  Data_Namespace::AbstractBufferMgr* mgr) = 0;
56  virtual void dropTable(const int db_id, const int table_id) = 0;
57  virtual std::string getType() const = 0;
58 };
59 
61  public:
62  ForeignStorageBuffer(const ChunkKey& chunk_key,
63  PersistentForeignStorageInterface* persistent_foreign_storage);
64 
65  void read(int8_t* const dst,
66  const size_t numBytes,
67  const size_t offset = 0,
69  const int dstDeviceId = -1) override;
70 
71  void append(int8_t* src,
72  const size_t numBytes,
74  const int deviceId = -1) override;
75 
78  };
79 
80  std::vector<int8_t> moveBuffer() { return std::move(buff_); }
81 
82  void write(int8_t* src,
83  const size_t numBytes,
84  const size_t offset = 0,
86  const int srcDeviceId = -1) override {
87  CHECK(false);
88  }
89 
90  void reserve(size_t numBytes) override { CHECK(false); }
91 
92  int8_t* getMemoryPtr() override {
93  CHECK(false);
94  return nullptr;
95  }
96 
97  size_t pageCount() const override {
98  CHECK(false);
99  return 0;
100  }
101 
102  size_t pageSize() const override {
103  CHECK(false);
104  return 0;
105  }
106 
107  size_t reservedSize() const override {
108  CHECK(false);
109  return 0;
110  }
111 
112  int8_t* tryZeroCopy(const size_t numBytes);
113 
114  private:
117  std::vector<int8_t> buff_;
118 };
119 
120 class ForeignStorageBufferMgr : public Data_Namespace::AbstractBufferMgr {
121  public:
122  ForeignStorageBufferMgr(const int db_id,
123  const int table_id,
124  PersistentForeignStorageInterface* persistent_foreign_storage);
125 
126  void checkpoint() override;
127 
129  const size_t pageSize = 0,
130  const size_t initialSize = 0) override;
131 
133  const size_t numBytes = 0) override;
134 
135  void fetchBuffer(const ChunkKey& key,
136  Data_Namespace::AbstractBuffer* destBuffer,
137  const size_t numBytes = 0) override;
138 
140  const ChunkKey& keyPrefix) override;
141  std::string getStringMgrType() override { return ToString(FILE_MGR); }
142 
143  size_t getNumChunks() override {
144  mapd_shared_lock<mapd_shared_mutex> chunk_index_write_lock(chunk_index_mutex_);
145  return chunk_index_.size();
146  }
147 
148  void deleteBuffer(const ChunkKey& key, const bool purge = true) override {
149  CHECK(false);
150  }
151 
152  void deleteBuffersWithPrefix(const ChunkKey& keyPrefix,
153  const bool purge = true) override {
154  CHECK(false);
155  }
156 
159  const size_t numBytes = 0) override {
160  CHECK(false);
161  return nullptr;
162  }
163 
164  bool isBufferOnDevice(const ChunkKey& key) override {
165  CHECK(false);
166  return false;
167  }
168 
169  std::string printSlabs() override {
170  CHECK(false);
171  return "";
172  }
173 
174  size_t getMaxSize() override {
175  CHECK(false);
176  return 0;
177  }
178 
179  size_t getInUseSize() override {
180  CHECK(false);
181  return 0;
182  }
183 
184  size_t getAllocated() override {
185  CHECK(false);
186  return 0;
187  }
188 
189  bool isAllocationCapped() override {
190  CHECK(false);
191  return false;
192  }
193 
194  void checkpoint(const int db_id, const int tb_id) override { CHECK(false); }
195 
196  // Buffer API
197  Data_Namespace::AbstractBuffer* alloc(const size_t numBytes = 0) override {
198  CHECK(false);
199  return nullptr;
200  }
201 
202  void free(Data_Namespace::AbstractBuffer* buffer) override { CHECK(false); }
203 
204  MgrType getMgrType() override {
205  CHECK(false);
206  return FILE_MGR;
207  }
208 
209  void removeTableRelatedDS(const int db_id, const int table_id) override {
210  persistent_foreign_storage_->dropTable(db_id, table_id);
211  }
212 
213  private:
215  std::map<ChunkKey, std::unique_ptr<ForeignStorageBuffer>> chunk_index_;
217 };
218 
220  public:
223 
224  ForeignStorageInterface(const ForeignStorageInterface& other) = delete;
226 
229 
230  Data_Namespace::AbstractBufferMgr* lookupBufferManager(const int db_id,
231  const int table_id);
232  void dropBufferManager(const int db_id, const int table_id);
233 
235  std::unique_ptr<PersistentForeignStorageInterface> persistent_foreign_storage);
236 
238  void prepareTable(const int db_id,
239  TableDescriptor& td,
240  std::list<ColumnDescriptor>& cols);
243  const TableDescriptor& td,
244  const std::list<ColumnDescriptor>& cols);
245 
246  private:
247  std::unordered_map<std::string, std::unique_ptr<PersistentForeignStorageInterface>>
249  std::map<std::pair<int, int>, PersistentForeignStorageInterface*>
251  std::map<std::pair<int, int>, std::unique_ptr<ForeignStorageBufferMgr>> managers_map_;
253 };
void reserve(size_t numBytes) override
PersistentForeignStorageInterface * persistent_foreign_storage_
void getChunkMetadataVecForKeyPrefix(ChunkMetadataVector &chunkMetadataVec, const ChunkKey &keyPrefix) override
void deleteBuffer(const ChunkKey &key, const bool purge=true) override
std::vector< int > ChunkKey
Definition: types.h:37
void checkpoint(const int db_id, const int tb_id) override
std::unordered_map< std::string, std::unique_ptr< PersistentForeignStorageInterface > > persistent_storage_interfaces_
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:114
virtual void registerTable(Catalog_Namespace::Catalog *catalog, std::pair< int, int > table_key, const std::string &type, const TableDescriptor &td, const std::list< ColumnDescriptor > &cols, Data_Namespace::AbstractBufferMgr *mgr)=0
Data_Namespace::AbstractBufferMgr * lookupBufferManager(const int db_id, const int table_id)
void append(int8_t *src, const size_t numBytes, const Data_Namespace::MemoryLevel srcBufferType=Data_Namespace::CPU_LEVEL, const int deviceId=-1) override
ForeignStorageInterface & operator=(const ForeignStorageInterface &other)=delete
size_t reservedSize() const override
std::string getStringMgrType() override
std::vector< int8_t > moveBuffer()
size_t pageSize() const override
void write(int8_t *src, const size_t numBytes, const size_t offset=0, const Data_Namespace::MemoryLevel srcBufferType=Data_Namespace::CPU_LEVEL, const int srcDeviceId=-1) override
void free(Data_Namespace::AbstractBuffer *buffer) override
void fetchBuffer(const ChunkKey &key, Data_Namespace::AbstractBuffer *destBuffer, const size_t numBytes=0) override
int8_t * getMemoryPtr() override
void registerPersistentStorageInterface(std::unique_ptr< PersistentForeignStorageInterface > persistent_foreign_storage)
Data_Namespace::AbstractBuffer * putBuffer(const ChunkKey &key, Data_Namespace::AbstractBuffer *srcBuffer, const size_t numBytes=0) override
bool isBufferOnDevice(const ChunkKey &key) override
ForeignStorageBufferMgr(const int db_id, const int table_id, PersistentForeignStorageInterface *persistent_foreign_storage)
std::shared_timed_mutex mapd_shared_mutex
virtual void prepareTable(const int, const std::string &type, TableDescriptor &, std::list< ColumnDescriptor > &)
mapd_shared_mutex chunk_index_mutex_
std::vector< std::pair< ChunkKey, std::shared_ptr< ChunkMetadata >>> ChunkMetadataVector
virtual void append(const std::vector< ForeignStorageColumnBuffer > &column_buffers)=0
ForeignStorageBuffer(const ChunkKey &chunk_key, PersistentForeignStorageInterface *persistent_foreign_storage)
An AbstractBuffer is a unit of data management for a data manager.
void registerTable(Catalog_Namespace::Catalog *catalog, const TableDescriptor &td, const std::list< ColumnDescriptor > &cols)
ids are created
std::map< ChunkKey, std::unique_ptr< ForeignStorageBuffer > > chunk_index_
std::vector< int8_t > buff_
virtual void dropTable(const int db_id, const int table_id)=0
Data_Namespace::AbstractBuffer * getBuffer(const ChunkKey &key, const size_t numBytes=0) override
virtual int8_t * tryZeroCopy(const ChunkKey &chunk_key, const SQLTypeInfo &sql_type, const size_t num_bytes)
Data_Namespace::AbstractBuffer * alloc(const size_t numBytes=0) override
std::map< std::pair< int, int >, PersistentForeignStorageInterface * > table_persistent_storage_interface_map_
void dropBufferManager(const int db_id, const int table_id)
#define CHECK(condition)
Definition: Logger.h:223
Data_Namespace::MemoryLevel getType() const override
std::map< std::pair< int, int >, std::unique_ptr< ForeignStorageBufferMgr > > managers_map_
std::string printSlabs() override
PersistentForeignStorageInterface * persistent_foreign_storage_
void deleteBuffersWithPrefix(const ChunkKey &keyPrefix, const bool purge=true) override
void read(int8_t *const dst, const size_t numBytes, const size_t offset=0, const Data_Namespace::MemoryLevel dstBufferType=Data_Namespace::CPU_LEVEL, const int dstDeviceId=-1) override
size_t pageCount() const override
virtual std::string getType() const =0
const std::vector< int8_t > buff
virtual void read(const ChunkKey &chunk_key, const SQLTypeInfo &sql_type, int8_t *dest, const size_t num_bytes)=0
int8_t * tryZeroCopy(const size_t numBytes)
void removeTableRelatedDS(const int db_id, const int table_id) override
void prepareTable(const int db_id, TableDescriptor &td, std::list< ColumnDescriptor > &cols)
prepare table options and modify columns
Data_Namespace::AbstractBuffer * createBuffer(const ChunkKey &key, const size_t pageSize=0, const size_t initialSize=0) override