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

Prevent race in SingleDirectoryDbLedgerStorage metrics collection #4307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

michaeljmarshall
Copy link
Member

Motivation

We swap the writeCache and the writeCacheBeingFlushed on flush. Therefore, it is not safe to call each to get the size/count metrics. Instead, if we expose the underlying accumulators, we can safely get the stats.

Changes

Expose the AtomicLong and the LongAdder objects in the WriteCache for safer metrics reporting.

@shoothzj
Copy link
Member

How do you guarantee they won't swap during L214-L217? It seems problem is not solved.

Copy link
Contributor

@dlg99 dlg99 left a comment

Choose a reason for hiding this comment

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

See my comment.
Overall, I don't think there is a problem.

Comment on lines +214 to +218
final AtomicLong finalWriteCacheSize = writeCache.cacheSize;
final AtomicLong finalWriteCacheBeingFlushedSize = writeCacheBeingFlushed.cacheSize;
final LongAdder finalWriteCacheCounter = writeCache.cacheCount;
final LongAdder finalWriteCacheBeingFlushedCounter = writeCacheBeingFlushed.cacheCount;

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is right.
Lambdas in the DbLedgerStorageStats() constructor used to provide a way to access to metrics of current writeCache/.. instance.
With this change it will provide metrics for the first used instance, one before the very first swap, so the stats will stop changing after the cache swaps couple of times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants