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

[14.0] ISPN-15042 Do not collect clustered stats in some conditions #11133

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;

import org.infinispan.commons.CacheException;
import org.infinispan.commons.time.TimeService;
import org.infinispan.factories.annotations.Inject;
import org.infinispan.factories.annotations.Start;
Expand Down Expand Up @@ -117,7 +116,6 @@ synchronized void fetchClusterWideStatsIfNeeded() {
updateStats();
} catch (Exception e) {
log.error("Could not execute cluster wide cache stats operation ", e);
throw new CacheException("Could not execute cluster wide cache stats operation", e);
} finally {
statsUpdateTimestamp = timeService.time();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.function.Function;
Expand Down Expand Up @@ -108,6 +109,10 @@ public void start() {

@Override
void updateStats() {
if (clusterExecutor == null) {
// Attempt to retrieve cluster stats before component has been initialized
return;
}
ConcurrentMap<Address, Map<String, Number>> resultMap = new ConcurrentHashMap<>();
TriConsumer<Address, Map<String, Number>, Throwable> triConsumer = (a, v, t) -> {
if (t != null) {
Expand All @@ -126,43 +131,47 @@ void updateStats() {
};
boolean accurateSize = globalConfiguration.metrics().accurateSize();
DistributedCacheStatsCallable task = new DistributedCacheStatsCallable(cache.getName(), accurateSize);
CompletableFuture<Void> future = clusterExecutor.submitConsumer(task, triConsumer);
future.join();

Collection<Map<String, Number>> responseList = resultMap.values();

for (String att : LONG_ATTRIBUTES)
putLongAttributes(responseList, att);

putLongAttributesAverage(responseList, AVERAGE_WRITE_TIME);
putLongAttributesAverage(responseList, AVERAGE_WRITE_TIME_NANOS);
putLongAttributesAverage(responseList, AVERAGE_READ_TIME);
putLongAttributesAverage(responseList, AVERAGE_READ_TIME_NANOS);
putLongAttributesAverage(responseList, AVERAGE_REMOVE_TIME);
putLongAttributesAverage(responseList, AVERAGE_REMOVE_TIME_NANOS);
putLongAttributesAverage(responseList, OFF_HEAP_MEMORY_USED);

putIntAttributes(responseList, NUMBER_OF_LOCKS_HELD);
putIntAttributes(responseList, NUMBER_OF_LOCKS_AVAILABLE);
putIntAttributesMax(responseList, REQUIRED_MIN_NODES);

putLongAttributes(responseList, APPROXIMATE_ENTRIES);
putLongAttributes(responseList, APPROXIMATE_ENTRIES_IN_MEMORY);
putLongAttributes(responseList, APPROXIMATE_ENTRIES_UNIQUE);

if (accurateSize) {
// Count each entry only once
long numberOfEntriesInMemory = cache.withFlags(Flag.SKIP_CACHE_LOAD).size();
statsMap.put(NUMBER_OF_ENTRIES_IN_MEMORY, numberOfEntriesInMemory);
int numberOfEntries = cache.size();
statsMap.put(NUMBER_OF_ENTRIES, (long) numberOfEntries);
} else {
statsMap.put(NUMBER_OF_ENTRIES_IN_MEMORY, -1L);
statsMap.put(NUMBER_OF_ENTRIES, -1L);
}
try {
CompletableFuture<Void> future = clusterExecutor.submitConsumer(task, triConsumer);
future.join();

Collection<Map<String, Number>> responseList = resultMap.values();

for (String att : LONG_ATTRIBUTES)
putLongAttributes(responseList, att);

putLongAttributesAverage(responseList, AVERAGE_WRITE_TIME);
putLongAttributesAverage(responseList, AVERAGE_WRITE_TIME_NANOS);
putLongAttributesAverage(responseList, AVERAGE_READ_TIME);
putLongAttributesAverage(responseList, AVERAGE_READ_TIME_NANOS);
putLongAttributesAverage(responseList, AVERAGE_REMOVE_TIME);
putLongAttributesAverage(responseList, AVERAGE_REMOVE_TIME_NANOS);
putLongAttributesAverage(responseList, OFF_HEAP_MEMORY_USED);

putIntAttributes(responseList, NUMBER_OF_LOCKS_HELD);
putIntAttributes(responseList, NUMBER_OF_LOCKS_AVAILABLE);
putIntAttributesMax(responseList, REQUIRED_MIN_NODES);

putLongAttributes(responseList, APPROXIMATE_ENTRIES);
putLongAttributes(responseList, APPROXIMATE_ENTRIES_IN_MEMORY);
putLongAttributes(responseList, APPROXIMATE_ENTRIES_UNIQUE);

if (accurateSize) {
// Count each entry only once
long numberOfEntriesInMemory = cache.withFlags(Flag.SKIP_CACHE_LOAD).size();
statsMap.put(NUMBER_OF_ENTRIES_IN_MEMORY, numberOfEntriesInMemory);
int numberOfEntries = cache.size();
statsMap.put(NUMBER_OF_ENTRIES, (long) numberOfEntries);
} else {
statsMap.put(NUMBER_OF_ENTRIES_IN_MEMORY, -1L);
statsMap.put(NUMBER_OF_ENTRIES, -1L);
}

updateTimeSinceStart(responseList);
updateRatios(responseList);
updateTimeSinceStart(responseList);
updateRatios(responseList);
} catch (CompletionException e) {
log.debug("Error while collecting cluster-wide cache stats", e.getCause());
}
}

// -------------------------------------------- JMX information -----------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@ public void start() {
@Override
protected List<Map<String, Number>> statistics() throws Exception {
final List<Map<String, Number>> successfulResponseMaps = new ArrayList<>();
CompletableFutures.await(clusterExecutor.submitConsumer(ignore -> getLocalStatMaps(), (addr, stats, t) -> {
if (t == null) {
successfulResponseMaps.add(stats);
}
}));
// protect against stats collection before the component is ready
if (clusterExecutor != null) {
CompletableFutures.await(clusterExecutor.submitConsumer(ignore -> getLocalStatMaps(), (addr, stats, t) -> {
if (t == null) {
successfulResponseMaps.add(stats);
}
}));
}
return successfulResponseMaps;
}

Expand Down