Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -16,9 +16,8 @@
*/
package org.apache.jackrabbit.oak.plugins.blob;

import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.cache.CacheLIRS;
import org.apache.jackrabbit.oak.cache.api.CacheStatsAdapter;
import org.apache.jackrabbit.oak.cache.CacheStats;
import org.apache.jackrabbit.oak.cache.api.LoadingCache;
import org.apache.jackrabbit.oak.cache.api.Weigher;
import org.apache.jackrabbit.oak.commons.StringUtils;
Expand Down Expand Up @@ -48,7 +47,7 @@ public abstract class CachingBlobStore extends AbstractBlobStore {
return (int) weight;
};

private final AbstractCacheStats cacheStats;
private final CacheStats cacheStats;

public static final String MEM_CACHE_NAME = "BlobStore-MemCache";

Expand All @@ -62,7 +61,7 @@ public CachingBlobStore(long cacheSize) {
weigher(weigher::weigh).
build().asOakCache();

cacheStats = new CacheStatsAdapter(cache, MEM_CACHE_NAME, weigher, cacheSize);
cacheStats = new CacheStats(cache, MEM_CACHE_NAME, weigher, cacheSize);
}

public CachingBlobStore() {
Expand All @@ -79,7 +78,7 @@ public long getBlobCacheSize() {
return blobCacheSize;
}

public AbstractCacheStats getCacheStats() {
public CacheStats getCacheStats() {
return cacheStats;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import org.apache.jackrabbit.oak.cache.CacheLIRS;
import org.apache.jackrabbit.oak.cache.api.Cache;
import org.apache.jackrabbit.oak.cache.api.CacheLoader;
import org.apache.jackrabbit.oak.cache.api.CacheStatsAdapter;
import org.apache.jackrabbit.oak.cache.CacheStats;
import org.apache.jackrabbit.oak.cache.api.Weigher;
import org.apache.jackrabbit.oak.commons.StringUtils;
import org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser;
Expand Down Expand Up @@ -423,7 +423,7 @@ private int build() {
}
}

class FileCacheStats extends CacheStatsAdapter implements DataStoreCacheStatsMBean {
class FileCacheStats extends CacheStats implements DataStoreCacheStatsMBean {
private static final long BLOCK_SIZE = 4 * 1024;
private final Weigher<Object, Object> weigher;
private final Cache<Object, Object> cache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@
import org.apache.jackrabbit.oak.api.blob.BlobDownloadOptions;
import org.apache.jackrabbit.oak.api.blob.BlobUpload;
import org.apache.jackrabbit.oak.api.blob.BlobUploadOptions;
import org.apache.jackrabbit.oak.cache.AbstractCacheStats;
import org.apache.jackrabbit.oak.cache.api.Cache;
import org.apache.jackrabbit.oak.cache.api.CacheBuilder;
import org.apache.jackrabbit.oak.cache.api.CacheStatsAdapter;
import org.apache.jackrabbit.oak.cache.CacheStats;
import org.apache.jackrabbit.oak.cache.api.Weigher;
import org.apache.jackrabbit.oak.commons.StringUtils;
import org.apache.jackrabbit.oak.commons.collections.IteratorUtils;
Expand Down Expand Up @@ -134,7 +132,7 @@ public int weigh(@NotNull String key, @NotNull byte[] value) {
}
};

private final AbstractCacheStats cacheStats;
private final CacheStats cacheStats;

public static final String MEM_CACHE_NAME = "BlobStore-MemCache";

Expand All @@ -159,7 +157,7 @@ public DataStoreBlobStore(DataStore delegate, boolean encodeLengthInId, int cach
.maximumWeight(cacheSize)
.weigher(weigher::weigh)
.build().asOakCache();
this.cacheStats = new CacheStatsAdapter(cache, MEM_CACHE_NAME, weigher, cacheSize);
this.cacheStats = new CacheStats(cache, MEM_CACHE_NAME, weigher, cacheSize);
}

//~----------------------------------< DataStore >
Expand Down Expand Up @@ -828,7 +826,7 @@ public DataStore getDataStore() {
return delegate;
}

public AbstractCacheStats getCacheStats() {
public CacheStats getCacheStats() {
return cacheStats;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import java.util.StringJoiner;
import java.util.concurrent.TimeUnit;

import org.apache.jackrabbit.guava.common.cache.CacheStats;
import org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean;
import org.apache.jackrabbit.oak.cache.api.CacheStatsSnapshot;
import org.apache.jackrabbit.oak.commons.jmx.AnnotatedStandardMBean;
import org.jetbrains.annotations.NotNull;

Expand All @@ -38,8 +38,8 @@ public abstract class AbstractCacheStats extends AnnotatedStandardMBean implemen
@NotNull
private final String name;

private CacheStats lastSnapshot =
new CacheStats(0, 0, 0, 0, 0, 0);
private CacheStatsSnapshot lastSnapshot =
new CacheStatsSnapshot(0, 0, 0, 0, 0, 0);

/**
* Create a new {@code CacheStatsMBean} for a cache with the given {@code name}.
Expand All @@ -51,19 +51,21 @@ protected AbstractCacheStats(@NotNull String name) {
}

/**
* Call back invoked to retrieve the most recent {@code CacheStats} instance of the
* Call back invoked to retrieve the most recent {@link CacheStatsSnapshot} of the
* underlying cache.
*/
protected abstract CacheStats getCurrentStats();
protected abstract CacheStatsSnapshot getCurrentStats();

private CacheStats stats() {
return getCurrentStats().minus(lastSnapshot);
private CacheStatsSnapshot stats() {
CacheStatsSnapshot baseline;
synchronized (this) {
baseline = lastSnapshot;
}
return getCurrentStats().minus(baseline);
}

@Override
public synchronized void resetStats() {
// Cache stats cannot be rest at Guava level. Instead we
// take a snapshot and then subtract it from future stats calls
lastSnapshot = getCurrentStats();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,82 +1,79 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jackrabbit.oak.cache;

import java.util.Map;
import java.util.Objects;

import org.apache.jackrabbit.guava.common.cache.Cache;
import org.apache.jackrabbit.guava.common.cache.Weigher;

import org.apache.jackrabbit.oak.cache.api.Cache;
import org.apache.jackrabbit.oak.cache.api.CacheStatsSnapshot;
import org.apache.jackrabbit.oak.cache.api.Weigher;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Cache statistics.
* Exposes a {@link Cache}'s statistics via the {@link org.apache.jackrabbit.oak.api.jmx.CacheStatsMBean}
* interface.
*/
public class CacheStats extends AbstractCacheStats {

private final Cache<Object, Object> cache;
private final Weigher<Object, Object> weigher;
private final long maxWeight;

/**
* Construct the cache stats object.
*
* @param cache the cache
* @param name the name of the cache
* @param weigher the weigher used to estimate the current weight
* @param maxWeight the maximum weight
* Creates an adapter for the given cache.
*
* @param cache the cache whose statistics to expose (must not be null)
* @param name the JMX bean name (must not be null)
* @param weigher optional weigher used to estimate current cache weight; {@code null} if unknown
* @param maxWeight configured maximum weight for the cache; {@code -1} if unbounded
*/
@SuppressWarnings("unchecked")
public CacheStats(
@NotNull Cache<?, ?> cache,
public <K, V> CacheStats(
@NotNull Cache<K, V> cache,
@NotNull String name,
@Nullable Weigher<?, ?> weigher,
@Nullable Weigher<K, V> weigher,
long maxWeight) {
super(name);
this.cache = (Cache<Object, Object>) Objects.requireNonNull(cache);
this.cache = (Cache<Object, Object>) cache;
this.weigher = (Weigher<Object, Object>) weigher;
this.maxWeight = maxWeight;
}

@Override
protected org.apache.jackrabbit.guava.common.cache.CacheStats getCurrentStats() {
protected CacheStatsSnapshot getCurrentStats() {
return cache.stats();
}

@Override
public long getElementCount() {
return cache.size();
return cache.asMap().size();
}

@Override
public long estimateCurrentWeight() {
if (weigher == null) {
return -1;
}
long size = 0;
for (Map.Entry<?, ?> e : cache.asMap().entrySet()) {
Object k = e.getKey();
Object v = e.getValue();
size += weigher.weigh(k, v);
long total = 0;
for (Map.Entry<Object, Object> e : cache.asMap().entrySet()) {
total += weigher.weigh(e.getKey(), e.getValue());
}
return size;
return total;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
* Determines the weight of object based on the memory taken by them. The memory estimates
* are based on empirical data and not exact
*/
public class EmpiricalWeigher extends GuavaCompatibleEmpiricalWeigher
implements Weigher<CacheValue, CacheValue> {
public class EmpiricalWeigher implements Weigher<CacheValue, CacheValue> {

static final Logger LOG = LoggerFactory.getLogger(EmpiricalWeigher.class);

Expand All @@ -45,15 +44,3 @@ public int weigh(@NotNull CacheValue key, @NotNull CacheValue value) {
}

}

/**
* Compatibility base class that keeps {@link EmpiricalWeigher} assignable to the
* legacy Guava-shim {@link org.apache.jackrabbit.guava.common.cache.Weigher} type while the public API migrates to
* {@link Weigher}.
*
* <p>TODO OAK-12162: remove this compatibility base in
* OAK-12162 once downstream callers no longer require {@link org.apache.jackrabbit.guava.common.cache.Weigher}
* assignability.</p>
*/
abstract class GuavaCompatibleEmpiricalWeigher implements org.apache.jackrabbit.guava.common.cache.Weigher<CacheValue, CacheValue> {
}

This file was deleted.

Loading
Loading