OmniSciDB  0b528656ed
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 <unordered_map>
23 
27  const std::vector<int8_t> buff;
28 };
29 
31  public:
33 
34  virtual void append(const std::vector<ForeignStorageColumnBuffer>& column_buffers) = 0;
35  virtual void read(const ChunkKey& chunk_key,
36  const SQLTypeInfo& sql_type,
37  int8_t* dest,
38  const size_t num_bytes) = 0;
39  virtual void prepareTable(const int /*db_id*/,
40  const std::string& type,
41  TableDescriptor& /*td*/,
42  std::list<ColumnDescriptor>& /*cols*/) {}
43  virtual void registerTable(Catalog_Namespace::Catalog* catalog,
44  std::pair<int, int> table_key,
45  const std::string& type,
46  const TableDescriptor& td,
47  const std::list<ColumnDescriptor>& cols,
48  Data_Namespace::AbstractBufferMgr* mgr) = 0;
49  virtual std::string getType() const = 0;
50 };
51 
53  public:
55  PersistentForeignStorageInterface* persistent_foreign_storage);
56 
57  void read(int8_t* const dst,
58  const size_t numBytes,
59  const size_t offset = 0,
61  const int dstDeviceId = -1) override;
62 
63  void append(int8_t* src,
64  const size_t numBytes,
66  const int deviceId = -1) override;
67 
70  };
71 
72  size_t size() const override { return size_; }
73 
74  std::vector<int8_t> moveBuffer() { return std::move(buff_); }
75 
76  void write(int8_t* src,
77  const size_t numBytes,
78  const size_t offset = 0,
80  const int srcDeviceId = -1) override {
81  CHECK(false);
82  }
83 
84  void reserve(size_t numBytes) override { CHECK(false); }
85 
86  int8_t* getMemoryPtr() override {
87  CHECK(false);
88  return nullptr;
89  }
90 
91  size_t pageCount() const override {
92  CHECK(false);
93  return 0;
94  }
95 
96  size_t pageSize() const override {
97  CHECK(false);
98  return 0;
99  }
100 
101  size_t reservedSize() const override {
102  CHECK(false);
103  return 0;
104  }
105 
106  private:
109  std::vector<int8_t> buff_;
110 };
111 
112 class ForeignStorageBufferMgr : public Data_Namespace::AbstractBufferMgr {
113  public:
114  ForeignStorageBufferMgr(const int db_id,
115  const int table_id,
116  PersistentForeignStorageInterface* persistent_foreign_storage);
117 
118  void checkpoint() override;
119 
120  Data_Namespace::AbstractBuffer* createBuffer(const ChunkKey& key,
121  const size_t pageSize = 0,
122  const size_t initialSize = 0) override;
123 
124  Data_Namespace::AbstractBuffer* getBuffer(const ChunkKey& key,
125  const size_t numBytes = 0) override;
126 
127  void fetchBuffer(const ChunkKey& key,
128  Data_Namespace::AbstractBuffer* destBuffer,
129  const size_t numBytes = 0) override;
130 
131  void getChunkMetadataVecForKeyPrefix(ChunkMetadataVector& chunkMetadataVec,
132  const ChunkKey& keyPrefix) override;
133  std::string getStringMgrType() override { return ToString(FILE_MGR); }
134 
135  size_t getNumChunks() override {
136  mapd_shared_lock<mapd_shared_mutex> chunk_index_write_lock(chunk_index_mutex_);
137  return chunk_index_.size();
138  }
139 
140  void deleteBuffer(const ChunkKey& key, const bool purge = true) override {
141  CHECK(false);
142  }
143 
144  void deleteBuffersWithPrefix(const ChunkKey& keyPrefix,
145  const bool purge = true) override {
146  CHECK(false);
147  }
148 
151  const size_t numBytes = 0) override {
152  CHECK(false);
153  return nullptr;
154  }
155 
156  void getChunkMetadataVec(ChunkMetadataVector& chunkMetadata) override { CHECK(false); }
157 
158  bool isBufferOnDevice(const ChunkKey& key) override {
159  CHECK(false);
160  return false;
161  }
162 
163  std::string printSlabs() override {
164  CHECK(false);
165  return "";
166  }
167 
168  void clearSlabs() override { CHECK(false); }
169 
170  size_t getMaxSize() override {
171  CHECK(false);
172  return 0;
173  }
174 
175  size_t getInUseSize() override {
176  CHECK(false);
177  return 0;
178  }
179 
180  size_t getAllocated() override {
181  CHECK(false);
182  return 0;
183  }
184 
185  bool isAllocationCapped() override {
186  CHECK(false);
187  return false;
188  }
189 
190  void checkpoint(const int db_id, const int tb_id) override { CHECK(false); }
191 
192  // Buffer API
193  Data_Namespace::AbstractBuffer* alloc(const size_t numBytes = 0) override {
194  CHECK(false);
195  return nullptr;
196  }
197 
198  void free(Data_Namespace::AbstractBuffer* buffer) override { CHECK(false); }
199 
200  MgrType getMgrType() override {
201  CHECK(false);
202  return FILE_MGR;
203  }
204 
205  void removeTableRelatedDS(const int db_id, const int table_id) override {
206  UNREACHABLE();
207  }
208 
209  private:
211  std::map<ChunkKey, std::unique_ptr<ForeignStorageBuffer>> chunk_index_;
213 };
214 
216  public:
217  static Data_Namespace::AbstractBufferMgr* lookupBufferManager(const int db_id,
218  const int table_id);
219 
220  static void registerPersistentStorageInterface(
221  std::unique_ptr<PersistentForeignStorageInterface> persistent_foreign_storage);
222 
223  static void destroy();
224 
226  static void prepareTable(const int db_id,
227  TableDescriptor& td,
228  std::list<ColumnDescriptor>& cols);
230  static void registerTable(Catalog_Namespace::Catalog* catalog,
231  const TableDescriptor& td,
232  const std::list<ColumnDescriptor>& cols);
233 
234  private:
235  static std::unordered_map<std::string,
236  std::unique_ptr<PersistentForeignStorageInterface>>
238  static std::map<std::pair<int, int>, PersistentForeignStorageInterface*>
240  static std::map<std::pair<int, int>, std::unique_ptr<ForeignStorageBufferMgr>>
243 };
void reserve(size_t numBytes) override
PersistentForeignStorageInterface * persistent_foreign_storage_
void deleteBuffer(const ChunkKey &key, const bool purge=true) override
int64_t * src
void checkpoint(const int db_id, const int tb_id) override
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:86
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
int8_t * getMemoryPtr() override
This file contains the class specification and related data structures for Catalog.
Data_Namespace::AbstractBuffer * putBuffer(const ChunkKey &key, Data_Namespace::AbstractBuffer *srcBuffer, const size_t numBytes=0) override
bool isBufferOnDevice(const ChunkKey &key) override
size_t read(FILE *f, const size_t offset, const size_t size, int8_t *buf)
Reads the specified number of bytes from the offset position in file f into buf.
Definition: File.cpp:112
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_
An AbstractBuffer is a unit of data management for a data manager.
static std::map< std::pair< int, int >, std::unique_ptr< ForeignStorageBufferMgr > > managers_map_
size_t append(FILE *f, const size_t size, int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
Definition: File.cpp:135
static std::mutex persistent_storage_interfaces_mutex_
std::map< ChunkKey, std::unique_ptr< ForeignStorageBuffer > > chunk_index_
std::vector< int8_t > buff_
size_t size() const override
Data_Namespace::AbstractBuffer * alloc(const size_t numBytes=0) override
void getChunkMetadataVec(ChunkMetadataVector &chunkMetadata) override
static 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::vector< int > ChunkKey
Definition: types.h:35
static std::unordered_map< std::string, std::unique_ptr< PersistentForeignStorageInterface > > persistent_storage_interfaces_
std::vector< std::pair< ChunkKey, std::shared_ptr< ChunkMetadata > >> ChunkMetadataVector
std::string printSlabs() override
specifies the content in-memory of a row in the table metadata table
PersistentForeignStorageInterface * persistent_foreign_storage_
void deleteBuffersWithPrefix(const ChunkKey &keyPrefix, const bool purge=true) override
size_t pageCount() const override
const std::vector< int8_t > buff
void removeTableRelatedDS(const int db_id, const int table_id) override