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

fix: avoid acquiring lock during reading stats #4070

Merged
merged 3 commits into from
May 30, 2024

Conversation

WenyXu
Copy link
Member

@WenyXu WenyXu commented May 29, 2024

I hereby agree to the terms of the GreptimeDB CLA.

Refer to a related PR or issue link (optional)

What's changed and what's your intention?

This PR uses Arc<Atomicu64> to store the shared value instead of RwLock, to avoid acquiring lock during reading value.

The datanode will report the stats (like manifest usage) via heartbeat. Before sending the heartbeat to the metasrv, it collects all stats from the region server. While collecting disk_usage will invoke the manifest_usage method on the manifest_manager, this operation is required to acquire the read lock of the manifest_manager.

       // read manifest_usage
       let manifest_usage = self
            .manifest_ctx
            .manifest_manager
            .read()
            .await
            .manifest_usage();
      let mut manager = self.manifest_manager.write().await;
      // update manifest
      // ..

However, acquiring a read lock will be blocked by the updating manifest operations, and the wait time may be as long as tens of seconds. This makes the datanode fail to send heartbeats in time, then all region leases on the datanodes will expire.

Checklist

  • I have written the necessary rustdoc comments.
  • I have added the necessary unit tests and integration tests.
  • This PR requires documentation updates.

@WenyXu WenyXu requested review from waynexia, v0y4g3r, evenyag and a team as code owners May 29, 2024 16:18
@github-actions github-actions bot added the docs-not-required This change does not impact docs. label May 29, 2024
@WenyXu WenyXu mentioned this pull request May 29, 2024
8 tasks
@killme2008
Copy link
Contributor

Good catch!

src/mito2/src/region.rs Outdated Show resolved Hide resolved
Copy link
Collaborator

@fengjiachun fengjiachun left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

codecov bot commented May 30, 2024

Codecov Report

Attention: Patch coverage is 96.05263% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 85.04%. Comparing base (6e9a9dc) to head (ee1b388).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4070      +/-   ##
==========================================
- Coverage   85.34%   85.04%   -0.31%     
==========================================
  Files         987      987              
  Lines      171485   172109     +624     
==========================================
+ Hits       146359   146371      +12     
- Misses      25126    25738     +612     

@discord9 discord9 added this pull request to the merge queue May 30, 2024
Merged via the queue into GreptimeTeam:main with commit eab309f May 30, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs-not-required This change does not impact docs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants