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
FileSet.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 #ifndef FILESET_CC
19 #define FILESET_CC
20 
21 #include "FileSet.h"
22 #include "FileSetPageIterator.h"
23 #include <stdio.h>
24 #include <string>
25 #include <cstring>
26 #include <fcntl.h>
27 #include <iostream>
28 #include <fstream>
29 #include <stdlib.h>
30 #include <sys/stat.h>
31 #include <sys/types.h>
32 #include <unistd.h>
33 #include <sys/stat.h>
34 
36  string filePath,
37  size_t pageSize,
38  NodeID nodeId,
39  DatabaseID dbId,
40  UserTypeID typeId,
41  SetID setId)
43  this->cache = cache;
44  this->filePath = filePath;
45  this->pageSize = pageSize;
46  this->fileSize = 0;
47  this->nodeId = nodeId;
48  this->dbId = dbId;
49  this->typeId = typeId;
50  this->setId = setId;
51 #ifdef __APPLE__
52  this->handle = open(filePath.c_str(), O_RDWR | O_APPEND | O_CREAT, S_IRWXU | S_IRWXO);
53 #else
54  this->handle =
55  open(filePath.c_str(), O_RDWR | O_APPEND | O_CREAT | O_DIRECT, S_IRWXU | S_IRWXO);
56 #endif
57  if (handle < 0) {
58  cout << "file can't be open:" << this->filePath << "\n";
59  exit(-1);
60  }
61 }
62 
64  if (this->handle >= 0) {
65  this->clear();
66  }
67 }
68 
70  close(this->handle);
71  this->handle = -1;
72  remove(this->filePath.c_str());
73 }
74 
75 int FileSet::writeData(void* data, size_t length) {
76  size_t retSize = write(this->handle, data, length);
77  if (retSize < length) {
78  return -1;
79  } else {
80  this->fileSize = this->fileSize + length;
81  return 0;
82  }
83 }
84 
86  PageIteratorPtr iter = make_shared<FileSetPageIterator>(this->cache,
87  this->handle,
88  this->fileSize,
89  this->pageSize,
90  this->nodeId,
91  this->dbId,
92  this->typeId,
93  this->setId);
94  return iter;
95 }
96 #endif
~FileSet()
Definition: FileSet.cc:63
unsigned int SetID
Definition: DataTypes.h:31
FileSet(PageCachePtr cache, string filePath, size_t pageSize, NodeID nodeId, DatabaseID dbId, UserTypeID typeId, SetID setId)
Definition: FileSet.cc:35
NodeID nodeId
Definition: FileSet.h:71
shared_ptr< PageCache > PageCachePtr
Definition: PageCache.h:39
shared_ptr< PageIteratorInterface > PageIteratorPtr
Definition: PageIterator.h:33
unsigned int NodeID
Definition: DataTypes.h:27
PageCachePtr cache
Definition: FileSet.h:68
Definition: DataTypes.h:52
unsigned int DatabaseID
Definition: DataTypes.h:29
int writeData(void *data, size_t length)
Definition: FileSet.cc:75
string filePath
Definition: FileSet.h:66
DatabaseID dbId
Definition: FileSet.h:72
UserTypeID typeId
Definition: FileSet.h:73
void clear()
Definition: FileSet.cc:69
size_t pageSize
Definition: FileSet.h:69
int handle
Definition: FileSet.h:67
SetID setId
Definition: FileSet.h:74
size_t fileSize
Definition: FileSet.h:70
PageIteratorPtr getIterator()
Definition: FileSet.cc:85
unsigned int UserTypeID
Definition: DataTypes.h:25