You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by up...@apache.org on 2021/03/16 18:54:50 UTC
[geode] 17/36: Bypass function execution completely
This is an automated email from the ASF dual-hosted git repository.
upthewaterspout pushed a commit to branch feature/redis-performance-testing
in repository https://gitbox.apache.org/repos/asf/geode.git
commit 50defdd631934cfe4edf28c26e8ccd8f498d79b1
Author: Jens Deppe <jd...@vmware.com>
AuthorDate: Tue Mar 2 14:35:20 2021 -0800
Bypass function execution completely
---
.../executor/SingleResultRedisFunction.java | 15 ++++++++++
.../hash/RedisHashCommandsFunctionInvoker.java | 10 +++++++
.../string/RedisStringCommandsFunctionInvoker.java | 34 ++++++++++------------
3 files changed, 40 insertions(+), 19 deletions(-)
diff --git a/geode-redis/src/main/java/org/apache/geode/redis/internal/executor/SingleResultRedisFunction.java b/geode-redis/src/main/java/org/apache/geode/redis/internal/executor/SingleResultRedisFunction.java
index 4888d4f..713c442 100644
--- a/geode-redis/src/main/java/org/apache/geode/redis/internal/executor/SingleResultRedisFunction.java
+++ b/geode-redis/src/main/java/org/apache/geode/redis/internal/executor/SingleResultRedisFunction.java
@@ -15,6 +15,8 @@
package org.apache.geode.redis.internal.executor;
+import java.util.concurrent.atomic.AtomicReference;
+
import org.apache.geode.cache.Region;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.internal.cache.PartitionedRegion;
@@ -50,6 +52,19 @@ public abstract class SingleResultRedisFunction implements InternalFunction<Obje
partitionedRegion.computeWithPrimaryLocked(key, computation);
}
+ @SuppressWarnings("unchecked")
+ public <T> T hackedExecute(RedisKey key, Object[] args) {
+ AtomicReference<Object> result = new AtomicReference<>();
+
+ Runnable computation = () -> {
+ result.set(compute(key, args));
+ };
+
+ partitionedRegion.computeWithPrimaryLocked(key, computation);
+
+ return (T) result.get();
+ }
+
@Override
public boolean optimizeForWrite() {
return true;
diff --git a/geode-redis/src/main/java/org/apache/geode/redis/internal/executor/hash/RedisHashCommandsFunctionInvoker.java b/geode-redis/src/main/java/org/apache/geode/redis/internal/executor/hash/RedisHashCommandsFunctionInvoker.java
index bfdfa54..aeda9b6 100644
--- a/geode-redis/src/main/java/org/apache/geode/redis/internal/executor/hash/RedisHashCommandsFunctionInvoker.java
+++ b/geode-redis/src/main/java/org/apache/geode/redis/internal/executor/hash/RedisHashCommandsFunctionInvoker.java
@@ -38,9 +38,11 @@ import java.util.regex.Pattern;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.geode.cache.Region;
+import org.apache.geode.cache.execute.FunctionService;
import org.apache.geode.redis.internal.data.ByteArrayWrapper;
import org.apache.geode.redis.internal.data.RedisData;
import org.apache.geode.redis.internal.data.RedisKey;
+import org.apache.geode.redis.internal.executor.CommandFunction;
import org.apache.geode.redis.internal.executor.RedisCommandsFunctionInvoker;
/**
@@ -51,8 +53,12 @@ import org.apache.geode.redis.internal.executor.RedisCommandsFunctionInvoker;
public class RedisHashCommandsFunctionInvoker extends RedisCommandsFunctionInvoker
implements RedisHashCommands {
+ private final CommandFunction function;
+
public RedisHashCommandsFunctionInvoker(Region<RedisKey, RedisData> region) {
super(region);
+
+ function = (CommandFunction) FunctionService.getFunction(CommandFunction.ID);
}
@Override
@@ -121,4 +127,8 @@ public class RedisHashCommandsFunctionInvoker extends RedisCommandsFunctionInvok
public BigDecimal hincrbyfloat(RedisKey key, ByteArrayWrapper field, BigDecimal increment) {
return invokeCommandFunction(key, HINCRBYFLOAT, field, increment);
}
+
+ protected <T> T invokeCommandFunction(RedisKey key, Object... arguments) {
+ return function.hackedExecute(key, arguments);
+ }
}
diff --git a/geode-redis/src/main/java/org/apache/geode/redis/internal/executor/string/RedisStringCommandsFunctionInvoker.java b/geode-redis/src/main/java/org/apache/geode/redis/internal/executor/string/RedisStringCommandsFunctionInvoker.java
index cb5725a..e8a8cf0 100644
--- a/geode-redis/src/main/java/org/apache/geode/redis/internal/executor/string/RedisStringCommandsFunctionInvoker.java
+++ b/geode-redis/src/main/java/org/apache/geode/redis/internal/executor/string/RedisStringCommandsFunctionInvoker.java
@@ -39,15 +39,11 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.logging.log4j.Logger;
-import org.apache.geode.cache.EntryNotFoundException;
import org.apache.geode.cache.Region;
-import org.apache.geode.internal.cache.PartitionedRegion;
-import org.apache.geode.internal.cache.VMCachedDeserializable;
import org.apache.geode.logging.internal.log4j.api.LogService;
import org.apache.geode.redis.internal.data.ByteArrayWrapper;
import org.apache.geode.redis.internal.data.RedisData;
import org.apache.geode.redis.internal.data.RedisKey;
-import org.apache.geode.redis.internal.data.RedisString;
import org.apache.geode.redis.internal.executor.RedisCommandsFunctionInvoker;
/**
@@ -72,21 +68,21 @@ public class RedisStringCommandsFunctionInvoker extends RedisCommandsFunctionInv
@Override
public ByteArrayWrapper get(RedisKey key) {
- Object v = null;
- try {
- v = ((PartitionedRegion) region).getValueInVM(key);
- } catch (EntryNotFoundException ignored) {
- logger.info("--->>> getValueInVM miss for: {}", key);
- }
-
- if (v != null) {
- Object cached = ((VMCachedDeserializable) v).getDeserializedForReading();
- int x = getInVmCount.incrementAndGet();
- if (x % 10000 == 0) {
- logger.info("--->>> getValueInVM hits: {}", x);
- }
- return ((RedisString) cached).get();
- }
+ // Object v = null;
+ // try {
+ // v = ((PartitionedRegion) region).getValueInVM(key);
+ // } catch (EntryNotFoundException ignored) {
+ // logger.info("--->>> getValueInVM miss for: {}", key);
+ // }
+ //
+ // if (v != null) {
+ // Object cached = ((VMCachedDeserializable) v).getDeserializedForReading();
+ // int x = getInVmCount.incrementAndGet();
+ // if (x % 10000 == 0) {
+ // logger.info("--->>> getValueInVM hits: {}", x);
+ // }
+ // return ((RedisString) cached).get();
+ // }
return invokeCommandFunction(key, GET);
}