OmniSciDB  2e3a973ef4
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  std::vector<int8_t> moveBuffer() { return std::move(buff_); }
73 
74  void write(int8_t* src,
75  const size_t numBytes,
76  const size_t offset = 0,
78  const int srcDeviceId = -1) override {
79  CHECK(false);
80  }
81 
82  void reserve(size_t numBytes) override { CHECK(false); }
83 
84  int8_t* getMemoryPtr() override {
85  CHECK(false);
86  return nullptr;
87  }
88 
89  size_t pageCount() const override {
90  CHECK(false);
91  return 0;
92  }
93 
94  size_t pageSize() const override {
95  CHECK(false);
96  return 0;
97  }
98 
99  size_t reservedSize() const override {
100  CHECK(false);
101  return 0;
102  }
103 
104  private:
107  std::vector<int8_t> buff_;
108 };
109 
110 class ForeignStorageBufferMgr : public Data_Namespace::AbstractBufferMgr {
111  public:
112  ForeignStorageBufferMgr(const int db_id,
113  const int table_id,
114  PersistentForeignStorageInterface* persistent_foreign_storage);
115 
116  void checkpoint() override;
117 
118  Data_Namespace::AbstractBuffer* createBuffer(const ChunkKey& key,
119  const size_t pageSize = 0,
120  const size_t initialSize = 0) override;
121 
122  Data_Namespace::AbstractBuffer* getBuffer(const ChunkKey& key,
123  const size_t numBytes = 0) override;
124 
125  void fetchBuffer(const ChunkKey& key,
126  Data_Namespace::AbstractBuffer* destBuffer,
127  const size_t numBytes = 0) override;
128 
129  void getChunkMetadataVecForKeyPrefix(ChunkMetadataVector& chunkMetadataVec,
130  const ChunkKey& keyPrefix) override;
131  std::string getStringMgrType() override { return ToString(FILE_MGR); }
132 
133  size_t getNumChunks() override {
134  mapd_shared_lock<mapd_shared_mutex> chunk_index_write_lock(chunk_index_mutex_);
135  return chunk_index_.size();
136  }
137 
138  void deleteBuffer(const ChunkKey& key, const bool purge = true) override {
139  CHECK(false);
140  }
141 
142  void deleteBuffersWithPrefix(const ChunkKey& keyPrefix,
143  const bool purge = true) override {
144  CHECK(false);
145  }
146 
149  const size_t numBytes = 0) override {
150  CHECK(false);
151  return nullptr;
152  }
153 
154  bool isBufferOnDevice(const ChunkKey& key) override {
155  CHECK(false);
156  return false;
157  }
158 
159  std::string printSlabs() override {
160  CHECK(false);
161  return "";
162  }
163 
164  void clearSlabs() override { CHECK(false); }
165 
166  size_t getMaxSize() override {
167  CHECK(false);
168  return 0;
169  }
170 
171  size_t getInUseSize() override {
172  CHECK(false);
173  return 0;
174  }
175 
176  size_t getAllocated() override {
177  CHECK(false);
178  return 0;
179  }
180 
181  bool isAllocationCapped() override {
182  CHECK(false);
183  return false;
184  }
185 
186  void checkpoint(const int db_id, const int tb_id) override { CHECK(false); }
187 
188  // Buffer API
189  Data_Namespace::AbstractBuffer* alloc(const size_t numBytes = 0) override {
190  CHECK(false);
191  return nullptr;
192  }
193 
194  void free(Data_Namespace::AbstractBuffer* buffer) override { CHECK(false); }
195 
196  MgrType getMgrType() override {
197  CHECK(false);
198  return FILE_MGR;
199  }
200 
201  void removeTableRelatedDS(const int db_id, const int table_id) override {
202  UNREACHABLE();
203  }
204 
205  private:
207  std::map<ChunkKey, std::unique_ptr<ForeignStorageBuffer>> chunk_index_;
209 };
210 
212  public:
213  static Data_Namespace::AbstractBufferMgr* lookupBufferManager(const int db_id,
214  const int table_id);
215 
216  static void registerPersistentStorageInterface(
217  std::unique_ptr<PersistentForeignStorageInterface> persistent_foreign_storage);
218 
219  static void destroy();
220 
222  static void prepareTable(const int db_id,
223  TableDescriptor& td,
224  std::list<ColumnDescriptor>& cols);
226  static void registerTable(Catalog_Namespace::Catalog* catalog,
227  const TableDescriptor& td,
228  const std::list<ColumnDescriptor>& cols);
229 
230  private:
231  static std::unordered_map<std::string,
232  std::unique_ptr<PersistentForeignStorageInterface>>
234  static std::map<std::pair<int, int>, PersistentForeignStorageInterface*>
236  static std::map<std::pair<int, int>, std::unique_ptr<ForeignStorageBufferMgr>>
239 };
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:97
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:117
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:140
static std::mutex persistent_storage_interfaces_mutex_
std::map< ChunkKey, std::unique_ptr< ForeignStorageBuffer > > chunk_index_
std::vector< int8_t > buff_
Data_Namespace::AbstractBuffer * alloc(const size_t numBytes=0) 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:37
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