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
PDBCatalog.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 PDB_CATALOG_H_
19 #define PDB_CATALOG_H_
20 
21 #include <algorithm>
22 #include <ctime>
23 #include <dirent.h>
24 #include <dlfcn.h>
25 #include <fstream>
26 #include <iostream>
27 #include <map>
28 #include <pthread.h>
29 #include <sqlite3.h>
30 #include <sstream>
31 #include <stdio.h>
32 #include <string.h>
33 #include <string>
34 #include <sys/stat.h>
35 #include <unistd.h>
36 #include <vector>
37 
39 #include "CatalogNodeMetadata.h"
41 #include "CatalogPrintMetadata.h"
42 #include "CatalogSetMetadata.h"
49 #include "Handle.h"
50 #include "InterfaceFunctions.h"
51 #include "Object.h"
52 #include "PDBCatalogMsgType.h"
53 #include "PDBCommunicator.h"
54 #include "PDBDebug.h"
55 #include "PDBLogger.h"
56 
57 using namespace std;
58 using namespace pdb;
59 
77 class PDBCatalog;
78 typedef shared_ptr<PDBCatalog> PDBCatalogPtr;
79 
80 class PDBCatalog {
81 public:
90  PDBCatalog(PDBLoggerPtr logger, string location);
91 
96  ~PDBCatalog();
97 
103  void open();
104 
120  bool registerUserDefinedObject(
121  int16_t typeCode,
122  pdb::Handle<CatalogUserTypeMetadata> &objectToRegister,
123  const string &objectBytes,
124  const string &typeName,
125  const string &fileName,
126  const string &tableName,
127  string &errorMessage);
128 
140  template <class CatalogMetadataType>
141  bool addMetadataToCatalog(
142  Handle<CatalogMetadataType> &metadataValue,
143  int &metadataCategory,
144  string &errorMessage);
145 
154  template <class CatalogMetadataType>
155  bool addItemToVector(Handle<CatalogMetadataType> &item, int &key);
156 
167  template <class CatalogMetadataType>
168  bool updateMetadataInCatalog(
169  pdb::Handle<CatalogMetadataType> &metadataValue,
170  int &metadataCategory,
171  string &errorMessage);
172 
183  template <class CatalogMetadataType>
184  bool deleteMetadataInCatalog(
185  pdb::Handle<CatalogMetadataType> metadataValue,
186  int &metadataCategory,
187  string &errorMessage);
188 
197  template <class CatalogMetadataType>
198  bool updateItemInVector(
199  int &index,
201 
210  template <class CatalogMetadataType>
211  bool deleteItemInVector(
212  int &index,
214 
218  map<string, CatalogNodeMetadata> getListOfNodesInCluster();
219 
232  bool getSerializedCatalog(string fileName, string version,
233  string &returnedBytes, string &errorMessage);
234 
241  void setCatalogVersion(string version);
242 
246  string getCatalogVersion();
247 
251  void getModifiedMetadata(Handle<CatalogPrintMetadata> &itemMetadata);
252 
270  template <class CatalogMetadataType>
271  bool getMetadataFromCatalog(
272  bool onlyModified,
273  string key,
274  Handle<pdb::Vector<CatalogMetadataType>> &returnedEntries,
275  string &errorMessage,
276  int metadataCategory);
277 
286  int getLastId(int &metadataCategory);
287 
295  string itemName2ItemId(int &metadataCategory, string &key);
296 
305  bool keyIsFound(int &metadataCategory, string &key, string &value);
306 
311  friend std::ostream &operator<<(std::ostream &out, PDBCatalog &catalog);
312 
316  PDBLoggerPtr getLogger();
317 
322  map<string, CatalogUserTypeMetadata> getUserDefinedTypesList();
323 
327  void printsAllCatalogMetadata(
328  std::string &outputString,
329  std::string &errMsg);
330 
334  void listRegisteredDatabases(
335  std::string &outputString,
336  std::string &errMsg);
337 
341  void listRegisteredSetsForADatabase(
342  std::string databaseName,
343  std::string &outputString,
344  std::string &errMsg);
345 
349  void listNodesInCluster(
350  std::string &outputString,
351  std::string &errMsg);
352 
356  void listUserDefinedTypes(
357  std::string &outputString,
358  std::string &errMsg);
359 
364  bool retrievesDynamicLibrary(
365  string fileName,
366  string tableName,
367  Handle<CatalogUserTypeMetadata> &returnedItem,
368  string &returnedSoLibrary,
369  string &errorName);
370 
378  void getListOfDatabases(
379  Handle<Vector<CatalogDatabaseMetadata>> &databasesInCatalog,
380  const string &key);
381 
389  void getListOfSets(
390  Handle<Vector<CatalogSetMetadata>> &setsInCatalog,
391  const string &key);
392 
401  void getListOfNodes(Handle<Vector<CatalogNodeMetadata>> &nodesInCatalog,
402  const string &key);
403 
407  void closeSQLiteHandler();
408 
409 private:
413  string getMapsPDBOjbect2SQLiteTable(int typeOfObject);
414 
418  void loadsMetadataIntoMemory();
419 
423  pthread_mutex_t registerMetadataMutex;
424 
429 
434 
438  sqlite3 *sqliteDBHandler = NULL;
439 
443  vector<CatalogDatabaseMetadata> dbList;
444 
450 
455  multimap<string, CatalogUserTypeMetadata> mapUsersInCluster;
456 
461  map<string, int16_t> mapTypeNameToTypeID;
462 
467  map<int16_t, string> mapTypeIdToTypeName;
468 
472  map<string, CatalogNodeMetadata> registeredNodes;
473 
479 
483  map<string, CatalogSetMetadata> registeredSets;
484 
490 
494  map<string, CatalogDatabaseMetadata> registeredDatabases;
495 
501 
505  map<string, CatalogUserTypeMetadata> registeredUserDefinedTypes;
506 
512 
519 
524  string uriPath;
525 
530 
536 
541  string tempPath;
542 
547  bool catalogSqlQuery(string statement);
548 
552  bool catalogSqlStep(sqlite3_stmt *stmt, string &errorMsg);
553 
558  int createsTempPath();
559 
563  void setUriPath(string thePath) { uriPath = thePath; }
564 
569  void deleteTempSoFiles(string filePath);
570 
575  map<int, string> mapsPDBOjbect2SQLiteTable;
576 
583 };
584 
585 #endif /* PDB_CATALOG_H_ */
string catalogRootPath
Definition: PDBCatalog.h:529
string catalogFilename
Definition: PDBCatalog.h:535
Handle< Vector< CatalogSetMetadata > > registeredSetsMetadata
Definition: PDBCatalog.h:489
Handle< Vector< CatalogUserTypeMetadata > > registeredUserDefinedTypesMetadata
Definition: PDBCatalog.h:511
Handle< pdb::Vector< Handle< CatalogUserTypeMetadata > > > listUsersInCluster
Definition: PDBCatalog.h:449
map< string, CatalogUserTypeMetadata > registeredUserDefinedTypes
Definition: PDBCatalog.h:505
Handle< Vector< CatalogDatabaseMetadata > > registeredDatabasesMetadata
Definition: PDBCatalog.h:500
map< string, CatalogSetMetadata > registeredSets
Definition: PDBCatalog.h:483
void setUriPath(string thePath)
Definition: PDBCatalog.h:563
multimap< string, CatalogUserTypeMetadata > mapUsersInCluster
Definition: PDBCatalog.h:455
string catalogVersion
Definition: PDBCatalog.h:428
map< int16_t, string > mapTypeIdToTypeName
Definition: PDBCatalog.h:467
map< string, CatalogNodeMetadata > registeredNodes
Definition: PDBCatalog.h:472
Handle< Map< String, Handle< Vector< Object > > > > catalogContents
Definition: PDBCatalog.h:518
Handle< Vector< CatalogNodeMetadata > > registeredNodesMetadata
Definition: PDBCatalog.h:478
pthread_mutex_t registerMetadataMutex
Definition: PDBCatalog.h:423
shared_ptr< PDBCatalog > PDBCatalogPtr
Definition: PDBCatalog.h:77
map< string, CatalogDatabaseMetadata > registeredDatabases
Definition: PDBCatalog.h:494
std::ostream & operator<<(std::ostream &out, PDBCatalog &catalog)
Definition: PDBCatalog.cc:1179
PDBLoggerPtr logger
Definition: PDBCatalog.h:433
map< string, int16_t > mapTypeNameToTypeID
Definition: PDBCatalog.h:461
string tempPath
Definition: PDBCatalog.h:541
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
map< int, string > mapsPDBOjbect2SQLiteTable
Definition: PDBCatalog.h:575
map< int, string > mapsPDBArrayOjbect2SQLiteTable
Definition: PDBCatalog.h:582
string uriPath
Definition: PDBCatalog.h:524
vector< CatalogDatabaseMetadata > dbList
Definition: PDBCatalog.h:443