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
Partitioner.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 #ifndef PARTITIONER_CC
20 #define PARTITIONER_CC
21 
22 
23 
24 namespace pdb {
25 
26 template<class KeyClass, class ValueClass>
27 Partitioner<KeyClass, ValueClass> :: Partitioner (std::pair<std::string, std::string> inputDatabaseAndSet,
28  std::pair<std::string, std::string> outputDatabaseAndSet) {
29 
30  this->inputDatabaseAndSet = inputDatabaseAndSet;
31  this->outputDatabaseAndSet = outputDatabaseAndSet;
32 }
33 
34 template<class KeyClass, class ValueClass>
36  std::shared_ptr<pdb::QueryClient> queryClient,
38 
39  /* Step 1. to check whether the input set and output set exists, if not we return false
40  * TODO: we do not have such function at master yet
41  */
42 
43  /* Step 2. to check whether partitionComp is null, if yes, we return false */
44  if (partitionComp == nullptr) {
45  errMsg = "Error: null partitionComp";
46  return false;
47  }
48 
49  /* Step 3. to check whether queryClient is null, if yes, we return false */
50  if (queryClient == nullptr) {
51  errMsg = "Error: null queryClient";
52  return false;
53  }
54 
55  const UseTemporaryAllocationBlock myBlock{256 * 1024 * 1024};
56 
57  /* Step 4. to deep copy the partition computation */
59  = deepCopyToCurrentAllocationBlock<PartitionComp<KeyClass, ValueClass>>(partitionComp);
60 
61  curPartitionComp->setOutput(outputDatabaseAndSet.first, outputDatabaseAndSet.second);
62 
63  /* Step 5. to create a scanner computation */
65  = makeObject<ScanUserSet<ValueClass>> (inputDatabaseAndSet.first, inputDatabaseAndSet.second);
66 
67  /* Step 6. to compose a query graph */
68  curPartitionComp->setInput(scanner);
69 
70  /* Step 8. to get the tcap string */
71  queryClient->setQueryGraph(curPartitionComp);
72  std::vector<Handle<Computation>> computations;
73  std::string tcapString = queryClient->getTCAP(computations);
74  std::cout << "number of computations is " << computations.size() << std::endl;
75  /* Step 9. to register the input-output mapping as well as the tcap string with StatsDB */
76  queryClient->registerReplica(inputDatabaseAndSet,
77  outputDatabaseAndSet,
78  curPartitionComp->getNumPartitions(),
79  curPartitionComp->getNumNodes(),
80  "Partition",
81  tcapString,
82  computations);
83  /* Step 10. to execute the partition computation */
84  return queryClient->executeComputations(errMsg, tcapString, computations);
85 
86 }
87 
88 template<class KeyClass, class ValueClass>
90  std::shared_ptr<pdb::QueryClient> queryClient,
92 
93  /* Step 1. to check whether the input set and output set exists, if not we return false
94  * TODO: we do not have such function at master yet
95  */
96 
97  /* Step 2. to check whether partitionComp is null, if yes, we return false */
98  if (partitionComp == nullptr) {
99  errMsg = "Error: null partitionComp";
100  return false;
101  }
102 
103  /* Step 3. to check whether queryClient is null, if yes, we return false */
104  if (queryClient == nullptr) {
105  errMsg = "Error: null queryClient";
106  return false;
107  }
108 
109  const UseTemporaryAllocationBlock myBlock{256 * 1024 * 1024};
110 
111  /* Step 4. to deep copy the partition computation */
113  = deepCopyToCurrentAllocationBlock<PartitionTransformationComp<KeyClass, ValueClass>>(partitionComp);
114 
115  /* Step 5. to create a scanner computation */
117  = makeObject<ScanUserSet<ValueClass>> (inputDatabaseAndSet.first, inputDatabaseAndSet.second);
118 
119  /* Step 6. to create a writer computation FROM KeyClass */
121  = makeObject<WriteUserSet<KeyClass>> (outputDatabaseAndSet.first, outputDatabaseAndSet.second);
122 
123  /* Step 7. to compose a query graph */
124  curPartitionComp->setInput(scanner);
125  writer->setInput(curPartitionComp);
126 
127  /* Step 8. to get the tcap string */
128  queryClient->setQueryGraph(writer);
129  std::vector<Handle<Computation>> computations;
130  std::string tcapString = queryClient->getTCAP(computations);
131 
132  /* Step 9. to register the input-output mapping as well as the tcap string with StatsDB */
133  queryClient->registerReplica(inputDatabaseAndSet,
134  outputDatabaseAndSet,
135  curPartitionComp->getNumPartitions(),
136  curPartitionComp->getNumNodes(),
137  "Transformation",
138  tcapString,
139  computations);
140 
141  /* Step 10. to execute the partition computation */
142  return queryClient->executeComputations(errMsg, tcapString, computations);
143 
144 }
145 
146 
147 
148 
149 }
150 
151 #endif
Partitioner(std::pair< std::string, std::string > inputDatabaseAndSet, std::pair< std::string, std::string > outputDatabaseAndSet)
Definition: Partitioner.cc:27
bool partitionWithTransformation(std::string &errMsg, std::shared_ptr< pdb::QueryClient > queryClient, Handle< PartitionTransformationComp< KeyClass, ValueClass >> partitionComp)
Definition: Partitioner.cc:89
bool partition(std::string &errMsg, std::shared_ptr< pdb::QueryClient > queryClient, Handle< PartitionComp< KeyClass, ValueClass >> partitionComp)
Definition: Partitioner.cc:35