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
UserType.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 
19 #ifndef USERTYPE_H
20 #define USERTYPE_H
21 
22 #include "DataTypes.h"
23 #include "SequenceFile.h"
24 #include "PageCache.h"
25 #include "PageCircularBuffer.h"
26 #include "UserSet.h"
27 
28 #include <string>
29 #include <map>
30 #include <memory>
31 #include <stdlib.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <unistd.h>
35 #include <vector>
36 #include <boost/filesystem.hpp>
37 
38 using namespace std;
39 
40 // create a smart pointer for Type objects
41 class UserType;
42 typedef shared_ptr<UserType> TypePtr;
43 
44 using namespace boost::filesystem;
45 
52 class UserType {
53 public:
57  UserType(NodeID nodeId,
58  DatabaseID dbId,
59  UserTypeID id,
60  string name,
61  ConfigurationPtr conf,
62  pdb::PDBLoggerPtr logger,
63  SharedMemPtr shm,
64  string metaTypePath,
65  vector<string>* dataTypePaths,
66  PageCachePtr cache,
67  PageCircularBufferPtr flushBuffer);
68 
73  ~UserType();
74 
78  void flush();
79 
80  // add new set
81  int addSet(string setName, SetID setId, size_t pageSize = DEFAULT_PAGE_SIZE);
82 
83  // Remove an existing set, including all the disk files associated with the set.
84  // If successful, return 0.
85  // Otherwise, e.g. the set doesn't exist, return -1.
86  int removeSet(SetID setId);
87 
88  // Return the specified Set instance that is belonging to this type instance.
89  // If no such set, returns nullptr.
90  SetPtr getSet(SetID setId);
91 
92  // Initialize type instance based on disk dirs and files.
93  // This function is only used for SequenceFile instances.
94  bool initializeFromTypeDir(path typeDir);
95 
96  // Initialize type instance based on disk dirs and files.
97  // This function is only used for PartitionedFile instances.
98  bool initializeFromMetaTypeDir(path metaTypeDir);
99 
100  // Return TypeID of the type instance.
101  UserTypeID getId() const {
102  return id;
103  }
104 
105  // Return name of the type instance.
106  string getName() const {
107  return name;
108  }
109 
110  // Set the TypeID for the type instance.
111  void setId(UserTypeID id) {
112  this->id = id;
113  }
114 
115  // Set the name for the type instance.
116  void setName(string name) {
117  this->name = name;
118  }
119 
120  // Return the total number of sets belonging to the type instance.
121  unsigned int getNumSets() {
122  return this->numSets;
123  }
124 
125  map<SetID, SetPtr>* getSets() {
126  return this->sets;
127  }
128 
129 
130 protected:
134  string encodePath(string typePath, SetID setId, string setName);
135 
136 private:
137  string name;
141  int numSets;
142  map<SetID, SetPtr>* sets;
146  string metaPath;
147  vector<string>* dataPaths;
150  pthread_mutex_t setLock;
151 };
152 
153 
154 #endif /* PDBTYPE_H */
void setId(UserTypeID id)
Definition: UserType.h:111
unsigned int SetID
Definition: DataTypes.h:31
unsigned int getNumSets()
Definition: UserType.h:121
NodeID nodeId
Definition: UserType.h:139
shared_ptr< UserType > TypePtr
Definition: UserType.h:41
string name
Definition: UserType.h:137
ConfigurationPtr conf
Definition: UserType.h:143
shared_ptr< PageCache > PageCachePtr
Definition: PageCache.h:39
PageCachePtr cache
Definition: UserType.h:148
unsigned int NodeID
Definition: DataTypes.h:27
map< SetID, SetPtr > * sets
Definition: UserType.h:142
string metaPath
Definition: UserType.h:146
vector< string > * dataPaths
Definition: UserType.h:147
shared_ptr< SharedMem > SharedMemPtr
Definition: SharedMem.h:32
int numSets
Definition: UserType.h:141
unsigned int DatabaseID
Definition: DataTypes.h:29
void setName(string name)
Definition: UserType.h:116
UserTypeID id
Definition: UserType.h:138
shared_ptr< Configuration > ConfigurationPtr
Definition: Configuration.h:89
SharedMemPtr shm
Definition: UserType.h:145
string getName() const
Definition: UserType.h:106
UserTypeID getId() const
Definition: UserType.h:101
DatabaseID dbId
Definition: UserType.h:140
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
map< SetID, SetPtr > * getSets()
Definition: UserType.h:125
shared_ptr< UserSet > SetPtr
Definition: UserSet.h:36
#define DEFAULT_PAGE_SIZE
Definition: Configuration.h:36
PageCircularBufferPtr flushBuffer
Definition: UserType.h:149
pthread_mutex_t setLock
Definition: UserType.h:150
pdb::PDBLoggerPtr logger
Definition: UserType.h:144
shared_ptr< PageCircularBuffer > PageCircularBufferPtr
unsigned int UserTypeID
Definition: DataTypes.h:25