This is an automated email from the ASF dual-hosted git repository.
jensdeppe pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push:
new e927bdf GEODE-8859: Fix redis-compatability data structure bucket
memory-usage reporting (#6084)
e927bdf is described below
commit e927bdf42b64eac96758642fcd22c8a144a3890e
Author: John Hutchison <[email protected]>
AuthorDate: Mon Mar 8 10:16:49 2021 -0500
GEODE-8859: Fix redis-compatability data structure bucket memory-usage
reporting (#6084)
- Implement default getForceReCalculateSize in RedisData interface
- Expose dataStoreBytesInUse on GeodeRedisServer
- Expose dataStoreBytesInUse on GeodeRedisService
- Expose dataStoreBytesInUse on RedisClusterStartupRule
Authored-by: john Hutchison <[email protected]>
---
.../test/dunit/rules/RedisClusterStartupRule.java | 7 ++
.../data/PartitionedRegionStatsUpdateTest.java | 76 ++++++++++++++++++++++
.../geode/redis/internal/GeodeRedisServer.java | 8 +++
.../geode/redis/internal/GeodeRedisService.java | 6 ++
.../geode/redis/internal/data/RedisData.java | 4 ++
5 files changed, 101 insertions(+)
diff --git
a/geode-redis/src/commonTest/java/org/apache/geode/test/dunit/rules/RedisClusterStartupRule.java
b/geode-redis/src/commonTest/java/org/apache/geode/test/dunit/rules/RedisClusterStartupRule.java
index 1f9fa3a..39faa8c 100644
---
a/geode-redis/src/commonTest/java/org/apache/geode/test/dunit/rules/RedisClusterStartupRule.java
+++
b/geode-redis/src/commonTest/java/org/apache/geode/test/dunit/rules/RedisClusterStartupRule.java
@@ -78,6 +78,13 @@ public class RedisClusterStartupRule extends
ClusterStartupRule {
return getRedisPort(getMember(vmNumber));
}
+ public Long getDataStoreBytesInUseForDataRegion(MemberVM vm) {
+ return vm.invoke(() -> {
+ GeodeRedisService service =
ClusterStartupRule.getCache().getService(GeodeRedisService.class);
+ return service.getDataStoreBytesInUseForDataRegion();
+ });
+ }
+
public int getRedisPort(MemberVM vm) {
return vm.invoke(() -> {
GeodeRedisService service =
ClusterStartupRule.getCache().getService(GeodeRedisService.class);
diff --git
a/geode-redis/src/distributedTest/java/org/apache/geode/redis/internal/data/PartitionedRegionStatsUpdateTest.java
b/geode-redis/src/distributedTest/java/org/apache/geode/redis/internal/data/PartitionedRegionStatsUpdateTest.java
new file mode 100644
index 0000000..5c28fca
--- /dev/null
+++
b/geode-redis/src/distributedTest/java/org/apache/geode/redis/internal/data/PartitionedRegionStatsUpdateTest.java
@@ -0,0 +1,76 @@
+/*
+ * 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
+ *
+ * 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.geode.redis.internal.data;
+
+import static
org.apache.geode.distributed.ConfigurationProperties.MAX_WAIT_TIME_RECONNECT;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.Properties;
+
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+import redis.clients.jedis.Jedis;
+
+import org.apache.geode.test.awaitility.GeodeAwaitility;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.dunit.rules.RedisClusterStartupRule;
+
+public class PartitionedRegionStatsUpdateTest {
+
+ @ClassRule
+ public static RedisClusterStartupRule clusterStartUpRule = new
RedisClusterStartupRule(2);
+
+ private static MemberVM server1;
+ private static final String LOCAL_HOST = "127.0.0.1";
+ private static final int JEDIS_TIMEOUT =
+ Math.toIntExact(GeodeAwaitility.getTimeout().toMillis());
+
+ private static Jedis jedis1;
+
+ @BeforeClass
+ public static void classSetup() {
+ Properties locatorProperties = new Properties();
+ locatorProperties.setProperty(MAX_WAIT_TIME_RECONNECT, "15000");
+
+ MemberVM locator = clusterStartUpRule.startLocatorVM(0, locatorProperties);
+ int locatorPort = locator.getPort();
+
+ server1 = clusterStartUpRule.startRedisVM(1, locatorPort);
+ int redisServerPort1 = clusterStartUpRule.getRedisPort(1);
+
+ jedis1 = new Jedis(LOCAL_HOST, redisServerPort1, JEDIS_TIMEOUT);
+ }
+
+ @Test
+ public void
should_showIncreaseInDatastoreBytesInUse_givenValueSizeIncreases() {
+ String KEY = "key";
+ String LONG_APPEND_VALUE = String.valueOf(Integer.MAX_VALUE);
+ jedis1.set(KEY, "value");
+
+ long initialDataStoreBytesInUse =
+ clusterStartUpRule.getDataStoreBytesInUseForDataRegion(server1);
+
+ for (int i = 0; i < 1000; i++) {
+ jedis1.append(KEY, LONG_APPEND_VALUE);
+ }
+
+ long finalDataStoreBytesInUse =
clusterStartUpRule.getDataStoreBytesInUseForDataRegion(server1);
+
assertThat(initialDataStoreBytesInUse).isLessThan(finalDataStoreBytesInUse);
+ }
+}
diff --git
a/geode-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisServer.java
b/geode-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisServer.java
index 06fa6d6..92449a2 100644
---
a/geode-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisServer.java
+++
b/geode-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisServer.java
@@ -23,6 +23,7 @@ import org.apache.geode.cache.Cache;
import org.apache.geode.cache.Region;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.cache.PartitionedRegion;
import org.apache.geode.internal.statistics.StatisticsClock;
import org.apache.geode.internal.statistics.StatisticsClockFactory;
import org.apache.geode.logging.internal.executors.LoggingExecutors;
@@ -134,6 +135,13 @@ public class GeodeRedisServer {
return redisStats;
}
+ @VisibleForTesting
+ protected Long getDataStoreBytesInUseForDataRegion() {
+ PartitionedRegion dataRegion = (PartitionedRegion)
this.getRegionProvider().getDataRegion();
+ long dataStoreBytesInUse =
dataRegion.getPrStats().getDataStoreBytesInUse();
+ return dataStoreBytesInUse;
+ }
+
/**
* Precedence of the internal property overrides the global system property.
*/
diff --git
a/geode-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisService.java
b/geode-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisService.java
index 082cfd8..b6d3238 100644
---
a/geode-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisService.java
+++
b/geode-redis/src/main/java/org/apache/geode/redis/internal/GeodeRedisService.java
@@ -17,6 +17,7 @@ package org.apache.geode.redis.internal;
import org.apache.logging.log4j.Logger;
+import org.apache.geode.annotations.VisibleForTesting;
import org.apache.geode.cache.Cache;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.distributed.internal.ResourceEvent;
@@ -102,6 +103,11 @@ public class GeodeRedisService implements CacheService,
ResourceEventsListener {
return redisServer.getPort();
}
+ @VisibleForTesting
+ public Long getDataStoreBytesInUseForDataRegion() {
+ return redisServer.getDataStoreBytesInUseForDataRegion();
+ }
+
public void setEnableUnsupported(boolean unsupported) {
redisServer.setAllowUnsupportedCommands(unsupported);
}
diff --git
a/geode-redis/src/main/java/org/apache/geode/redis/internal/data/RedisData.java
b/geode-redis/src/main/java/org/apache/geode/redis/internal/data/RedisData.java
index 5e24051..c5ff8e4 100644
---
a/geode-redis/src/main/java/org/apache/geode/redis/internal/data/RedisData.java
+++
b/geode-redis/src/main/java/org/apache/geode/redis/internal/data/RedisData.java
@@ -60,4 +60,8 @@ public interface RedisData extends Delta, DataSerializable {
boolean rename(Region<ByteArrayWrapper, RedisData> region, ByteArrayWrapper
oldKey,
ByteArrayWrapper newKey);
+ default boolean getForceRecalculateSize() {
+ return true;
+ }
+
}