Skip to content

Commit

Permalink
Added comments
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Alfonsi <petealft@amazon.com>
  • Loading branch information
Peter Alfonsi committed Apr 8, 2024
1 parent a4e867d commit c81254f
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
* A class caches use to internally keep track of their stats across multiple dimensions.
* Not intended to be exposed outside the cache; for this, use statsHolder.getCacheStats() to create an immutable
* copy of the current state of the stats.
* Currently, in the IRC, the stats tracked in a StatsHolder will not appear for empty shards that have had no cache
* operations done on them yet. This might be changed in the future, by exposing a method to add empty nodes to the
* tree in StatsHolder in the ICache interface.
*
* @opensearch.experimental
*/
Expand All @@ -30,6 +33,8 @@ public class StatsHolder {
// A tree structure based on dimension values, which stores stats values in its leaf nodes.
// Non-leaf nodes have stats matching the sum of their children.
private final DimensionNode statsRoot;
// To avoid sync problems, obtain a lock before creating or removing nodes in the stats tree.
// No lock is needed to edit stats on existing nodes.
private final Lock lock = new ReentrantLock();

public StatsHolder(List<String> dimensionNames) {
Expand Down Expand Up @@ -172,11 +177,10 @@ private MDCSDimensionNode createMatchingMDCSDimensionNode(DimensionNode node) {
}

public void removeDimensions(List<String> dimensionValues) {
assert dimensionValues.size() == dimensionNames.size() : "Must specify a value for every dimension when removing from StatsHolder";
// As we are removing nodes from the tree, obtain the lock
lock.lock();
try {
assert dimensionValues.size() == dimensionNames.size()
: "Must specify a value for every dimension when removing from StatsHolder";
removeDimensionsHelper(dimensionValues, statsRoot, 0);
} finally {
lock.unlock();
Expand Down

0 comments on commit c81254f

Please sign in to comment.