OmniSciDB  06b3bd477c
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 #pragma once
23 
24 #include <boost/preprocessor.hpp>
25 #include "../Shared/types.h"
26 #include "AbstractBuffer.h"
27 
28 #define X_DEFINE_ENUM_WITH_STRING_CONVERSIONS_TOSTRING_CASE(r, data, elem) \
29  case elem: \
30  return BOOST_PP_STRINGIZE(elem);
31 
32 #define DEFINE_ENUM_WITH_STRING_CONVERSIONS(name, enumerators) \
33  enum name { BOOST_PP_SEQ_ENUM(enumerators) }; \
34  \
35  inline const char* ToString(name v) { \
36  switch (v) { \
37  BOOST_PP_SEQ_FOR_EACH( \
38  X_DEFINE_ENUM_WITH_STRING_CONVERSIONS_TOSTRING_CASE, name, enumerators) \
39  default: \
40  return "[Unknown " BOOST_PP_STRINGIZE(name) "]"; \
41  } \
42  }
43 
45  (FILE_MGR)(CPU_MGR)(GPU_MGR)(GLOBAL_FILE_MGR)(
46  PERSISTENT_STORAGE_MGR)(FOREIGN_STORAGE_MGR))
47 
48 namespace Data_Namespace {
49 
62 class AbstractBufferMgr {
63  public:
64  virtual ~AbstractBufferMgr() {}
65  AbstractBufferMgr(const int deviceId) : device_id_(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,
81  AbstractBuffer* srcBuffer,
82  const size_t numBytes = 0) = 0;
83  virtual void getChunkMetadataVec(ChunkMetadataVector& chunkMetadata) = 0;
84  virtual void getChunkMetadataVecForKeyPrefix(ChunkMetadataVector& chunkMetadataVec,
85  const ChunkKey& keyPrefix) = 0;
86 
87  virtual bool isBufferOnDevice(const ChunkKey& key) = 0;
88  virtual std::string printSlabs() = 0;
89  virtual void clearSlabs() = 0;
90  virtual size_t getMaxSize() = 0;
91  virtual size_t getInUseSize() = 0;
92  virtual size_t getAllocated() = 0;
93  virtual bool isAllocationCapped() = 0;
94 
95  virtual void checkpoint() = 0;
96  virtual void checkpoint(const int db_id, const int tb_id) = 0;
97  virtual void removeTableRelatedDS(const int db_id, const int table_id) = 0;
98 
99  // Buffer API
100  virtual AbstractBuffer* alloc(const size_t numBytes = 0) = 0;
101  virtual void free(AbstractBuffer* buffer) = 0;
102  virtual MgrType getMgrType() = 0;
103  virtual std::string getStringMgrType() = 0;
104  virtual size_t getNumChunks() = 0;
105  inline int getDeviceId() { return device_id_; }
106 
107  protected:
108  AbstractBufferMgr* parentMgr_;
109  int device_id_;
110 };
111 
112 } // namespace Data_Namespace
std::vector< int > ChunkKey
Definition: types.h:35
#define DEFINE_ENUM_WITH_STRING_CONVERSIONS(name, enumerators)
std::vector< std::pair< ChunkKey, std::shared_ptr< ChunkMetadata >>> ChunkMetadataVector