dnrusakov commented on a change in pull request #3282: WIP STREAMCOMP-2724: 
Stream Manager migrated to mainly use smart pointers instead of a manual memory 
management
URL: https://github.com/apache/incubator-heron/pull/3282#discussion_r291705974
 
 

 ##########
 File path: heron/instance/src/cpp/slave/slave.cpp
 ##########
 @@ -79,19 +80,22 @@ void Slave::InternalStart() {
   eventLoop_->loop();
 }
 
-void Slave::HandleGatewayData(google::protobuf::Message* msg) {
+void Slave::HandleGatewayData(unique_ptr<google::protobuf::Message> msg) {
   if (msg->GetTypeName() == pplan_typename_) {
     LOG(INFO) << "Slave Received a new pplan message from Gateway";
-    auto pplan = static_cast<proto::system::PhysicalPlan*>(msg);
-    HandleNewPhysicalPlan(pplan);
+    auto pplan = unique_ptr<proto::system::PhysicalPlan>(
+            static_cast<proto::system::PhysicalPlan*>(msg.release()));
+    HandleNewPhysicalPlan(std::move(pplan));
   } else {
-    auto tupleSet = static_cast<proto::system::HeronTupleSet2*>(msg);
-    HandleStMgrTuples(tupleSet);
+    auto tupleSet = unique_ptr<proto::system::HeronTupleSet2>(
+            static_cast<proto::system::HeronTupleSet2*>(msg.release()));
+    HandleStMgrTuples(std::move(tupleSet));
   }
 }
 
-void Slave::HandleNewPhysicalPlan(proto::system::PhysicalPlan* pplan) {
-  taskContext_->newPhysicalPlan(pplan);
+void Slave::HandleNewPhysicalPlan(unique_ptr<proto::system::PhysicalPlan> 
pplan) {
+  std::shared_ptr<proto::system::PhysicalPlan> newPplan = std::move(pplan);
 
 Review comment:
   > why convert unique to shared here? 
   
   In the line 98 we call 
```TaskContextImpl::newPhysicalPlan(std::shared_ptr<proto::system::PhysicalPlan>
 pplan)``` which takes the shared pointer and then store it in the field of the 
class (`TaskContextImpl`).
   Then `HandleNewPhysicalPlan` (after call of 
`TaskContextImpl::newPhysicalPlan(newPplan)`), the handler 
(`HandleNewPhysicalPlan`) proceeds to use `pplan` down the road, - that means 
we can not move `pplan` into `TaskContextImpl::newPhysicalPlan(...)` if it 
would be a `unique_ptr`.
   
   > I am wondering which function was responsible for deleting this pointer?
   
   Previously it was handled by destructor of `TaskContextImpl` class. Now 
`TaskContextImpl` stores `pplan` as a smart pointer and the memory will be 
freed automatically as soon as the instance of `TaskContextImpl` destructed.
   
   > Or in another word, is unique + weak better here? 
   
   `weak_ptr` can be obtained only from `shared_ptr`, but not from `unique_ptr`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to