liaoxin01 commented on code in PR #56120:
URL: https://github.com/apache/doris/pull/56120#discussion_r2355811172


##########
be/src/runtime/load_stream.cpp:
##########
@@ -680,9 +681,25 @@ void LoadStream::_dispatch(StreamId id, const 
PStreamHeader& hdr, butil::IOBuf*
         std::vector<int64_t> success_tablet_ids;
         FailedTablets failed_tablets;
         std::vector<PTabletID> tablets_to_commit(hdr.tablets().begin(), 
hdr.tablets().end());
-        close(hdr.src_id(), tablets_to_commit, &success_tablet_ids, 
&failed_tablets);
+        bool all_closed =
+                close(hdr.src_id(), tablets_to_commit, &success_tablet_ids, 
&failed_tablets);
         _report_result(id, Status::OK(), success_tablet_ids, failed_tablets, 
true);
-        brpc::StreamClose(id);
+        std::lock_guard<bthread::Mutex> lock_guard(_lock);
+        // if incremental stream, we need to wait for all non-incremental 
streams to be closed
+        // before closing incremental streams. We need a fencing mechanism to 
avoid use after closing
+        // across different be.
+        if (hdr.has_num_incremental_streams() && hdr.num_incremental_streams() 
> 0) {
+            _closing_stream_ids.push_back(id);
+        } else {
+            brpc::StreamClose(id);
+        }
+
+        if (all_closed) {
+            for (auto& closing_id : _closing_stream_ids) {
+                brpc::StreamClose(closing_id);
+                _closing_stream_ids.clear();
+            }
+        }

Review Comment:
   ```suggestion
           if (all_closed) {
               for (auto& closing_id : _closing_stream_ids) {
                   brpc::StreamClose(closing_id);             
               }
               _closing_stream_ids.clear();
           }
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to