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
SetCachePageIterator.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 
20 #ifndef SET_CACHE_PAGE_ITERATOR_CC
21 #define SET_CACHE_PAGE_ITERATOR_CC
22 
23 #include "PDBDebug.h"
24 #include "SetCachePageIterator.h"
25 // TODO using snapshot and reference count to support multiple concurrent iterators for one same
26 // buffer
27 // Argument: why do we need multiple concurrent iterators for the same buffer?
28 // Maybe there are two concurrent jobs? so can we just share the iterator between two jobs?
29 
30 // thread-safe (Fixed by Jia: now flushing is OK by updating the FileSearchKey)
31 
32 // NOTE: the constructor can only be invoked in UserSet::getIterators(), where it will be protected
33 // by lockDirtyPageSet();
34 
36  this->cache = cache;
37  this->set = set;
38  this->iter = this->set->getDirtyPageSet()->begin();
39 }
40 
41 // remove all elements that have been flushed to disk (inCache == false)
43 
45  this->iter = this->set->getDirtyPageSet()->begin();
46  return nullptr;
47 }
48 
50  this->iter = this->set->getDirtyPageSet()->end();
51  return nullptr;
52 }
53 
55  this->cache->evictionLock();
56  if (this->iter != this->set->getDirtyPageSet()->end()) {
57  if (this->iter->second.inCache == true) {
58  CacheKey key;
59  key.dbId = this->set->getDbID();
60  key.typeId = this->set->getTypeID();
61  key.setId = this->set->getSetID();
62  key.pageId = this->iter->first;
63  PDB_COUT << "SetCachePageIterator: in cache: curPageId=" << key.pageId << "\n";
64 #ifdef USE_LOCALITY_SET
65  PDBPagePtr page = this->cache->getPage(key, this->set);
66 #else
67  PDBPagePtr page = this->cache->getPage(key, nullptr);
68 #endif
69  this->cache->evictionUnlock();
70  ++iter;
71  return page;
72  } else {
73  this->cache->evictionUnlock();
74  // the page is already flushed to file, so load from file
75  PageID pageId = this->iter->first;
76  PDB_COUT << "SetCachePageIterator: not in cache: curPageId=" << pageId << "\n";
77  FileSearchKey searchKey = this->iter->second;
78 #ifdef USE_LOCALITY_SET
79  PDBPagePtr page = this->cache->getPage(this->set->getFile(),
80  searchKey.partitionId,
81  searchKey.pageSeqInPartition,
82  pageId,
83  false,
84  this->set);
85 #else
86  PDBPagePtr page = this->cache->getPage(this->set->getFile(),
87  searchKey.partitionId,
88  searchKey.pageSeqInPartition,
89  pageId,
90  false,
91  nullptr);
92 #endif
93  // remove iter
94  this->set->lockDirtyPageSet();
95  this->iter = this->set->getDirtyPageSet()->erase(this->iter);
96  this->set->unlockDirtyPageSet();
97  return page;
98  }
99  }
100  return nullptr;
101 }
102 
104  if (this->iter != this->set->getDirtyPageSet()->end()) {
105  return true;
106  } else {
107  return false;
108  }
109 }
110 
111 #endif
SetID setId
Definition: DataTypes.h:87
shared_ptr< PDBPage > PDBPagePtr
Definition: PDBPage.h:32
shared_ptr< PageCache > PageCachePtr
Definition: PageCache.h:39
PDBPagePtr next() override
std::unordered_map< PageID, FileSearchKey >::iterator iter
DatabaseID dbId
Definition: DataTypes.h:85
unsigned int pageSeqInPartition
Definition: DataTypes.h:94
UserTypeID getTypeID()
Definition: UserSet.h:225
SetID getSetID()
Definition: UserSet.h:233
unsigned int PageID
Definition: DataTypes.h:26
FilePartitionID partitionId
Definition: DataTypes.h:93
PageID pageId
Definition: DataTypes.h:88
DatabaseID getDbID()
Definition: UserSet.h:217
#define PDB_COUT
Definition: PDBDebug.h:31
void lockDirtyPageSet()
Definition: UserSet.h:322
void unlockDirtyPageSet()
Definition: UserSet.h:326
SetCachePageIterator(PageCachePtr cache, UserSet *set)
UserTypeID typeId
Definition: DataTypes.h:86
PartitionedFilePtr getFile()
Definition: UserSet.h:247
unordered_map< PageID, FileSearchKey > * getDirtyPageSet()
Definition: UserSet.h:318