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
PDBDistributionManager.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  * PDBDistributionManager.h
20 
21  *
22  * Created on: Nov, 2015
23  * Author: Kia Teymourian
24  */
25 
26 #ifndef PDB_DISTRIBUTION_MANAGER_H
27 #define PDB_DISTRIBUTION_MANAGER_H
28 
29 
30 #include <string>
31 #include <iostream>
32 #include <unordered_map>
33 #include <map>
34 
35 #include <cassert>
36 
37 
38 #include "PDBLogger.h"
39 #include "Ack.h"
40 #include "PDBString.h"
41 #include "PDBVector.h"
42 
43 
44 namespace pdb {
45 
51 class PDBDistributionManager;
52 using namespace std;
53 
54 // A smart pointer for PDBDistributionManager
55 typedef shared_ptr<PDBDistributionManager> PDBDistributionManagerPtr;
56 
57 
59 
60 public:
62 
64 
65  // This method adds or update a node.
66  // If the node is seen for the first time it adds it to memory with the current time and returns
67  // 0
68  // If the node already exists it updates the timestamp and returns 1.
69  bool addOrUpdateNodes(PDBLoggerPtr myLoggerIn, string& nodeID);
70 
71  // TODO: return the one of the nodes from the list.
72  string getSingleNode();
73 
74  // Query executer nodes have to ask for permission to run queries on the cluster before they run
75  // it.
76  // A Query ID is a global unique identifier for the query.
77  string getPermitToRunQuery(PDBLoggerPtr myLoggerIn);
78 
79  // When the query executer is done with running query it has to notify Distribution Manager.
80  // It has to send the same queryID and receive an Ack.
81  int queryIsDone(string& queryID, PDBLoggerPtr myLoggerIn);
82 
83  unordered_map<string, long>& getUpNodesOfCluster() {
84  return nodesOfCluster;
85  }
86 
87  int getNoOfNodes() {
88  return nodesOfCluster.size();
89  }
90 
91  void setNodesOfCluster(const unordered_map<string, long>& nodesOfCluster) {
92  this->nodesOfCluster = nodesOfCluster;
93  }
94 
96  return queryPlannerPlace;
97  }
98 
99  void setQueryPlannerPlace(string& queryPlannerPlace) {
100  this->queryPlannerPlace = queryPlannerPlace;
101  }
102 
103 private:
104  // stores the heart beat data that we are collecting form all worker nodes in the cluster.
105  unordered_map<string, long> nodesOfCluster;
106 
107  // This is a counter to count heart beat messages and active the cleaning process after we got
108  // specific number of messages.
109  // This is just to do not start the cleaning process immediately after cluster bootstrapping.
111 
112  // it stores the location of the query planner in the cluster.
114 
115  // stores currently running queries and their start time.
116  // we store the start time of query execution to be able to clean the list when one of the
117  // executors goes down and does not response any more.
118  map<string, long> runningQueries;
119 
121  pthread_mutex_t writeLock;
122 };
123 }
124 #endif /* DISTRIBUTION_HEADERS_PDBDISTRIBUTIONMANAGER_H_ */
unordered_map< string, long > & getUpNodesOfCluster()
void setNodesOfCluster(const unordered_map< string, long > &nodesOfCluster)
void setQueryPlannerPlace(string &queryPlannerPlace)
unordered_map< string, long > nodesOfCluster
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
shared_ptr< PDBDistributionManager > PDBDistributionManagerPtr