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
PDBPage.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 PDB_Page_C
20
#define PDB_Page_C
21
#include "
PDBPage.h
"
22
#include <cstring>
23
#include <stdlib.h>
24
#include <iostream>
25
26
// create an empty page
27
PDBPage::PDBPage
(
char
* dataIn,
28
NodeID
dataNodeID,
29
DatabaseID
dataDbID,
30
UserTypeID
dataTypeID,
31
SetID
dataSetID,
32
PageID
dataPageID,
33
size_t
dataSize,
34
size_t
shmOffset,
35
int
internalOffset,
36
int
numObjectsIn) {
37
rawBytes
= dataIn;
38
nodeID
= dataNodeID;
39
dbID
= dataDbID;
40
typeID
= dataTypeID;
41
setID
= dataSetID;
42
pageID
= dataPageID;
43
size
= dataSize;
44
offset
= shmOffset;
45
this->
numObjects
= numObjectsIn;
46
this->
curAppendOffset
=
sizeof
(
NodeID
) +
sizeof
(
DatabaseID
) +
sizeof
(
UserTypeID
) +
47
sizeof
(
SetID
) +
sizeof
(
PageID
) +
sizeof
(
int
) +
sizeof
(size_t);
48
this->
refCount
= 0;
49
this->
pinned
=
true
;
50
this->
dirty
=
false
;
51
this->
inFlush
=
false
;
52
this->
partitionId
= (
FilePartitionID
)(-1);
53
this->
pageSeqInPartition
= (
unsigned
int)(-1);
54
pthread_mutex_init(&(this->
refCountMutex
),
nullptr
);
55
pthread_rwlock_init(&(this->
flushLock
),
nullptr
);
56
this->internalOffset =
internalOffset
;
57
char
* refCountBytes = this->
rawBytes
+
58
(
sizeof
(
NodeID
) +
sizeof
(
DatabaseID
) +
sizeof
(
UserTypeID
) +
sizeof
(
SetID
) +
sizeof
(
PageID
));
59
*((
int
*)refCountBytes) = numObjectsIn;
60
char
* pageSizeBytes = refCountBytes +
sizeof
(int);
61
*((
size_t
*)pageSizeBytes) = dataSize;
62
}
63
64
65
// create a PDBPage instance from a non-empty page.
66
PDBPage::PDBPage
(
char
* dataIn,
size_t
offset,
int
internalOffset) {
67
this->
rawBytes
= dataIn;
68
this->offset =
offset
;
69
this->internalOffset =
internalOffset
;
70
this->
curAppendOffset
=
sizeof
(
NodeID
) +
sizeof
(
DatabaseID
) +
sizeof
(
UserTypeID
) +
71
sizeof
(
SetID
) +
sizeof
(
PageID
) +
sizeof
(
int
) +
sizeof
(size_t);
72
char
* cur = this->
rawBytes
;
73
this->
nodeID
= *((
NodeID
*)cur);
74
cur = cur +
sizeof
(
NodeID
);
75
this->
dbID
= *((
DatabaseID
*)cur);
76
cur = cur +
sizeof
(
DatabaseID
);
77
this->
typeID
= *((
UserTypeID
*)cur);
78
cur = cur +
sizeof
(
UserTypeID
);
79
this->
setID
= *((
SetID
*)cur);
80
cur = cur +
sizeof
(
SetID
);
81
this->
pageID
= *((
PageID
*)cur);
82
cur = cur +
sizeof
(
PageID
);
83
this->
numObjects
= *((
int
*)cur);
84
cur = cur +
sizeof
(int);
85
this->
size
= *((
size_t
*)cur);
86
this->
refCount
= 0;
87
this->
pinned
=
true
;
88
this->
dirty
=
false
;
89
this->
inFlush
=
false
;
90
this->
partitionId
= (
FilePartitionID
)(-1);
91
this->
pageSeqInPartition
= (
unsigned
int)(-1);
92
pthread_mutex_init(&(this->
refCountMutex
),
nullptr
);
93
pthread_rwlock_init(&(this->
flushLock
),
nullptr
);
94
}
95
96
97
PDBPage::~PDBPage
() {
98
freePage
();
99
pthread_mutex_destroy(&(this->
refCountMutex
));
100
pthread_rwlock_destroy(&(this->
flushLock
));
101
}
102
107
void
PDBPage::preparePage
() {
108
char
* cur = this->
rawBytes
;
109
*((
NodeID
*)cur) =
nodeID
;
110
cur = cur +
sizeof
(
NodeID
);
111
*((
DatabaseID
*)cur) =
dbID
;
112
cur = cur +
sizeof
(
DatabaseID
);
113
*((
UserTypeID
*)cur) =
typeID
;
114
cur = cur +
sizeof
(
UserTypeID
);
115
*((
SetID
*)cur) =
setID
;
116
cur = cur +
sizeof
(
SetID
);
117
*((
PageID
*)cur) =
pageID
;
118
cur = cur +
sizeof
(
PageID
);
119
*((
int
*)cur) = 0;
120
cur = cur +
sizeof
(int);
121
*((
size_t
*)cur) = this->
size
;
122
this->
curAppendOffset
=
sizeof
(
NodeID
) +
sizeof
(
DatabaseID
) +
sizeof
(
UserTypeID
) +
123
sizeof
(
SetID
) +
sizeof
(
PageID
) +
sizeof
(
int
) +
sizeof
(size_t);
124
return
;
125
}
126
127
128
void
PDBPage::readLock
() {
129
pthread_rwlock_rdlock(&(this->
flushLock
));
130
}
131
132
void
PDBPage::readUnlock
() {
133
pthread_rwlock_unlock(&(this->
flushLock
));
134
}
135
136
void
PDBPage::writeLock
() {
137
pthread_rwlock_wrlock(&(this->
flushLock
));
138
}
139
140
void
PDBPage::writeUnlock
() {
141
pthread_rwlock_unlock(&(this->
flushLock
));
142
}
143
144
void
*
PDBPage::getBytes
() {
145
146
return
this->
rawBytes
+
sizeof
(
NodeID
) +
sizeof
(
DatabaseID
) +
sizeof
(
UserTypeID
) +
147
sizeof
(
SetID
) +
sizeof
(
PageID
) +
sizeof
(
int
) +
sizeof
(size_t);
148
}
149
150
size_t
PDBPage::getSize
() {
151
152
return
this->
size
- (
sizeof
(
NodeID
) +
sizeof
(
DatabaseID
) +
sizeof
(
UserTypeID
) +
sizeof
(
SetID
) +
153
sizeof
(
PageID
) +
sizeof
(
int
) +
sizeof
(size_t));
154
}
155
156
void
PDBPage::unpin
() {
157
this->
decRefCount
();
158
}
159
160
161
void
PDBPage::freePage
() {
162
if
(
rawBytes
!=
nullptr
) {
163
// we always free page data by SharedMem class when page is flushed or evicted, and we do
164
// not free page data here
165
// If it comes to here, there must be a problem. Shared memory should already be freed,
166
// there could be memory leaks
167
rawBytes
=
nullptr
;
168
}
169
nodeID
= -1;
170
dbID
= -1;
171
typeID
= -1;
172
setID
= -1;
173
pageID
= -1;
174
offset
= 0;
175
size
= 0;
176
numObjects
= 0;
177
internalOffset
= 0;
178
}
179
180
#endif
PDBPage::dirty
bool dirty
Definition:
PDBPage.h:420
SetID
unsigned int SetID
Definition:
DataTypes.h:31
PDBPage::preparePage
void preparePage()
Definition:
PDBPage.cc:107
PDBPage::~PDBPage
~PDBPage()
Definition:
PDBPage.cc:97
PDBPage::internalOffset
int internalOffset
Definition:
PDBPage.h:439
PDBPage::inFlush
bool inFlush
Definition:
PDBPage.h:424
PDBPage::readLock
void readLock()
Definition:
PDBPage.cc:128
PDBPage::refCount
int refCount
Definition:
PDBPage.h:418
PDBPage::nodeID
NodeID nodeID
Definition:
PDBPage.h:412
NodeID
unsigned int NodeID
Definition:
DataTypes.h:27
PDBPage::writeLock
void writeLock()
Definition:
PDBPage.cc:136
PDBPage::flushLock
pthread_rwlock_t flushLock
Definition:
PDBPage.h:422
PDBPage::refCountMutex
pthread_mutex_t refCountMutex
Definition:
PDBPage.h:421
PDBPage::numObjects
int numObjects
Definition:
PDBPage.h:409
PDBPage::pageID
PageID pageID
Definition:
PDBPage.h:416
DatabaseID
unsigned int DatabaseID
Definition:
DataTypes.h:29
PageID
unsigned int PageID
Definition:
DataTypes.h:26
PDBPage::decRefCount
void decRefCount()
Definition:
PDBPage.h:93
PDBPage::unpin
void unpin()
Definition:
PDBPage.cc:156
PDBPage::readUnlock
void readUnlock()
Definition:
PDBPage.cc:132
PDBPage::size
size_t size
Definition:
PDBPage.h:417
PDBPage::pageSeqInPartition
unsigned int pageSeqInPartition
Definition:
PDBPage.h:435
PDBPage::rawBytes
char * rawBytes
Definition:
PDBPage.h:405
PDBPage::writeUnlock
void writeUnlock()
Definition:
PDBPage.cc:140
PDBPage.h
PDBPage::offset
size_t offset
Definition:
PDBPage.h:406
PDBPage::dbID
DatabaseID dbID
Definition:
PDBPage.h:413
PDBPage::pinned
bool pinned
Definition:
PDBPage.h:419
PDBPage::partitionId
FilePartitionID partitionId
Definition:
PDBPage.h:434
PDBPage::getBytes
void * getBytes()
Definition:
PDBPage.cc:144
PDBPage::getSize
size_t getSize()
Definition:
PDBPage.cc:150
PDBPage::setID
SetID setID
Definition:
PDBPage.h:415
PDBPage::PDBPage
PDBPage(char *dataIn, NodeID dataNodeID, DatabaseID dataDbID, UserTypeID dataTypeID, SetID setID, PageID pageID, size_t dataSize, size_t offset, int internalOffset=0, int numObjects=0)
Definition:
PDBPage.cc:27
FilePartitionID
unsigned int FilePartitionID
Definition:
DataTypes.h:32
PDBPage::freePage
void freePage()
Definition:
PDBPage.cc:161
PDBPage::typeID
UserTypeID typeID
Definition:
PDBPage.h:414
UserTypeID
unsigned int UserTypeID
Definition:
DataTypes.h:25
PDBPage::curAppendOffset
size_t curAppendOffset
Definition:
PDBPage.h:438
plinycompute
pdb
src
storage
source
PDBPage.cc
Generated on Mon Jun 18 2018 18:10:37 by
1.8.6