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.
Main Page
Namespaces
Classes
Files
File List
File Members
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
35
SetCachePageIterator::SetCachePageIterator
(
PageCachePtr
cache,
UserSet
* set) {
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)
42
SetCachePageIterator::~SetCachePageIterator
() {}
43
44
PDBPagePtr
SetCachePageIterator::begin
() {
45
this->
iter
= this->
set
->
getDirtyPageSet
()->begin();
46
return
nullptr
;
47
}
48
49
PDBPagePtr
SetCachePageIterator::end
() {
50
this->
iter
= this->
set
->
getDirtyPageSet
()->end();
51
return
nullptr
;
52
}
53
54
PDBPagePtr
SetCachePageIterator::next
() {
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
103
bool
SetCachePageIterator::hasNext
() {
104
if
(this->
iter
!= this->
set
->
getDirtyPageSet
()->end()) {
105
return
true
;
106
}
else
{
107
return
false
;
108
}
109
}
110
111
#endif
CacheKey::setId
SetID setId
Definition:
DataTypes.h:87
PDBPagePtr
shared_ptr< PDBPage > PDBPagePtr
Definition:
PDBPage.h:32
SetCachePageIterator::hasNext
bool hasNext() override
Definition:
SetCachePageIterator.cc:103
PDBDebug.h
PageCachePtr
shared_ptr< PageCache > PageCachePtr
Definition:
PageCache.h:39
SetCachePageIterator::next
PDBPagePtr next() override
Definition:
SetCachePageIterator.cc:54
SetCachePageIterator::iter
std::unordered_map< PageID, FileSearchKey >::iterator iter
Definition:
SetCachePageIterator.h:69
CacheKey::dbId
DatabaseID dbId
Definition:
DataTypes.h:85
FileSearchKey::pageSeqInPartition
unsigned int pageSeqInPartition
Definition:
DataTypes.h:94
SetCachePageIterator::begin
PDBPagePtr begin()
Definition:
SetCachePageIterator.cc:44
UserSet::getTypeID
UserTypeID getTypeID()
Definition:
UserSet.h:225
UserSet::getSetID
SetID getSetID()
Definition:
UserSet.h:233
SetCachePageIterator::set
UserSet * set
Definition:
SetCachePageIterator.h:68
PageID
unsigned int PageID
Definition:
DataTypes.h:26
FileSearchKey::partitionId
FilePartitionID partitionId
Definition:
DataTypes.h:93
CacheKey::pageId
PageID pageId
Definition:
DataTypes.h:88
CacheKey
Definition:
DataTypes.h:84
SetCachePageIterator::cache
PageCachePtr cache
Definition:
SetCachePageIterator.h:67
UserSet::getDbID
DatabaseID getDbID()
Definition:
UserSet.h:217
PDB_COUT
#define PDB_COUT
Definition:
PDBDebug.h:31
UserSet::lockDirtyPageSet
void lockDirtyPageSet()
Definition:
UserSet.h:322
UserSet::unlockDirtyPageSet
void unlockDirtyPageSet()
Definition:
UserSet.h:326
FileSearchKey
Definition:
DataTypes.h:91
SetCachePageIterator.h
SetCachePageIterator::SetCachePageIterator
SetCachePageIterator(PageCachePtr cache, UserSet *set)
Definition:
SetCachePageIterator.cc:35
SetCachePageIterator::~SetCachePageIterator
virtual ~SetCachePageIterator()
Definition:
SetCachePageIterator.cc:42
CacheKey::typeId
UserTypeID typeId
Definition:
DataTypes.h:86
UserSet::getFile
PartitionedFilePtr getFile()
Definition:
UserSet.h:247
UserSet::getDirtyPageSet
unordered_map< PageID, FileSearchKey > * getDirtyPageSet()
Definition:
UserSet.h:318
UserSet
Definition:
UserSet.h:55
SetCachePageIterator::end
PDBPagePtr end()
Definition:
SetCachePageIterator.cc:49
plinycompute
pdb
src
storage
source
SetCachePageIterator.cc
Generated on Mon Jun 18 2018 18:10:37 by
1.8.6