OmniSciDB  1dac507f6e
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Page.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 
23 #ifndef DATAMGR_MEMORY_FILE_PAGE_H
24 #define DATAMGR_MEMORY_FILE_PAGE_H
25 
26 #include "Shared/Logger.h"
27 
28 #include <cassert>
29 #include <deque>
30 #include <stdexcept>
31 #include <vector>
32 #include "../../Shared/types.h"
33 
34 namespace File_Namespace {
35 
46 struct Page {
47  int fileId;
48  size_t pageNum;
49 
51  Page(int fileId, size_t pageNum) : fileId(fileId), pageNum(pageNum) {}
52  Page() : fileId(-1), pageNum(0) {}
53 
54  inline bool isValid() { return fileId >= 0; }
55 };
56 
69 struct MultiPage {
70  size_t pageSize;
71  std::deque<Page> pageVersions;
72  std::deque<int> epochs;
73 
75  MultiPage(size_t pageSizeIn) : pageSize(pageSizeIn) {}
76 
79  while (pageVersions.size() > 0) {
80  pop();
81  }
82  }
83 
86  inline Page current(int* epoch = NULL) const {
87  if (pageVersions.size() < 1) {
88  LOG(FATAL) << "No current version of the page exists in this MultiPage.";
89  }
90  if (epoch != NULL) {
91  *epoch = this->epochs.back();
92  }
93  return pageVersions.back();
94  }
95 
97  inline void push(Page& page, const int epoch) {
98  pageVersions.push_back(page);
99  epochs.push_back(epoch);
100  CHECK_EQ(pageVersions.size(), epochs.size());
101  }
102 
104  inline void pop() {
105  if (pageVersions.size() < 1) {
106  LOG(FATAL) << "No page to pop.";
107  }
108  pageVersions.pop_front();
109  epochs.pop_front();
110  CHECK_EQ(pageVersions.size(), epochs.size());
111  }
112 };
113 
120 // typedef std::pair<std::pair<std::vector<int>,std::vector<int> >, Page > HeaderInfo;
121 struct HeaderInfo {
122  ChunkKey chunkKey; // a vector of ints
123  int pageId;
126 
128  const int pageId,
129  const int versionEpoch,
130  const Page& page)
131  : chunkKey(chunkKey), pageId(pageId), versionEpoch(versionEpoch), page(page) {}
132 };
133 
134 } // namespace File_Namespace
135 
136 #endif // DATAMGR_MEMORY_FILE_PAGE_H
#define CHECK_EQ(x, y)
Definition: Logger.h:198
std::vector< int > ChunkKey
Definition: types.h:35
Page current(int *epoch=NULL) const
Definition: Page.h:86
~MultiPage()
Destructor – purges all pages.
Definition: Page.h:78
A logical page (Page) belongs to a file on disk.
Definition: Page.h:46
void pop()
Purges the oldest Page.
Definition: Page.h:104
#define LOG(tag)
Definition: Logger.h:185
Stores Pair of ChunkKey and Page id and version, in a pair with a Page struct itself (File id and Pag...
Definition: Page.h:121
bool isValid()
Definition: Page.h:54
std::deque< Page > pageVersions
Definition: Page.h:71
size_t pageNum
unique identifier of the owning file
Definition: Page.h:48
MultiPage(size_t pageSizeIn)
Constructor.
Definition: Page.h:75
std::deque< int > epochs
Definition: Page.h:72
The MultiPage stores versions of the same logical page in a deque.
Definition: Page.h:69
void push(Page &page, const int epoch)
Pushes a new page with epoch value.
Definition: Page.h:97
HeaderInfo(const ChunkKey &chunkKey, const int pageId, const int versionEpoch, const Page &page)
Definition: Page.h:127
Page(int fileId, size_t pageNum)
page number
Definition: Page.h:51