-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Peter Alfonsi <[email protected]>
- Loading branch information
Peter Alfonsi
committed
Apr 16, 2024
1 parent
00df37e
commit 5ba6e47
Showing
3 changed files
with
121 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
server/src/main/java/org/opensearch/common/cache/stats/CacheStatsHolderInterface.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.cache.stats; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* An abstract class extended by CacheStatsHolder and DummyCacheStatsHolder. | ||
* Can be removed once the pluggable caches feature is no longer experimental. | ||
*/ | ||
public interface CacheStatsHolderInterface { | ||
void incrementHits(List<String> dimensionValues); | ||
|
||
void incrementMisses(List<String> dimensionValues); | ||
|
||
void incrementEvictions(List<String> dimensionValues); | ||
|
||
void incrementSizeInBytes(List<String> dimensionValues, long amountBytes); | ||
|
||
void decrementSizeInBytes(List<String> dimensionValues, long amountBytes); | ||
|
||
void incrementEntries(List<String> dimensionValues); | ||
|
||
void decrementEntries(List<String> dimensionValues); | ||
|
||
void reset(); | ||
|
||
long count(); | ||
|
||
void removeDimensions(List<String> dimensionValues); | ||
|
||
ImmutableCacheStatsHolder getImmutableCacheStatsHolder(); | ||
} |
70 changes: 70 additions & 0 deletions
70
server/src/main/java/org/opensearch/common/cache/stats/DummyCacheStatsHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.cache.stats; | ||
|
||
import org.opensearch.common.metrics.CounterMetric; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A dummy version of CacheStatsHolder, which cache implementations use when FeatureFlags.PLUGGABLE_CACHES is false. | ||
* Will be removed once pluggable caches is no longer an experimental feature. | ||
* Returns all-zero stats when calling getImmutableCacheStatsHolder(). Does keep track of entries for use in ICache.count(). | ||
*/ | ||
public class DummyCacheStatsHolder implements CacheStatsHolderInterface { | ||
private final CounterMetric entries; | ||
private final List<String> dimensionNames; | ||
|
||
public DummyCacheStatsHolder(List<String> dimensionNames) { | ||
this.dimensionNames = dimensionNames; | ||
this.entries = new CounterMetric(); | ||
} | ||
|
||
@Override | ||
public void incrementHits(List<String> dimensionValues) {} | ||
|
||
@Override | ||
public void incrementMisses(List<String> dimensionValues) {} | ||
|
||
@Override | ||
public void incrementEvictions(List<String> dimensionValues) {} | ||
|
||
@Override | ||
public void incrementSizeInBytes(List<String> dimensionValues, long amountBytes) {} | ||
|
||
@Override | ||
public void decrementSizeInBytes(List<String> dimensionValues, long amountBytes) {} | ||
|
||
@Override | ||
public void incrementEntries(List<String> dimensionValues) { | ||
entries.inc(); | ||
} | ||
|
||
@Override | ||
public void decrementEntries(List<String> dimensionValues) { | ||
entries.dec(); | ||
} | ||
|
||
@Override | ||
public void reset() {} | ||
|
||
@Override | ||
public long count() { | ||
return entries.count(); | ||
} | ||
|
||
@Override | ||
public void removeDimensions(List<String> dimensionValues) {} | ||
|
||
@Override | ||
public ImmutableCacheStatsHolder getImmutableCacheStatsHolder() { | ||
ImmutableCacheStatsHolder.Node dummyNode = new ImmutableCacheStatsHolder.Node("", null, new ImmutableCacheStats(0, 0, 0, 0, 0)); | ||
return new ImmutableCacheStatsHolder(dummyNode, dimensionNames); | ||
} | ||
} |