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
CatalogStandardDatabaseMetadata.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 /*
19  * CatalogStandardDatabaseMetadata.cc
20  *
21  */
22 
24 
25 using namespace std;
26 
27 // This class serves to store information about the databases in a given
28 // instance of PDB
29 // and provide methods for maintaining their associated metadata.
30 // Clients of this class will access this information using a handler to the
31 // catalog.
32 
34 
36  string dbIdIn, string dbNameIn, string userCreatorIn, string createdOnIn,
37  string lastModifiedIn)
38  : dbId(dbIdIn), dbName(dbNameIn), userCreator(userCreatorIn),
39  createdOn(createdOnIn), lastModified(lastModifiedIn) {}
40 
42  const CatalogStandardDatabaseMetadata &pdbDatabaseToCopy) {
43  dbId = pdbDatabaseToCopy.dbId;
44  dbName = pdbDatabaseToCopy.dbName;
45  userCreator = pdbDatabaseToCopy.userCreator;
46  createdOn = pdbDatabaseToCopy.createdOn;
47  lastModified = pdbDatabaseToCopy.lastModified;
48  listOfNodes = pdbDatabaseToCopy.listOfNodes;
49  listOfSets = pdbDatabaseToCopy.listOfSets;
50  listOfTypes = pdbDatabaseToCopy.listOfTypes;
51  setsInDB = pdbDatabaseToCopy.setsInDB;
52  nodesInDB = pdbDatabaseToCopy.nodesInDB;
53 }
54 
55 void CatalogStandardDatabaseMetadata::setValues(string dbIdIn, string dbNameIn,
56  string userCreatorIn,
57  string createdOnIn,
58  string lastModifiedIn) {
59  dbId = dbIdIn;
60  dbName = dbNameIn;
61  userCreator = userCreatorIn;
62  createdOn = createdOnIn;
63  lastModified = lastModifiedIn;
64 }
65 
67 
69  CatalogStandardPermissionsMetadata &permissionsIn) {
70  listOfPermissions.push_back(permissionsIn);
71 }
72 
74  PDB_COUT << "Adding node " << nodeIn.c_str() << endl;
75  listOfNodes.push_back(nodeIn);
76 }
77 
79  PDB_COUT << "Adding node " << setIn.c_str() << endl;
80  listOfSets.push_back(setIn);
81 }
82 
84  string &nodeIP) {
85  PDB_COUT << "first: " << setName.c_str()
86  << " push_back node: " << nodeIP.c_str();
87  setsInDB[setName].push_back(nodeIP);
88 }
89 
91  string &setName) {
92  PDB_COUT << "first: " << nodeIP.c_str()
93  << " push_back set: " << setName.c_str();
94  nodesInDB[nodeIP].push_back(setName);
95 }
96 
98  listOfTypes.push_back(typeIn);
99 }
100 
102  vector<string> &newList) {
103  listOfSets = newList;
104 }
105 
107  vector<string> &newList) {
108  listOfNodes = newList;
109 }
110 
112  map<string, vector<string>> &newMap) {
113  setsInDB = newMap;
114 }
115 
117  map<string, vector<string>> &newMap) {
118  nodesInDB = newMap;
119 }
120 
127  deleteSetFromSetList(setName);
128  deleteSetFromSetMap(setName);
129  deleteSetFromNodeMap(setName);
130 }
131 
133  string set) {
134  deleteNodeFromSingleSet(node, set);
135  deleteSetFromSingleNode(set, node);
136 }
137 
139  string &setName) {
140  // creates a temp vector
141  vector<string> tempListOfNodes;
142 
143  for (int i = 0; i < getListOfNodes().size(); i++) {
144  string itemValue = getListOfNodes()[i];
145  if (itemValue != setName) {
146  tempListOfNodes.push_back(itemValue);
147  }
148  }
149  replaceListOfNodes(tempListOfNodes);
150 }
151 
153  return listOfNodes;
154 }
155 
157  return listOfSets;
158 }
159 
161  return listOfTypes;
162 }
163 
164 vector<CatalogStandardPermissionsMetadata>
166  return listOfPermissions;
167 }
168 
170 
172 
174 
176 
178 
180  return lastModified;
181 }
182 
184  dbName = itemKeyIn;
185 }
186 
187 void CatalogStandardDatabaseMetadata::setItemId(string &idIn) { dbId = idIn; }
188 
190  dbName = itemNameIn;
191 }
192 
193 map<string, vector<string>> CatalogStandardDatabaseMetadata::getSetsInDB() {
194  return setsInDB;
195 }
196 
197 map<string, vector<string>> CatalogStandardDatabaseMetadata::getNodesInDB() {
198  return nodesInDB;
199 }
200 
202  string output;
203  string spaces("");
204  output = " \nDB ";
205  output.append(getItemId().c_str()).append(":").append(getItemKey().c_str());
206 
207  int i = 0;
208  output.append("\n is stored in (")
209  .append(to_string(nodesInDB.size()))
210  .append(")nodes: [ ");
211 
212  for (auto &item : nodesInDB) {
213  if (i > 0)
214  output.append(", ").append(spaces).append(item.first);
215  else
216  output.append(item.first);
217  i++;
218  }
219 
220  output.append(" ]\n and has (")
221  .append(to_string(setsInDB.size()))
222  .append(")sets: [ ");
223  i = 0;
224 
225  for (auto &item : setsInDB) {
226  if (i > 0)
227  output.append(", ").append(spaces).append(item.first.c_str());
228  else
229  output.append(item.first.c_str());
230  i++;
231  }
232  output.append(" ]");
233 
234  for (auto &item : setsInDB) {
235  output.append("\n * Set: ")
236  .append(item.first.c_str())
237  .append(" is stored in (")
238  .append(to_string(item.second.size()))
239  .append(")nodes: [ ");
240  for (int i = 0; i < item.second.size(); i++) {
241  if (i > 0)
242  output.append(", ").append(spaces).append(item.second[i].c_str());
243  else
244  output.append(item.second[i].c_str());
245  }
246  output.append(" ]");
247  }
248 
249  return output;
250 }
251 
253  // creates a temp vector
254  vector<string> tempListOfSets;
255  for (int i = 0; i < getListOfSets().size(); i++) {
256  string itemValue = getListOfSets()[i];
257  if (itemValue != setName) {
258  tempListOfSets.push_back(itemValue);
259  }
260  }
261  replaceListOfSets(tempListOfSets);
262 }
263 
265  // creates a temp vector
266  map<string, vector<string>> tempSetsInDB;
267  for (auto &a : getSetsInDB()) {
268  if (a.first != setName) {
269  tempSetsInDB[a.first] = a.second;
270  }
271  }
272  replaceMapOfSets(tempSetsInDB);
273 }
274 
276  string &setName) {
277  getSetsInDB().erase(node);
278 }
279 
281  string &node) {
282  getNodesInDB().erase(setName);
283 }
284 
286  map<string, vector<string>> tempNodesInDB;
287  for (const auto &setsInNode : nodesInDB) {
288  auto node = setsInNode.first;
289  auto sets = setsInNode.second;
290  auto newSetsInNode = tempNodesInDB[node];
291  for (int i = 0; i < sets.size(); i++) {
292  if (sets[i] != setName) {
293  newSetsInNode.push_back(sets[i]);
294  }
295  }
296  }
297  replaceMapOfNodes(tempNodesInDB);
298 }
vector< CatalogStandardPermissionsMetadata > getListOfPermissions()
void addNodeToMap(string &nodeIP, string &setName)
vector< CatalogStandardPermissionsMetadata > listOfPermissions
map< string, vector< string > > nodesInDB
map< string, vector< string > > setsInDB
void replaceMapOfNodes(map< string, vector< string >> &newMap)
void deleteNodeFromSingleSet(string &node, string &setName)
void replaceListOfNodes(vector< string > &newList)
void replaceListOfSets(vector< string > &newList)
void deleteSetFromSingleNode(string &setName, string &node)
#define PDB_COUT
Definition: PDBDebug.h:31
map< string, vector< string > > getNodesInDB()
void removeNodeFromSet(string node, string set)
void addSetToMap(string &setName, string &nodeIP)
void setValues(string dbIdIn, string dbNameIn, string userCreatorIn, string createdOnIn, string lastModifiedIn)
void deleteNodeFromMap(string &nodeIP, string &setName)
void addPermission(CatalogStandardPermissionsMetadata &permissionsIn)
map< string, vector< string > > getSetsInDB()
void replaceMapOfSets(map< string, vector< string >> &newMap)