Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: trace_events: fix race with metadata events #25235

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/tracing/agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,17 @@ void Agent::AppendTraceEvent(TraceObject* trace_event) {
id_writer.second->AppendTraceEvent(trace_event);
}

void Agent::AddMetadataEvent(std::unique_ptr<TraceObject> event) {
Mutex::ScopedLock lock(metadata_events_mutex_);
metadata_events_.push_back(std::move(event));
}

void Agent::Flush(bool blocking) {
for (const auto& event : metadata_events_)
AppendTraceEvent(event.get());
{
Mutex::ScopedLock lock(metadata_events_mutex_);
for (const auto& event : metadata_events_)
AppendTraceEvent(event.get());
}

for (const auto& id_writer : writers_)
id_writer.second->Flush(blocking);
Expand Down
6 changes: 3 additions & 3 deletions src/tracing/agent.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ class Agent {
// Writes to all writers registered through AddClient().
void AppendTraceEvent(TraceObject* trace_event);

void AddMetadataEvent(std::unique_ptr<TraceObject> event) {
metadata_events_.push_back(std::move(event));
}
void AddMetadataEvent(std::unique_ptr<TraceObject> event);
// Flushes all writers registered through AddClient().
void Flush(bool blocking);

Expand Down Expand Up @@ -145,6 +143,8 @@ class Agent {
ConditionVariable initialize_writer_condvar_;
uv_async_t initialize_writer_async_;
std::set<AsyncTraceWriter*> to_be_initialized_;

Mutex metadata_events_mutex_;
std::list<std::unique_ptr<TraceObject>> metadata_events_;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a dumb question, but when does this list get cleared? Does it ever?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't and shouldn't really. These need to be cached and re-emitted whenever the trace file rolls over to a new file. There should only ever be a limited number of these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Metadata events are meta information about the process and environment rather than being events at particular points in time. In production scenarios, the trace events may be streamed across the network where only a trailing buffer is retained. The idea is that these metadata events should be periodically remitted to ensure that they are still available even if the start of the log is truncated.

};

Expand Down