zclllyybb commented on code in PR #35595:
URL: https://github.com/apache/doris/pull/35595#discussion_r1619335540


##########
be/src/pipeline/pipeline_tracing.cpp:
##########
@@ -105,7 +123,7 @@ void PipelineTracerContext::_dump_query(TUniqueId query_id) 
{
     auto writer = io::LocalFileWriter {path, fd};
 
     ScheduleRecord record;
-    while (_datas[query_id].try_dequeue(record)) {
+    while ((*map_ptr)[QueryID {query_id}]->try_dequeue(record)) {

Review Comment:
   maybe here we should add some comment to let people know it's thread-safe by 
copy-and-swap for any possible modification.



##########
be/src/pipeline/pipeline_tracing.cpp:
##########
@@ -39,12 +39,31 @@ void PipelineTracerContext::record(ScheduleRecord record) {
     if (_dump_type == RecordType::None) [[unlikely]] {
         return;
     }
-    if (_datas.contains(record.query_id)) {
-        _datas[record.query_id].enqueue(record);
+
+    auto map_ptr = std::atomic_load_explicit(&_data, 
std::memory_order_relaxed);
+    auto it = map_ptr->find({record.query_id});
+    if (it != map_ptr->end()) {
+        it->second->enqueue(record);
     } else {
-        // dump per timeslice may cause this. lead perv records broken. that's 
acceptable
-        std::unique_lock<std::mutex> l(_data_lock); // add new item, may rehash
-        _datas[record.query_id].enqueue(record);
+        _update([&](QueryTracesMap& new_map) {
+            if (!new_map.contains({record.query_id})) {
+                new_map[{record.query_id}].reset(new OneQueryTraces());
+            }
+            new_map[{record.query_id}]->enqueue(record);
+        });
+    }
+}
+
+void PipelineTracerContext::_update(std::function<void(QueryTracesMap&)>&& 
handler) {
+    auto map_ptr = std::atomic_load_explicit(&_data, 
std::memory_order_relaxed);

Review Comment:
   do not use these atomic APIs for `std::shared_ptr`. they are deprecated in 
C++20 and will be removed in C++26. use `std::atomic<shared_ptr>` instead.



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