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
PartitionedFile.h
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 #ifndef PARTITIONEDFILE_H
19 #define PARTITIONEDFILE_H
20 
21 #include "PDBFile.h"
23 #include "SharedMem.h"
24 #include <string>
25 #include <vector>
26 #include <memory>
27 using namespace std;
29 typedef shared_ptr<PartitionedFile> PartitionedFilePtr;
30 
70 public:
74  PartitionedFile(NodeID nodeId,
75  DatabaseID dbId,
76  UserTypeID typeId,
77  SetID setId,
78  string metaPartitionPath,
79  vector<string> dataPartitionPaths,
80  pdb::PDBLoggerPtr logger,
81  size_t pageSize);
82 
86  PartitionedFile(NodeID nodeId,
87  DatabaseID dbId,
88  UserTypeID typeId,
89  SetID setId,
90  string metaPartitionPath,
91  pdb::PDBLoggerPtr logger);
92 
96  ~PartitionedFile();
97 
101  bool openAll() override;
102 
106  bool openMeta();
107 
111  bool openData();
112 
116  bool openDataDirect();
117 
121  bool closeAll() override;
122 
126  bool closeDirect();
127 
131  void clear() override;
132 
137  int appendPage(FilePartitionID partitionId, PDBPagePtr page) override;
138 
142  int appendPageDirect(FilePartitionID partitionId, PDBPagePtr page);
143 
147  int writeMeta() override;
148 
149 
153  int updateMeta() override;
154 
164  size_t loadPage(FilePartitionID partitionId,
165  unsigned int pageSeqInPartition,
166  char* pageInCache,
167  size_t length) override;
168 
172  size_t loadPageDirect(FilePartitionID partitionId,
173  unsigned int pageSeqInPartition,
174  char* pageInCache,
175  size_t length);
176 
177 
183  size_t loadPageFromCurPos(FilePartitionID partitionId,
184  unsigned int pageSeqInPartition,
185  char* pageInCache,
186  size_t length);
187 
192  PageID loadPageId(FilePartitionID partitionId, unsigned int pageSeqInPartition);
193 
199  PageID loadPageIdFromCurPos(FilePartitionID partitionId,
200  unsigned int pageSeqInPartition,
201  char* pageInCache,
202  size_t length);
203 
204 
210  unsigned int getAndSetNumFlushedPages() override;
211 
215  unsigned int getNumFlushedPages() override;
216 
220  PageID getLastFlushedPageID() override;
221 
225  PageID getLatestPageID() override;
226 
230  NodeID getNodeId() override;
231 
235  DatabaseID getDbId() override;
236 
240  UserTypeID getTypeId() override;
241 
245  SetID getSetId() override;
246 
250  size_t getPageSize() override;
251 
255  size_t getPageSizeInMeta() override;
256 
260  FileType getFileType() override;
261 
265  PartitionedFileMetaDataPtr getMetaData();
266 
270  void initializeDataFiles();
271 
275  void setDataPartitionPaths(const vector<string>& dataPartitionPaths);
276 
280  void buildMetaDataFromMetaPartition(SharedMemPtr shm);
281 
285  unsigned int getNumPartitions();
286 
287 protected:
291  int writeData(FILE* file, void* data, size_t length);
292 
296  int writeDataDirect(int handle, void* data, size_t length);
297 
301  int seekPage(FILE* file, unsigned int pageSeqInPartition);
302 
306  int seekPageDirect(int handle, unsigned int pageSeqInPartition);
307 
311  int seekPageSizeInMeta();
312 
316  int seekNumFlushedPagesInMeta();
317 
321  int seekNumFlushedPagesInPartitionMeta(FilePartitionID partitionId);
322 
323 
324 private:
328  pthread_mutex_t fileMutex;
329 
330 
334  FILE* metaFile = nullptr;
335  // int metaHandle;
336 
340  vector<FILE*> dataFiles;
341  vector<int> dataHandles;
342 
347 
351  vector<string> dataPartitionPaths;
352 
356  pdb::PDBLoggerPtr logger = nullptr;
357 
361  PartitionedFileMetaDataPtr metaData = nullptr;
362 
367 
372 
377 
382 
386  size_t pageSize = 0;
387 
392 
396  bool cleared;
397 };
398 
399 
400 #endif /* PARTITIONEDFILE_H */
vector< string > dataPartitionPaths
unsigned int SetID
Definition: DataTypes.h:31
shared_ptr< PDBPage > PDBPagePtr
Definition: PDBPage.h:32
vector< FILE * > dataFiles
FileType
Definition: DataTypes.h:72
vector< int > dataHandles
unsigned int NodeID
Definition: DataTypes.h:27
shared_ptr< PartitionedFile > PartitionedFilePtr
shared_ptr< SharedMem > SharedMemPtr
Definition: SharedMem.h:32
unsigned int DatabaseID
Definition: DataTypes.h:29
unsigned int PageID
Definition: DataTypes.h:26
pthread_mutex_t fileMutex
shared_ptr< PartitionedFileMetaData > PartitionedFileMetaDataPtr
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
unsigned int FilePartitionID
Definition: DataTypes.h:32
unsigned int UserTypeID
Definition: DataTypes.h:25