A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
FileSetPageIterator.cc
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 
19 #ifndef FILESETPAGEITERATOR_CC
20 #define FILESETPAGEITERATOR_CC
21 
22 #include "FileSetPageIterator.h"
23 #include <stdio.h>
24 #include <string>
25 #include <cstring>
26 #include <fcntl.h>
27 #include <iostream>
28 #include <fstream>
29 #include <stdlib.h>
30 #include <sys/stat.h>
31 #include <sys/types.h>
32 #include <unistd.h>
33 #include <sys/stat.h>
34 
36  int handle,
37  size_t fileSize,
38  size_t pageSize,
39  NodeID nodeId,
40  DatabaseID dbId,
41  UserTypeID typeId,
42  SetID setId) {
43  this->cache = cache;
44  this->handle = handle;
45  this->fileSize = fileSize;
46  this->pageSize = pageSize;
47  this->iteratedSize = 0;
48  // Suppose there is only one iterator running at a time
49  lseek(handle, 0, SEEK_SET);
50  this->nodeId = nodeId;
51  this->dbId = dbId;
52  this->typeId = typeId;
53  this->setId = setId;
54  this->pageId = 0;
55 }
56 
58 
60  if (iteratedSize < this->fileSize) {
61  return true;
62  } else {
63  return false;
64  }
65 }
66 
67 
69  if (iteratedSize >= this->fileSize) {
70  return nullptr;
71  } else {
72  size_t size = this->fileSize - iteratedSize;
73  PDBPagePtr page;
74  if (size < pageSize) {
75  page = cache->buildAndCachePageFromFileHandle(
76  handle, size, nodeId, dbId, typeId, setId, pageId);
77  this->iteratedSize += size;
78  } else {
79  page = cache->buildAndCachePageFromFileHandle(
81  this->iteratedSize += pageSize;
82  }
83 
84  pageId++;
85  return page;
86  }
87 }
88 
90  if (offset < this->iteratedSize) {
91  this->iteratedSize = this->iteratedSize - offset;
92  return true;
93  } else {
94  return false;
95  }
96 }
97 
98 #endif
unsigned int SetID
Definition: DataTypes.h:31
shared_ptr< PDBPage > PDBPagePtr
Definition: PDBPage.h:32
FileSetPageIterator(PageCachePtr cache, int fileHandle, size_t fileSize, size_t pageSize, NodeID nodeId, DatabaseID dbId, UserTypeID typeId, SetID setId)
shared_ptr< PageCache > PageCachePtr
Definition: PageCache.h:39
unsigned int NodeID
Definition: DataTypes.h:27
PDBPagePtr next() override
unsigned int DatabaseID
Definition: DataTypes.h:29
bool offsetIteratedSize(size_t iteratedSize)
unsigned int UserTypeID
Definition: DataTypes.h:25