lh2debug commented on code in PR #3140:
URL: https://github.com/apache/brpc/pull/3140#discussion_r2522308829
##########
src/bthread/task_meta.h:
##########
@@ -43,10 +48,10 @@ struct ButexWaiter;
struct LocalStorage {
KeyTable* keytable;
void* assigned_data;
- void* rpcz_parent_span;
+ std::weak_ptr<brpc::Span> rpcz_parent_span;
Review Comment:
done
##########
src/brpc/span.h:
##########
@@ -181,11 +269,38 @@ friend class SpanDB;
// time2_us \s annotation2 <SEP>
// ...
std::string _info;
+ // Protects _info from concurrent modifications.
+ // Multiple threads may call Annotate() simultaneously (e.g., retry logic,
+ // network layer, user code via TRACEPRINTF), causing data corruption in
+ // string concatenation without synchronization.
+ mutable pthread_spinlock_t _info_spinlock;
+
+ std::weak_ptr<Span> _local_parent;
+ std::list<std::shared_ptr<Span>> _client_list;
+ // Protects _client_list from concurrent modifications.
+ // In some scenarios, multiple bthreads may simultaneously create child
spans
+ // (e.g.,raft leader parallel RPCs to followers) and push_back to parent's
_client_list.
+ // Also protects against concurrent iteration (e.g., CountClientSpans,
SpanDB::Index)
+ // while the list is being modified.
+ mutable pthread_spinlock_t _client_list_spinlock;
+};
+
+class SpanContainer : public bvar::Collected {
+public:
+ explicit SpanContainer(std::shared_ptr<Span> span) : _span(span) {}
Review Comment:
Okay, I'll change this later.
--
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]