bookkeeper icon indicating copy to clipboard operation
bookkeeper copied to clipboard

Prevent race in SingleDirectoryDbLedgerStorage metrics collection

Open michaeljmarshall opened this issue 1 year ago • 2 comments

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.

michaeljmarshall avatar Apr 22 '24 20:04 michaeljmarshall

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

hezhangjian avatar Apr 26 '24 06:04 hezhangjian

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

We're in the constructor. I don't think anything could have access to trigger the swap yet.

michaeljmarshall avatar Jul 17 '24 18:07 michaeljmarshall