DonalEvans commented on a change in pull request #7417:
URL: https://github.com/apache/geode/pull/7417#discussion_r818159410
##########
File path:
geode-for-redis/src/main/java/org/apache/geode/redis/internal/data/RedisList.java
##########
@@ -61,20 +62,35 @@ public RedisList() {
}
/**
- * @param elementsToAdd elements to add to this set; NOTE this list may by
modified by this call
+ * @param elementsToAdd elements to add to this list; NOTE this list may be
modified by this call
* @param region the region this instance is stored in
- * @param key the name of the set to add to
+ * @param key the name of the list to add to
* @param onlyIfExists if true then the elements should only be added if the
key already exists
* and holds a list, otherwise no operation is performed.
* @return the length of the list after the operation
*/
- public long lpush(List<byte[]> elementsToAdd, Region<RedisKey, RedisData>
region, RedisKey key,
- final boolean onlyIfExists) {
- elementsPush(elementsToAdd);
+ public synchronized long lpush(List<byte[]> elementsToAdd, Region<RedisKey,
RedisData> region,
+ RedisKey key, final boolean onlyIfExists) {
+ elementsPushHead(elementsToAdd);
storeChanges(region, key, new AddByteArrays(elementsToAdd));
return elementList.size();
}
+ /**
+ * @param elementsToAdd elements to add to this list; NOTE this list may be
modified by this call
Review comment:
I believe that the "NOTE" on this comment (and the similar one for
`lpush()`) is no longer accurate, as the list of elements to add is never
modified by either method.
##########
File path:
geode-for-redis/src/integrationTest/java/org/apache/geode/redis/internal/commands/executor/list/AbstractRPushIntegrationTest.java
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.commands.executor.list;
+
+import static
org.apache.geode.redis.RedisCommandArgumentsTestHelper.assertAtLeastNArgs;
+import static org.apache.geode.redis.internal.RedisConstants.ERROR_WRONG_TYPE;
+import static
org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static
org.apache.geode.test.dunit.rules.RedisClusterStartupRule.REDIS_CLIENT_TIMEOUT;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.Protocol;
+
+import org.apache.geode.redis.RedisIntegrationTest;
+
+public abstract class AbstractRPushIntegrationTest implements
RedisIntegrationTest {
Review comment:
Could we add a concurrent test to make sure that RPUSH is correctly
locking/synchronizing:
```
@Test
public void concurrentRpush_behavesCorrectly() {
String[] rpushElements1 = IntStream.range(0, 10)
.mapToObj(Integer::toString)
.toArray(String[]::new);
String[] rpushElements2 = IntStream.range(10, 20)
.mapToObj(Integer::toString)
.toArray(String[]::new);
String[] expectedContents1 =
Streams.concat(Arrays.stream(rpushElements1),
Arrays.stream(rpushElements2))
.toArray(String[]::new);
String[] expectedContents2 =
Streams.concat(Arrays.stream(rpushElements2),
Arrays.stream(rpushElements1))
.toArray(String[]::new);
new ConcurrentLoopingThreads(1000,
i -> jedis.rpush(KEY, rpushElements1),
i -> jedis.rpush(KEY, rpushElements2))
.runWithAction(() -> {
String[] actualContents = new String[expectedContents1.length];
for (int i = 0; i < actualContents.length; ++i) {
actualContents[i] = jedis.lindex(KEY, i);
}
assertThat(actualContents).satisfiesAnyOf(
actual ->
assertThat(actual).containsExactly(expectedContents1),
actual ->
assertThat(actual).containsExactly(expectedContents2));
jedis.del(KEY);
});
}
```
Similarly, we could add a test for RPUSH with concurrent LPUSH to make sure
that both are locking and synchronizing properly.
##########
File path: geode-docs/tools_modules/geode_for_redis.html.md.erb
##########
@@ -176,35 +176,35 @@ Could not connect to Redis at 127.0.0.1:6379: Connection
refused
<%=vars.product_name%> for Redis supports the following Redis commands.
-| Supported Commands ||||
-|-----|-----|-----|-----|
-| APPEND | AUTH | CLIENT | CLUSTER **[1]** |
-| COMMAND **[2]** | DECR | DECRBY | DEL |
-| DUMP | ECHO | EXISTS | EXPIRE |
-| EXPIREAT | GET | GETRANGE | GETSET |
-| HDEL | HEXISTS | HGET | HGETALL |
-| HINCRBY | HINCRBYFLOAT | HKEYS | HLEN |
-| HMGET | HMSET | HSCAN **[3]** | HSET |
-| HSETNX | HSTRLEN | HVALS | INCR |
-| INCRBY | INCRBYFLOAT | INFO **[4]** | KEYS |
-| LINDEX | LLEN | LOLWUT | LPOP |
-| LPUSH | LPUSHX | MGET | MSET |
-| MSETNX | PERSIST | PEXPIRE | PEXPIREAT |
-| PING | PSETEX | PSUBSCRIBE | PTTL |
-| PUBLISH PUBSUB | PUNSUBSCRIBE | RENAME |
-| RENAMENX | RESTORE | SADD | SCARD |
-| SDIFF | SDIFFSTORE | SET | SETEX |
-| SETNX | SETRANGE | SINTER | SINTERSTORE |
-| SISMEMBER | SMEMBERS | SMOVE | SPOP |
-| SRANDMEMBER | SREM | SSCAN **[3]** | STRLEN |
-| SUBSCRIBE | SUNION | SUNIONSTORE | TTL |
-| TYPE | UNSUBSCRIBE | QUIT | ZADD |
-| ZCARD | ZCOUNT | ZINCRBY | ZINTERSTORE |
-| ZLEXCOUNT | ZPOPMAX | ZPOPMIN | ZRANGE |
-| ZRANGEBYLEX | ZRANGEBYSCORE | ZRANK | ZREM |
-| ZREMRANGEBYLEX | ZREMRANGEBYRANK | ZREMRANGEBYSCORE | ZREVRANGE |
-| ZREVRANGEBYLEX | ZREVRANGEBYSCORE | ZREVRANK | ZSCAN **[3]** |
-| ZSCORE | ZUNIONSTORE |||
+| Supported Commands | | | |
+|--------------------|------------------|------------------|-----------------|
+| APPEND | AUTH | CLIENT | CLUSTER **[1]** |
+| COMMAND **[2]** | DECR | DECRBY | DEL |
+| DUMP | ECHO | EXISTS | EXPIRE |
+| EXPIREAT | GET | GETRANGE | GETSET |
+| HDEL | HEXISTS | HGET | HGETALL |
+| HINCRBY | HINCRBYFLOAT | HKEYS | HLEN |
+| HMGET | HMSET | HSCAN **[3]** | HSET |
+| HSETNX | HSTRLEN | HVALS | INCR |
+| INCRBY | INCRBYFLOAT | INFO **[4]** | KEYS |
+| LINDEX | LLEN | LOLWUT | LPOP |
+| LPUSH | LPUSHX | MGET | MSET |
+| MSETNX | PERSIST | PEXPIRE | PEXPIREAT |
+| PING | PSETEX | PSUBSCRIBE | PTTL |
+| PUBLISH PUBSUB | PUNSUBSCRIBE | RENAME | RENAMENX |
Review comment:
Not your change, but should this be PUBLISH | PUBSUB, since they're two
different commands?
##########
File path:
geode-for-redis/src/distributedTest/java/org/apache/geode/redis/internal/commands/executor/list/RPushDUnitTest.java
##########
@@ -0,0 +1,201 @@
+/*
+ * 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.commands.executor.list;
+
+import static
org.apache.geode.test.dunit.rules.RedisClusterStartupRule.BIND_ADDRESS;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import redis.clients.jedis.HostAndPort;
+import redis.clients.jedis.JedisCluster;
+
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.dunit.rules.RedisClusterStartupRule;
+import org.apache.geode.test.junit.rules.ExecutorServiceRule;
+
+public class RPushDUnitTest {
+ @Rule
+ public RedisClusterStartupRule clusterStartUp = new
RedisClusterStartupRule();
+
+ @Rule
+ public ExecutorServiceRule executor = new ExecutorServiceRule();
+
+ public static final int PUSHER_COUNT = 6;
+ public static final int PUSH_LIST_SIZE = 3;
+ private static final int MINIMUM_ITERATIONS = 10000;
+
+ private static final AtomicLong runningCount = new AtomicLong(PUSHER_COUNT);
+ private static List<String> listHashtags;
+ private static List<String> keys;
+ private static HashMap<String, List<String>> keyToElementListMap;
+ private static List<Runnable> taskList;
+
+ private JedisCluster jedis;
+
+ @Before
+ public void testSetup() {
+ MemberVM locator = clusterStartUp.startLocatorVM(0);
+ clusterStartUp.startRedisVM(1, locator.getPort());
+ clusterStartUp.startRedisVM(2, locator.getPort());
+ clusterStartUp.startRedisVM(3, locator.getPort());
+ int redisServerPort = clusterStartUp.getRedisPort(1);
+ jedis = new JedisCluster(new HostAndPort(BIND_ADDRESS, redisServerPort),
10_000);
+ listHashtags = makeListHashtags();
+ keys = makeListKeys(listHashtags);
+ keyToElementListMap = new HashMap<>();
+ for (String key : keys) {
+ keyToElementListMap.put(key, makeElementList(PUSH_LIST_SIZE, key));
+ }
+
+ taskList = new ArrayList<>();
+ taskList.add(() -> rpushPerformAndVerify(keys.get(0),
keyToElementListMap.get(keys.get(0)),
+ runningCount));
+ taskList.add(() -> rpushPerformAndVerify(keys.get(0),
keyToElementListMap.get(keys.get(0)),
+ runningCount));
+ taskList.add(() -> rpushPerformAndVerify(keys.get(1),
keyToElementListMap.get(keys.get(1)),
+ runningCount));
+ taskList.add(() -> rpushPerformAndVerify(keys.get(1),
keyToElementListMap.get(keys.get(1)),
+ runningCount));
+ taskList.add(() -> rpushPerformAndVerify(keys.get(2),
keyToElementListMap.get(keys.get(2)),
+ runningCount));
+ taskList.add(() -> rpushPerformAndVerify(keys.get(2),
keyToElementListMap.get(keys.get(2)),
+ runningCount));
+ taskList.add(() -> verifyListLengthCondition(keys.get(0), runningCount));
+ taskList.add(() -> verifyListLengthCondition(keys.get(1), runningCount));
+ taskList.add(() -> verifyListLengthCondition(keys.get(2), runningCount));
+ }
+
+ @After
+ public void tearDown() {
+ jedis.close();
+ }
+
+ @Test
+ public void givenBucketsMovedDuringRPush_elementsAreAddedAtomically()
+ throws ExecutionException, InterruptedException {
+
+ List<Future<Void>> futureList = new ArrayList<>();
+ for (Runnable task : taskList) {
+ futureList.add(executor.runAsync(task));
+ }
+
+ for (int i = 0; i < 10 && runningCount.get() > 0; i++) {
+ clusterStartUp.moveBucketForKey(listHashtags.get(i %
listHashtags.size()));
+ Thread.sleep(500);
+ }
+
+ for (Future<Void> future : futureList) {
+ future.get();
+ }
+
+ for (String key : keys) {
+ long length = jedis.llen(key);
+ assertThat(length).isGreaterThanOrEqualTo(MINIMUM_ITERATIONS * 2 *
PUSH_LIST_SIZE);
+ validateListContents(key, keyToElementListMap);
+ }
+ }
+
+ @Test
+ public void shouldNotLoseData_givenPrimaryServerCrashesDuringOperations()
+ throws ExecutionException, InterruptedException {
+ List<Future<Void>> futureList = new ArrayList<>();
+ for (Runnable task : taskList) {
+ futureList.add(executor.runAsync(task));
+ }
+
+ Thread.sleep(200);
Review comment:
Rather than a `Thread.sleep()` here, it would probably be better to use
an `await()` until all the lists have some minimum size (since I assume that's
what we're actually waiting for).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]