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
LocalitySet.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 LOCALITY_SET_CC
20 #define LOCALITY_SET_CC
21 
22 #include "LocalitySet.h"
23 #include <iostream>
25  LocalitySetReplacementPolicy replacementPolicy,
26  OperationType operationType,
27  DurabilityType durabilityType,
28  PersistenceType persistenceType) {
29  cachedPages = new list<PDBPagePtr>();
30  this->localityType = localityType;
31  this->replacementPolicy = replacementPolicy;
32  this->operationType = operationType;
33  this->durabilityType = durabilityType;
34  this->persistenceType = persistenceType;
35  this->lifetimeEnded = false;
36 }
37 
39  cachedPages->clear();
40  delete cachedPages;
41 }
42 
44  cachedPages->push_back(page);
45 }
46 
48  for (list<PDBPagePtr>::iterator it = cachedPages->begin(); it != cachedPages->end(); ++it) {
49  if ((*it) == page) {
50  cachedPages->erase(it);
51  break;
52  }
53  }
54  cachedPages->push_back(page);
55 }
56 
58  for (list<PDBPagePtr>::iterator it = cachedPages->begin(); it != cachedPages->end(); ++it) {
59  if ((*it) == page) {
60  cachedPages->erase(it);
61  break;
62  }
63  }
64 }
65 
67  PDBPagePtr retPage = nullptr;
68  if (this->replacementPolicy == MRU) {
69  for (list<PDBPagePtr>::reverse_iterator it = cachedPages->rbegin();
70  it != cachedPages->rend();
71  ++it) {
72  if ((*it)->getRefCount() == 0) {
73  retPage = (*it);
74  break;
75  }
76  }
77  } else {
78  for (list<PDBPagePtr>::iterator it = cachedPages->begin(); it != cachedPages->end(); ++it) {
79  if ((*it)->getRefCount() == 0) {
80  retPage = (*it);
81  break;
82  }
83  }
84  }
85  return retPage;
86 }
87 
89  vector<PDBPagePtr>* retPages = new vector<PDBPagePtr>();
90  int totalPages = cachedPages->size();
91  if (totalPages == 0) {
92  delete retPages;
93  return nullptr;
94  }
95  int numPages = 0;
96  if (this->replacementPolicy == MRU) {
97  for (list<PDBPagePtr>::reverse_iterator it = cachedPages->rbegin();
98  it != cachedPages->rend();
99  ++it) {
100  if ((*it)->getRefCount() == 0) {
101  retPages->push_back(*it);
102  numPages++;
103  if (this->operationType == Write) {
104  break;
105  } else {
106 
107  if ((double)numPages / (double)totalPages >= 0.1) {
108  break;
109  }
110  }
111  }
112  }
113  } else {
114  for (list<PDBPagePtr>::iterator it = cachedPages->begin(); it != cachedPages->end(); ++it) {
115  if ((*it)->getRefCount() == 0) {
116  retPages->push_back(*it);
117  numPages++;
118  if (this->operationType == Write) {
119  break;
120  } else {
121  if ((double)numPages / (double)totalPages >= 0.1) {
122  break;
123  }
124  }
125  }
126  }
127  }
128  if (numPages == 0) {
129  delete retPages;
130  return nullptr;
131  } else {
132  return retPages;
133  }
134 }
135 
136 
138  this->replacementPolicy = policy;
139  this->operationType = operationType;
140  this->lifetimeEnded = false;
141 }
142 
144  this->lifetimeEnded = true;
145 }
146 
147 
149  return this->localityType;
150 }
151 
153  this->localityType = type;
154 }
155 
157  return this->replacementPolicy;
158 }
159 
161  this->replacementPolicy = policy;
162 }
163 
165  return this->operationType;
166 }
167 
169  this->operationType = type;
170 }
171 
172 
174  return this->durabilityType;
175 }
176 
178  this->durabilityType = type;
179 }
180 
182  return this->persistenceType;
183 }
184 
186  this->persistenceType = type;
187 }
188 
190  return this->lifetimeEnded;
191 }
192 
193 void LocalitySet::setLifetimeEnd(bool lifetimeEnded) {
194  this->lifetimeEnded = lifetimeEnded;
195 }
196 
197 
198 #endif
LocalitySetReplacementPolicy replacementPolicy
Definition: LocalitySet.h:135
shared_ptr< PDBPage > PDBPagePtr
Definition: PDBPage.h:32
OperationType
Definition: DataTypes.h:57
LocalityType localityType
Definition: LocalitySet.h:125
void unpin()
Definition: LocalitySet.cc:143
OperationType operationType
Definition: LocalitySet.h:145
LocalitySetReplacementPolicy getReplacementPolicy()
Definition: LocalitySet.cc:156
void setPersistenceType(PersistenceType type)
Definition: LocalitySet.cc:185
LocalityType
Definition: DataTypes.h:50
PDBPagePtr selectPageForReplacement()
Definition: LocalitySet.cc:66
bool lifetimeEnded
Definition: LocalitySet.h:170
LocalitySet(LocalityType localityType, LocalitySetReplacementPolicy replacementPolicy, OperationType operationType, DurabilityType durabilityType, PersistenceType persistenceType)
Definition: LocalitySet.cc:24
void setReplacementPolicy(LocalitySetReplacementPolicy policy)
Definition: LocalitySet.cc:160
void addCachedPage(PDBPagePtr page)
Definition: LocalitySet.cc:43
DurabilityType
Definition: DataTypes.h:59
bool isLifetimeEnded()
Definition: LocalitySet.cc:189
LocalitySetReplacementPolicy
Definition: DataTypes.h:52
DurabilityType getDurabilityType()
Definition: LocalitySet.cc:173
void updateCachedPage(PDBPagePtr page)
Definition: LocalitySet.cc:47
Definition: DataTypes.h:52
void setLocalityType(LocalityType type)
Definition: LocalitySet.cc:152
void pin(LocalitySetReplacementPolicy policy, OperationType operationType)
Definition: LocalitySet.cc:137
vector< PDBPagePtr > * selectPagesForReplacement()
Definition: LocalitySet.cc:88
LocalityType getLocalityType()
Definition: LocalitySet.cc:148
OperationType getOperationType()
Definition: LocalitySet.cc:164
PersistenceType
Definition: DataTypes.h:68
list< PDBPagePtr > * cachedPages
Definition: LocalitySet.h:113
void setOperationType(OperationType type)
Definition: LocalitySet.cc:168
void removeCachedPage(PDBPagePtr page)
Definition: LocalitySet.cc:57
void setLifetimeEnd(bool lifetimeEnded)
Definition: LocalitySet.cc:193
DurabilityType durabilityType
Definition: LocalitySet.h:154
PersistenceType getPersistenceType()
Definition: LocalitySet.cc:181
void setDurabilityType(DurabilityType type)
Definition: LocalitySet.cc:177
PersistenceType persistenceType
Definition: LocalitySet.h:163