Skip to content

Metrics: Revert added locking and annotations - #13567

Merged
moonchen merged 1 commit into
apache:masterfrom
moonchen:revert-metrics-thread-safety-locks
Aug 19, 2026
Merged

Metrics: Revert added locking and annotations#13567
moonchen merged 1 commit into
apache:masterfrom
moonchen:revert-metrics-thread-safety-locks

Conversation

@moonchen

Copy link
Copy Markdown
Contributor

The locking that the thread safety annotations required on the ts::Metrics::Storage read paths introduces too much of a performance regression. Revert it for now, until a better solution can be found.

The thread safety analysis infrastructure and its use in SSLOriginSessionCache are unaffected.

The locking that the thread safety annotations required on the
ts::Metrics::Storage read paths introduces too much of a performance
regression.  Revert it for now, until a better solution can be found.

The thread safety analysis infrastructure and its use in
SSLOriginSessionCache are unaffected.
Copilot AI lite review requested due to automatic review settings August 18, 2026 22:41
@moonchen moonchen added the Backport Marked for backport for an LTS patch release label Aug 18, 2026
@moonchen moonchen self-assigned this Aug 18, 2026
@moonchen moonchen added Regression Revert Metrics Performance and removed Backport Marked for backport for an LTS patch release labels Aug 18, 2026
@moonchen
moonchen requested a review from cmcfarlen August 18, 2026 22:44
@moonchen moonchen added this to the 11.0.0 milestone Aug 18, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the ts::Metrics::Storage implementation to roll back previously-added thread-safety annotations and associated locking on some read paths, aiming to avoid a performance regression in metric reads while keeping the rest of the thread-safety infrastructure (e.g., SSLOriginSessionCache) unchanged.

Changes:

  • Replaced ts::mutex / ts::lock_guard usage in Metrics::Storage with std::mutex / std::lock_guard.
  • Removed several thread-safety annotations (TS_GUARDED_BY, TS_REQUIRES, TS_NO_THREAD_SAFETY_ANALYSIS) from Metrics::Storage.
  • Removed locking in some Storage read helpers (lookup(id, ...), name(id), and valid(id)), and adjusted rename() locking.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/tsutil/Metrics.cc Adjusts locking strategy around Storage operations, including removing locks from some ID-based read paths.
include/tsutil/Metrics.h Removes thread-safety annotations and switches Storage to std::mutex, including changing/relaxing locking in small inline helpers.
Suppressed comments (2)

src/tsutil/Metrics.cc:145

  • Storage::name() reads _cur_blob, _cur_off, and _blobs[...] without synchronization, but those are updated under _mutex in create() / createSpan(). This introduces a data race and can lead to returning the wrong name or dereferencing a partially-published blob under concurrent metric creation.
Metrics::Storage::name(Metrics::IdType id) const
{
  auto [blob_ix, offset]         = _splitID(id);
  Metrics::NamesAndAtomics *blob = _blobs[blob_ix].get();

src/tsutil/Metrics.cc:200

  • Storage::rename() acquires _mutex only after reading _blobs[...], _cur_blob, _cur_off, and taking a reference to the stored name. With concurrent create() / createSpan() this is a data race, and even without it the late lock undermines the function’s own correctness guarantees. Take the lock before accessing any shared state and remove the later lock_guard.
  std::string    &cur = std::get<0>(std::get<0>(*blob)[offset]);
  std::lock_guard lock(_mutex);


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/tsutil/Metrics.cc
Comment on lines 95 to 99
Metrics::Storage::lookup(Metrics::IdType id, std::string_view *out_name, Metrics::MetricType *out_type) const
{
ts::lock_guard lock(_mutex);
auto [blob_ix, offset] = _splitID(id);
Metrics::NamesAndAtomics *blob = _blobs[blob_ix].get();

Comment thread include/tsutil/Metrics.h
Comment on lines 345 to 349
valid(IdType id) const
{
auto [blob, entry] = _splitID(id);

ts::lock_guard lock(_mutex);
return (id >= 0 && ((blob < _cur_blob && entry < MAX_SIZE) || (blob == _cur_blob && entry <= _cur_off)));

@cmcfarlen cmcfarlen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! I know copilot is not happy about it, but we can address the "data race" with atomics in a followup PR.

@moonchen
moonchen merged commit 0201367 into apache:master Aug 19, 2026
15 checks passed
@github-project-automation github-project-automation Bot moved this to For v10.2.0 in ATS v10.2.x Aug 19, 2026
@cmcfarlen cmcfarlen moved this from For v10.2.0 to Picked v10.2.1 in ATS v10.2.x Aug 19, 2026
@cmcfarlen cmcfarlen modified the milestones: 11.0.0, 10.2.1 Aug 19, 2026
@cmcfarlen

Copy link
Copy Markdown
Contributor

Cherry-picked to 10.2.x

cmcfarlen pushed a commit that referenced this pull request Aug 19, 2026
The locking that the thread safety annotations required on the
ts::Metrics::Storage read paths introduces too much of a performance
regression.  Revert it for now, until a better solution can be found.

The thread safety analysis infrastructure and its use in
SSLOriginSessionCache are unaffected.

(cherry picked from commit 0201367)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Picked v10.2.1

Development

Successfully merging this pull request may close these issues.

3 participants