OmniSciDB  04ee39c94c
AbstractBufferMgr.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 
22 #ifndef ABSTRACTDATAMGR_H
23 #define ABSTRACTDATAMGR_H
24 
25 #include <boost/preprocessor.hpp>
26 #include "../Shared/types.h"
27 #include "AbstractBuffer.h"
28 
29 #define X_DEFINE_ENUM_WITH_STRING_CONVERSIONS_TOSTRING_CASE(r, data, elem) \
30  case elem: \
31  return BOOST_PP_STRINGIZE(elem);
32 
33 #define DEFINE_ENUM_WITH_STRING_CONVERSIONS(name, enumerators) \
34  enum name { BOOST_PP_SEQ_ENUM(enumerators) }; \
35  \
36  inline const char* ToString(name v) { \
37  switch (v) { \
38  BOOST_PP_SEQ_FOR_EACH( \
39  X_DEFINE_ENUM_WITH_STRING_CONVERSIONS_TOSTRING_CASE, name, enumerators) \
40  default: \
41  return "[Unknown " BOOST_PP_STRINGIZE(name) "]"; \
42  } \
43  }
44 
46  (FILE_MGR)(CPU_MGR)(GPU_MGR)(GLOBAL_FILE_MGR))
47 
48 namespace Data_Namespace {
49 
62 class AbstractBufferMgr {
63  public:
64  virtual ~AbstractBufferMgr() {}
65  AbstractBufferMgr(const int deviceId) : deviceId_(deviceId) {}
66 
67  // Chunk API
68  virtual AbstractBuffer* createBuffer(const ChunkKey& key,
69  const size_t pageSize = 0,
70  const size_t initialSize = 0) = 0;
71  virtual void deleteBuffer(
72  const ChunkKey& key,
73  const bool purge = true) = 0; // purge param only used in FileMgr
74  virtual void deleteBuffersWithPrefix(const ChunkKey& keyPrefix,
75  const bool purge = true) = 0;
76  virtual AbstractBuffer* getBuffer(const ChunkKey& key, const size_t numBytes = 0) = 0;
77  virtual void fetchBuffer(const ChunkKey& key,
78  AbstractBuffer* destBuffer,
79  const size_t numBytes = 0) = 0;
80  // virtual AbstractBuffer* putBuffer(const ChunkKey &key, AbstractBuffer *srcBuffer,
81  // const size_t numBytes = 0) = 0;
82  virtual AbstractBuffer* putBuffer(const ChunkKey& key,
83  AbstractBuffer* srcBuffer,
84  const size_t numBytes = 0) = 0;
85  virtual void getChunkMetadataVec(
86  std::vector<std::pair<ChunkKey, ChunkMetadata>>& chunkMetadata) = 0;
87  virtual void getChunkMetadataVecForKeyPrefix(
88  std::vector<std::pair<ChunkKey, ChunkMetadata>>& chunkMetadataVec,
89  const ChunkKey& keyPrefix) = 0;
90 
91  virtual bool isBufferOnDevice(const ChunkKey& key) = 0;
92  virtual std::string printSlabs() = 0;
93  virtual void clearSlabs() = 0;
94  virtual size_t getMaxSize() = 0;
95  virtual size_t getInUseSize() = 0;
96  virtual size_t getAllocated() = 0;
97  virtual bool isAllocationCapped() = 0;
98 
99  virtual void checkpoint() = 0;
100  virtual void checkpoint(const int db_id, const int tb_id) = 0;
101 
102  // Buffer API
103  virtual AbstractBuffer* alloc(const size_t numBytes = 0) = 0;
104  virtual void free(AbstractBuffer* buffer) = 0;
105  // virtual AbstractBuffer* putBuffer(AbstractBuffer *d) = 0;
106  virtual MgrType getMgrType() = 0;
107  virtual std::string getStringMgrType() = 0;
108  virtual size_t getNumChunks() = 0;
109  inline int getDeviceId() { return deviceId_; }
110 
111  protected:
112  AbstractBufferMgr* parentMgr_;
113  int deviceId_;
114 };
115 
116 } // namespace Data_Namespace
117 
118 #endif // ABSTRACTDATAMGR_H
#define DEFINE_ENUM_WITH_STRING_CONVERSIONS(name, enumerators)
std::vector< int > ChunkKey
Definition: types.h:35