OmniSciDB  85c2d10cdc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 "../AbstractBufferMgr.h"
20 #include "Catalog/Catalog.h"
21 
22 #include <atomic>
23 #include <unordered_map>
24 
28  const std::vector<int8_t> buff;
29 };
30 
32  public:
34 
35  virtual void append(const std::vector<ForeignStorageColumnBuffer>& column_buffers) = 0;
36  virtual void read(const ChunkKey& chunk_key,
37  const SQLTypeInfo& sql_type,
38  int8_t* dest,
39  const size_t num_bytes) = 0;
40  virtual int8_t* tryZeroCopy(const ChunkKey& chunk_key,
41  const SQLTypeInfo& sql_type,
42  const size_t num_bytes) {
43  return nullptr;
44  }
45  virtual void prepareTable(const int /*db_id*/,
46  const std::string& type,
47  TableDescriptor& /*td*/,
48  std::list<ColumnDescriptor>& /*cols*/) {}
49  virtual void registerTable(Catalog_Namespace::Catalog* catalog,
50  std::pair<int, int> table_key,
51  const std::string& type,
52  const TableDescriptor& td,
53  const std::list<ColumnDescriptor>& cols,
54  Data_Namespace::AbstractBufferMgr* mgr) = 0;
55  virtual std::string getType() const = 0;
56 };
57 
59  public:
60  ForeignStorageBuffer(const ChunkKey& chunk_key,
61  PersistentForeignStorageInterface* persistent_foreign_storage);
62 
63  void read(int8_t* const dst,
64  const size_t numBytes,
65  const size_t offset = 0,
67  const int dstDeviceId = -1) override;
68 
69  void append(int8_t* src,
70  const size_t numBytes,
72  const int deviceId = -1) override;
73 
76  };
77 
78  std::vector<int8_t> moveBuffer() { return std::move(buff_); }
79 
80  void write(int8_t* src,
81  const size_t numBytes,
82  const size_t offset = 0,
84  const int srcDeviceId = -1) override {
85  CHECK(false);
86  }
87 
88  void reserve(size_t numBytes) override { CHECK(false); }
89 
90  int8_t* getMemoryPtr() override {
91  CHECK(false);
92  return nullptr;
93  }
94 
95  size_t pageCount() const override {
96  CHECK(false);
97  return 0;
98  }
99 
100  size_t pageSize() const override {
101  CHECK(false);
102  return 0;
103  }
104 
105  size_t reservedSize() const override {
106  CHECK(false);
107  return 0;
108  }
109 
110  int8_t* tryZeroCopy(const size_t numBytes);
111 
112  private:
115  std::vector<int8_t> buff_;
116 };
117 
118 class ForeignStorageBufferMgr : public Data_Namespace::AbstractBufferMgr {
119  public:
120  ForeignStorageBufferMgr(const int db_id,
121  const int table_id,
122  PersistentForeignStorageInterface* persistent_foreign_storage);
123 
124  void checkpoint() override;
125 
127  const size_t pageSize = 0,
128  const size_t initialSize = 0) override;
129 
131  const size_t numBytes = 0) override;
132 
133  void fetchBuffer(const ChunkKey& key,
134  Data_Namespace::AbstractBuffer* destBuffer,
135  const size_t numBytes = 0) override;
136 
138  const ChunkKey& keyPrefix) override;
139  std::string getStringMgrType() override { return ToString(FILE_MGR); }
140 
141  size_t getNumChunks() override {
142  mapd_shared_lock<mapd_shared_mutex> chunk_index_write_lock(chunk_index_mutex_);
143  return chunk_index_.size();
144  }
145 
146  void deleteBuffer(const ChunkKey& key, const bool purge = true) override {
147  CHECK(false);
148  }
149 
150  void deleteBuffersWithPrefix(const ChunkKey& keyPrefix,
151  const bool purge = true) override {
152  CHECK(false);
153  }
154 
157  const size_t numBytes = 0) override {
158  CHECK(false);
159  return nullptr;
160  }
161 
162  bool isBufferOnDevice(const ChunkKey& key) override {
163  CHECK(false);
164  return false;
165  }
166 
167  std::string printSlabs() override {
168  CHECK(false);
169  return "";
170  }
171 
172  void clearSlabs() override { CHECK(false); }
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  UNREACHABLE();
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 
234  std::unique_ptr<PersistentForeignStorageInterface> persistent_foreign_storage);
235 
237  void prepareTable(const int db_id,
238  TableDescriptor& td,
239  std::list<ColumnDescriptor>& cols);
242  const TableDescriptor& td,
243  const std::list<ColumnDescriptor>& cols);
244 
245  private:
246  std::unordered_map<std::string, std::unique_ptr<PersistentForeignStorageInterface>>
248  std::map<std::pair<int, int>, PersistentForeignStorageInterface*>
250  std::map<std::pair<int, int>, std::unique_ptr<ForeignStorageBufferMgr>> managers_map_;
252 };
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:101
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
#define UNREACHABLE()
Definition: Logger.h:241
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
This file contains the class specification and related data structures for Catalog.
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_
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_
#define CHECK(condition)
Definition: Logger.h:197
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