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

Stats rework (1/3): Interfaces and implementations for tiers #24

Open
wants to merge 34 commits into
base: ehcache-disk-integ-base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
641abf1
CacheStats interface and SingleDimensionCacheStats impl
Feb 8, 2024
937ca51
First attempt to integrate new stats with EhcacheDiskCache
Feb 8, 2024
21b1078
Adds Serializer interface and impls for Key and BytesReference
Jan 9, 2024
a460acd
Adds ICacheKey serializer impl
Feb 9, 2024
31ee9ae
Added more icachekey serializer tests
Feb 9, 2024
9069077
Attempts to fix ehcache hits
Feb 9, 2024
18ddb23
Fixed unexpected misses by implementing hashCode for ICacheKey and Ca…
Feb 9, 2024
8618458
Adds memory tracking to disk tier
Feb 12, 2024
46b3e49
Updated other tests
Feb 12, 2024
51ea583
Added partial memory tests
Feb 12, 2024
17cf26a
Changed cache stats API to get values by dimension list
Feb 12, 2024
be5eece
Cleanup
Feb 13, 2024
a6b0899
Redid memory tracking to use already implemented weigher fn
Feb 13, 2024
9b1e66c
Split CacheStats into CacheStats and CacheStatsBase, which can't upda…
Feb 13, 2024
01e04a8
Readded BytesReferenceSerializer impl as ICacheKeySerializerTests dep…
Feb 13, 2024
3777e3f
Changed SingleDimensionCacheStats to use ConcurrentMap
Feb 14, 2024
6059680
Made SingleDimensionCacheStats also take in tier dimensions
Feb 14, 2024
7f5a455
Added overall CacheStatsResponse object packaging all 5 metrics
Feb 14, 2024
36c600d
Removed skeleton TSC stats implementation
Feb 14, 2024
27fdfe1
Merge remote-tracking branch 'sgup432/ehcache_disk_integ' into rework…
Feb 26, 2024
c8dc1b3
Modified factories to take new arguments
Feb 26, 2024
4abd602
added utilitly fns to CacheStatsResponse
Feb 27, 2024
2586fa1
Making TieredCachePlugin constructor public
sgup432 Feb 27, 2024
6a2b374
Fixing CacheService unit test
sgup432 Feb 27, 2024
3e7ea26
Added multi dimension cache stats impl
Feb 27, 2024
b4c83e7
Removed SingleDimensionCacheStats
Feb 27, 2024
d579c51
Adds IRC key serializer
Feb 27, 2024
c34c218
Addressed Sagar's other comment
Feb 27, 2024
2f4bd4f
Merge remote-tracking branch 'sgup432/ehcache_disk_integ' into rework…
Feb 28, 2024
a61f033
Fixed on heap stats integration, added tests
Feb 29, 2024
2483981
Optimized multi dimension stats
Mar 1, 2024
2aeaa53
Added reset() to CacheStats
Mar 1, 2024
60df761
Fixed reset impl for multi dim stats
Mar 1, 2024
ea33af8
spotlessApply
Mar 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.opensearch.plugins.Plugin;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -36,7 +37,8 @@ public EhcacheCachePlugin() {}

@Override
public Map<CacheStoreType, StoreAwareCache.Factory> getCacheStoreTypeMap() {
return Map.of(CacheStoreType.DISK, new EhcacheDiskCache.EhcacheDiskCacheFactory());
return new HashMap<>(); // TODO: FIX
//return Map.of(CacheStoreType.DISK, new EhcacheDiskCache.EhcacheDiskCacheFactory());
}

@Override
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions server/src/main/java/org/opensearch/common/cache/ICache.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
* @opensearch.experimental
*/
public interface ICache<K, V> extends Closeable {
V get(K key);
V get(ICacheKey<K> key);

void put(K key, V value);
void put(ICacheKey<K> key, V value);

V computeIfAbsent(K key, LoadAwareCacheLoader<K, V> loader) throws Exception;
V computeIfAbsent(ICacheKey<K> key, LoadAwareCacheLoader<ICacheKey<K>, V> loader) throws Exception;

void invalidate(K key);
void invalidate(ICacheKey<K> key);

void invalidateAll();

Iterable<K> keys();
Iterable<ICacheKey<K>> keys();

long count();

Expand Down
45 changes: 45 additions & 0 deletions server/src/main/java/org/opensearch/common/cache/ICacheKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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;


import org.opensearch.common.cache.stats.CacheStatsDimension;

import java.util.List;
import java.util.Objects;

public class ICacheKey<K> {
public final K key; // K must implement equals()
public final List<CacheStatsDimension> dimensions;

public ICacheKey(K key, List<CacheStatsDimension> dimensions) {
this.key = key;
this.dimensions = dimensions;
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o == null) {
return false;
}
if (o.getClass() != ICacheKey.class) {
return false;
}
ICacheKey other = (ICacheKey) o;
return key.equals(other.key) && dimensions.equals(other.dimensions);
}

@Override
public int hashCode() {
return Objects.hash(key, dimensions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,44 @@

package org.opensearch.common.cache.stats;

import org.opensearch.core.common.io.stream.Writeable;

import java.util.List;

/**
* Interface for any cache specific stats.
* TODO: Add rest of stats like hits/misses.
* Interface for any cache specific stats. Allows accessing stats by total value or by dimension,
* and also allows updating stats.
* When updating stats, we take in the list of dimensions associated with the key/value pair that caused the update.
* This allows us to aggregate stats by dimension when accessing them.
*/
public interface CacheStats {
// Provides the current number of entries in cache.
long count();
public interface CacheStats extends Writeable {

// Methods to get all 5 values at once, either in total or for a specific set of dimensions.
CacheStatsResponse getTotalStats();
CacheStatsResponse getStatsByDimensions(List<CacheStatsDimension> dimensions);

// Methods to get total values.
long getTotalHits();
long getTotalMisses();
long getTotalEvictions();
long getTotalMemorySize();
long getTotalEntries();

// Methods to get values for a specific set of dimensions.
// Returns the sum of values for cache entries that match all dimensions in the list.
long getHitsByDimensions(List<CacheStatsDimension> dimensions);
long getMissesByDimensions(List<CacheStatsDimension> dimensions);
long getEvictionsByDimensions(List<CacheStatsDimension> dimensions);
long getMemorySizeByDimensions(List<CacheStatsDimension> dimensions);
long getEntriesByDimensions(List<CacheStatsDimension> dimensions);


void incrementHitsByDimensions(List<CacheStatsDimension> dimensions);
void incrementMissesByDimensions(List<CacheStatsDimension> dimensions);
void incrementEvictionsByDimensions(List<CacheStatsDimension> dimensions);
// Can also use to decrement, with negative values
void incrementMemorySizeByDimensions(List<CacheStatsDimension> dimensions, long amountBytes);
void incrementEntriesByDimensions(List<CacheStatsDimension> dimensions);
void decrementEntriesByDimensions(List<CacheStatsDimension> dimensions);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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.core.common.io.stream.StreamInput;
import org.opensearch.core.common.io.stream.StreamOutput;
import org.opensearch.core.common.io.stream.Writeable;

import java.io.IOException;
import java.util.Objects;

public class CacheStatsDimension implements Writeable {
// Values for tier dimensions, that are reused across CacheStats implementations
public static final String TIER_DIMENSION_NAME = "tier";
public static final String TIER_DIMENSION_VALUE_ON_HEAP = "on_heap";
public static final String TIER_DIMENSION_VALUE_DISK = "disk";
Copy link

Choose a reason for hiding this comment

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

This should not be declared here. Should be present in respective caches.

public final String dimensionName;
public final String dimensionValue;
public CacheStatsDimension(String dimensionName, String dimensionValue) {
this.dimensionName = dimensionName;
this.dimensionValue = dimensionValue;
}

public CacheStatsDimension(StreamInput in) throws IOException {
this.dimensionName = in.readString();
this.dimensionValue = in.readString();
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(dimensionName);
out.writeString(dimensionValue);
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if (o == null) {
return false;
}
if (o.getClass() != CacheStatsDimension.class) {
return false;
}
CacheStatsDimension other = (CacheStatsDimension) o;
if (other.dimensionName == null || other.dimensionValue == null) {
return false;
}
return other.dimensionName.equals(dimensionName) && other.dimensionValue.equals(dimensionValue);
}

@Override
public int hashCode() {
return Objects.hash(dimensionName, dimensionValue);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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;

/**
* A class containing the 5 metrics tracked by a CacheStats object.
*/
public class CacheStatsResponse { // TODO: Make this extend ToXContent.
public final long hits;
public final long misses;
public final long evictions;
public final long memorySize;
public final long entries;

public CacheStatsResponse(long hits, long misses, long evictions, long memorySize, long entries) {
this.hits = hits;
this.misses = misses;
this.evictions = evictions;
this.memorySize = memorySize;
this.entries = entries;
}
}
Loading
Loading