Skip to content

Commit

Permalink
Make gathering multimap stats not to break last access merge policy
Browse files Browse the repository at this point in the history
Gathering multimap statistics calls
MultiMapPartitionContainer#getMultiMapContainer() that updates the
lastAccessTime of the returned container, which in the end breaks the
last access merge policy. This is fixed by making gathering statistics
not to count an access. Also, retrieving the container on backups
for the given partition made not to be considered an access.

Fixes hazelcast#16001
  • Loading branch information
blazember committed Nov 13, 2019
1 parent 2252c4f commit c0137b9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
Expand Up @@ -61,9 +61,20 @@ public MultiMapContainer getOrCreateMultiMapContainer(String name, boolean isAcc
return container;
}

public MultiMapContainer getMultiMapContainer(String name) {
/**
* Returns the {@link MultiMapContainer} with the given {@code name}
* if exists or {@code null otherwise}. Depending on the {@code isAccess}
* parameter this call updates the {@code lastAccessTime} field of the
* container.
*
* @param name The name of the container to retrieve
* @param isAccess Indicates whether or not this call should be treated
* as an access
* @return the container or {@code null} if doesn't exist
*/
public MultiMapContainer getMultiMapContainer(String name, boolean isAccess) {
MultiMapContainer container = containerMap.get(name);
if (container != null) {
if (container != null && isAccess) {
container.access();
}
return container;
Expand Down
Expand Up @@ -212,12 +212,14 @@ public Set<Data> localKeySet(String name) {
Set<Data> keySet = new HashSet<Data>();
for (int i = 0; i < nodeEngine.getPartitionService().getPartitionCount(); i++) {
IPartition partition = nodeEngine.getPartitionService().getPartition(i);
boolean isLocalPartition = partition.isLocal();
MultiMapPartitionContainer partitionContainer = getPartitionContainer(i);
MultiMapContainer multiMapContainer = partitionContainer.getMultiMapContainer(name);
// we should not treat retrieving the container on backups an access
MultiMapContainer multiMapContainer = partitionContainer.getMultiMapContainer(name, isLocalPartition);
if (multiMapContainer == null) {
continue;
}
if (partition.isLocal()) {
if (isLocalPartition) {
keySet.addAll(multiMapContainer.keySet());
}
}
Expand Down Expand Up @@ -394,7 +396,7 @@ public LocalMultiMapStats createStats(String name) {
for (int partitionId = 0; partitionId < nodeEngine.getPartitionService().getPartitionCount(); partitionId++) {
IPartition partition = nodeEngine.getPartitionService().getPartition(partitionId, false);
MultiMapPartitionContainer partitionContainer = getPartitionContainer(partitionId);
MultiMapContainer multiMapContainer = partitionContainer.getMultiMapContainer(name);
MultiMapContainer multiMapContainer = partitionContainer.getMultiMapContainer(name, false);
if (multiMapContainer == null) {
continue;
}
Expand Down
Expand Up @@ -45,6 +45,10 @@
import java.util.Collection;
import java.util.Map;

import static com.hazelcast.internal.diagnostics.Diagnostics.ENABLED;
import static com.hazelcast.internal.diagnostics.Diagnostics.METRICS_DISTRIBUTED_DATASTRUCTURES;
import static com.hazelcast.internal.diagnostics.Diagnostics.METRICS_LEVEL;
import static com.hazelcast.internal.metrics.ProbeLevel.INFO;
import static com.hazelcast.multimap.MultiMapTestUtil.getBackupMultiMap;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertFalse;
Expand Down Expand Up @@ -128,6 +132,11 @@ protected Config config() {
.setStatisticsEnabled(true)
.setBackupCount(1)
.setAsyncBackupCount(0);

config.getProperties().setProperty(ENABLED.getName(), "true");
config.getProperties().setProperty(METRICS_DISTRIBUTED_DATASTRUCTURES.getName(), "true");
config.getProperties().setProperty(METRICS_LEVEL.getName(), INFO.name());

return config;
}

Expand Down
Expand Up @@ -63,7 +63,7 @@ public static <K, V> Map<K, Collection<V>> getBackupMultiMap(HazelcastInstance[]
continue;
}
MultiMapPartitionContainer partitionContainer = mapService.getPartitionContainer(partitionId);
MultiMapContainer multiMapContainer = partitionContainer.getMultiMapContainer(multiMapName);
MultiMapContainer multiMapContainer = partitionContainer.getMultiMapContainer(multiMapName, false);
if (multiMapContainer == null) {
continue;
}
Expand Down
Expand Up @@ -423,7 +423,7 @@ public void testMultiMapService() {
multiMap.put(key, "value2");

MultiMapPartitionContainer partitionContainer = multiMapService.getPartitionContainer(partitionId);
MultiMapContainer multiMapContainer = partitionContainer.getMultiMapContainer("myMultiMap");
MultiMapContainer multiMapContainer = partitionContainer.getMultiMapContainer("myMultiMap", false);

ConcurrentMap<Data, MultiMapValue> multiMapValues = multiMapContainer.getMultiMapValues();
for (Map.Entry<Data, MultiMapValue> entry : multiMapValues.entrySet()) {
Expand Down

0 comments on commit c0137b9

Please sign in to comment.