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
CatalogServer.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 CATALOG_SERVER_H
19 #define CATALOG_SERVER_H
20 
21 #include "CatalogClient.h"
22 #include "PDBCatalog.h"
23 #include "PDBDebug.h"
24 #include "PDBServer.h"
25 #include "ServerFunctionality.h"
26 
51 namespace pdb {
52 
54 
55 public:
56  /* Destructor */
58 
59  /* Creates a Catalog Server
60  * catalogDirectory: the path of the location of the catalog
61  * isManagerCatalogServer: true if this is the Manager Catalog Server
62  * workers nodes have this parameter set to false
63  * managerIP: the IP address of the Manager Catalog
64  * managerPort: the port number of the Manager Catalog
65  */
67  std::string managerIP, int managerPort);
68 
69  /* From the ServerFunctionality interface */
70  void registerHandlers(PDBServer &forMe) override;
71 
72  /* Returns the type Id of a type given its name */
73  int16_t searchForObjectTypeName(string objectTypeName);
74 
75  /* Returns the name of a type given it's type Id */
76  string searchForObjectTypeName(int16_t typeIdentifier);
77 
78  /* Retrieves the content of a Shared Library given it's Type Id
79  * putting it at the specified location
80  */
81  bool getSharedLibrary(int16_t identifier, vector<char> &putResultHere,
82  std::string &errMsg);
83 
84  /* Retrieves the content of a Shared Library along with its registered
85  * metadata,
86  * given it's typeName. Typically this method is invoked by a remote machine
87  * that
88  * has no knowledge of the typeID
89  */
90  bool getSharedLibraryByTypeName(std::string typeName,
91  Handle<CatalogUserTypeMetadata> &typeMetadata,
92  string &sharedLibraryBytes,
93  std::string &errMsg);
94 
95  /* Returns the type of an object in the specified set, as a type name */
96  int16_t getObjectType(string databaseName, string setName);
97 
98  /* Creates a new database... returns true on success */
99  bool addDatabase(string databaseName, string &errMsg);
100 
101  /* Deletes a database... returns true on success */
102  bool deleteDatabase(string databaseName, string &errMsg);
103 
104  /* Deletes a set from the database */
105  bool deleteSet(std::string databaseName, std::string setName,
106  std::string &errMsg);
107 
108  /* Creates a new set in a given database... returns true on success */
109  bool addSet(int16_t typeIdentifier, string databaseName, string setName,
110  string &errMsg);
111 
112  /* Adds information about a node to a set for a given database
113  * returns true on success, false on fail
114  */
115  bool addNodeToSet(std::string nodeIP, std::string databaseName,
116  std::string setName, std::string &errMsg);
117 
118  /* Adds information about a node to a database
119  * returns true on success, false on fail
120  */
121  bool addNodeToDB(std::string nodeIP, std::string databaseName,
122  std::string &errMsg);
123 
124  /* Removes information about a node from a set, this is invoked when storage
125  * removes a set for a database in a node in the cluster returns true on
126  * success
127  */
128  bool removeNodeFromSet(std::string nodeIP, std::string databaseName,
129  std::string setName, std::string &errMsg);
130 
131  /* Removes information about a node from a database, this is invoked when
132  * storage
133  * removes a database in a node in the cluster returns true on success
134  */
135  bool removeNodeFromDB(std::string nodeIP, std::string databaseName,
136  std::string &errMsg);
137 
138  /* Adds a new object type... return -1 on failure, this is done on a worker
139  * node catalog
140  * the typeID is given by the manager catalog
141  */
142  int16_t addObjectType(int16_t typeID, string &soFile, string &errMsg);
143 
144  /* Print the content of the catalog metadata that have changed since a given
145  * timestamp */
146  void printCatalog(Handle<CatalogPrintMetadata> &metadataToPrint);
147 
148  /* Print the contents of the catalog metadata */
149  bool printCatalog();
150 
151  /* Adds metadata about a new node in the cluster */
152  bool addNodeMetadata(Handle<CatalogNodeMetadata> &nodeMetadata,
153  std::string &errMsg);
154 
155  /* Adds metadata about a new database in the cluster */
157  std::string &errMsg);
158 
159  /* Adds metadata about a new set in the cluster */
160  bool addSetMetadata(Handle<CatalogSetMetadata> &setMetadata,
161  std::string &errMsg);
162 
163  /* Updates metadata changes about a database in the cluster */
165  std::string &errMsg);
166 
167  /* Returns true if this is the manager catalog server */
169 
170  /* Sets if this is the Manager Catalog Server (true) or not (false) */
171  void setIsManagerCatalogServer(bool isManagerCatalogServerIn);
172 
173  /* Broadcasts a metadata item to all available nodes in a cluster, when an
174  * update has occurred
175  * returns a map with the results from updating each node in the cluster
176  */
177  template <class Type>
178  bool broadcastCatalogUpdate(Handle<Type> metadataToSend,
179  map<string, pair<bool, string>> &broadcastResults,
180  string &errMsg);
181 
182  /* Broadcasts a metadata item to all available nodes in a cluster, when an
183  * delete has occurred returns a map with the results from updating each
184  * node in the cluster
185  */
186  template <class Type>
187  bool broadcastCatalogDelete(Handle<Type> metadataToSend,
188  map<string, pair<bool, string>> &broadcastResults,
189  string &errMsg);
190 
191  /* Returns true if a node is already registered in the Catalog */
192  bool isNodeRegistered(string nodeIP);
193 
194  /* Returns true if a database is already registered in the Catalog */
195  bool isDatabaseRegistered(string dbName);
196 
197  /* Returns true if a set for a given database is already registered in the
198  * Catalog */
199  bool isSetRegistered(string dbName, string setName);
200 
201  /* Returns a reference to the underlying class that manages catalog metadata
202  * the metadata is stored in a SQLite database
203  */
205 
206 private:
207  /* Containers for storing metadata retrieved from the catalog */
212 
213  /* Maps from type name string to typeID, and vice-versa */
214  map<string, int16_t> allTypeNames;
215  map<int16_t, string> allTypeCodes;
216 
217  /* Vector of nodes in the cluster */
218  vector<string> allNodesInCluster;
219 
220  /* Maps from database/set pair to the typeID that set stores */
221  map<pair<string, string>, int16_t> setTypes;
222 
223  /* Interface to a persistent catalog storage for storing and retrieving PDB
224  * metadata.
225  * All metadata is stored in an SQLite database.
226  */
228 
229  /* Catalog client helper to connect to the Manager Catalog Server */
231 
232  /* Path where the catalog file is located */
233  std::string catalogDirectory;
234 
235  /* To ensure serialized access */
236  pthread_mutex_t workingMutex;
237 
238  /* True if this is the Manager Catalog Server */
240 
241  /* Default IP of the Catalog Server, can be changed in the constructor */
242  string managerIP = "localhost";
243 
244  /* Default port of the Catalog Server, can be changed in the constructor */
245  int managerPort = 8108;
246 
247  /* Logger to capture debug information for the Catalog Server */
249 };
250 }
251 
252 #endif
int16_t addObjectType(int16_t typeID, string &soFile, string &errMsg)
void registerHandlers(PDBServer &forMe) override
bool deleteDatabase(string databaseName, string &errMsg)
bool deleteSet(std::string databaseName, std::string setName, std::string &errMsg)
bool addSet(int16_t typeIdentifier, string databaseName, string setName, string &errMsg)
Handle< Vector< CatalogSetMetadata > > _setTypes
map< int16_t, string > allTypeCodes
bool broadcastCatalogDelete(Handle< Type > metadataToSend, map< string, pair< bool, string >> &broadcastResults, string &errMsg)
bool addSetMetadata(Handle< CatalogSetMetadata > &setMetadata, std::string &errMsg)
map< pair< string, string >, int16_t > setTypes
bool addDatabaseMetadata(Handle< CatalogDatabaseMetadata > &dbMetadata, std::string &errMsg)
PDBCatalogPtr getCatalog()
vector< string > allNodesInCluster
PDBCatalogPtr pdbCatalog
bool getSharedLibrary(int16_t identifier, vector< char > &putResultHere, std::string &errMsg)
bool broadcastCatalogUpdate(Handle< Type > metadataToSend, map< string, pair< bool, string >> &broadcastResults, string &errMsg)
bool addNodeMetadata(Handle< CatalogNodeMetadata > &nodeMetadata, std::string &errMsg)
std::string catalogDirectory
bool getSharedLibraryByTypeName(std::string typeName, Handle< CatalogUserTypeMetadata > &typeMetadata, string &sharedLibraryBytes, std::string &errMsg)
bool removeNodeFromSet(std::string nodeIP, std::string databaseName, std::string setName, std::string &errMsg)
Handle< Vector< CatalogNodeMetadata > > _allNodesInCluster
bool addNodeToSet(std::string nodeIP, std::string databaseName, std::string setName, std::string &errMsg)
PDBLoggerPtr catServerLogger
bool updateDatabaseMetadata(Handle< CatalogDatabaseMetadata > &dbMetadata, std::string &errMsg)
shared_ptr< PDBCatalog > PDBCatalogPtr
Definition: PDBCatalog.h:77
bool isDatabaseRegistered(string dbName)
void setIsManagerCatalogServer(bool isManagerCatalogServerIn)
map< string, int16_t > allTypeNames
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
bool removeNodeFromDB(std::string nodeIP, std::string databaseName, std::string &errMsg)
int16_t searchForObjectTypeName(string objectTypeName)
Handle< Vector< CatalogUserTypeMetadata > > _udfsValues
bool addDatabase(string databaseName, string &errMsg)
pthread_mutex_t workingMutex
bool isNodeRegistered(string nodeIP)
bool isSetRegistered(string dbName, string setName)
Handle< Vector< CatalogDatabaseMetadata > > _allDatabases
CatalogClient catalogClientConnectionToManagerCatalogServer
int16_t getObjectType(string databaseName, string setName)
CatalogServer(std::string catalogDirectory, bool isManagerCatalogServer, std::string managerIP, int managerPort)
bool addNodeToDB(std::string nodeIP, std::string databaseName, std::string &errMsg)
bool getIsManagerCatalogServer()