From fe84aed0c18eed9d5d32797434748f8f11d7c19f Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Mon, 2 Sep 2024 11:56:08 +0300 Subject: [PATCH] Fixed - RLiveObject value shouldn't be deleted during index update. #6133 --- .../liveobject/core/AccessorInterceptor.java | 5 +-- .../RedissonLiveObjectServiceTest.java | 42 ++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/redisson/src/main/java/org/redisson/liveobject/core/AccessorInterceptor.java b/redisson/src/main/java/org/redisson/liveobject/core/AccessorInterceptor.java index b6f7b15ff..f5b60b00e 100644 --- a/redisson/src/main/java/org/redisson/liveobject/core/AccessorInterceptor.java +++ b/redisson/src/main/java/org/redisson/liveobject/core/AccessorInterceptor.java @@ -215,9 +215,9 @@ public class AccessorInterceptor { || commandExecutor.getServiceManager().getCfg().isClusterConfig()) { CompletableFuture f; if (commandExecutor instanceof CommandBatchService) { - f = liveMap.removeAsync(field.getName()).toCompletableFuture(); + f = liveMap.getAsync(field.getName()).toCompletableFuture(); } else { - Object value = liveMap.remove(field.getName()); + Object value = liveMap.get(field.getName()); f = CompletableFuture.completedFuture(value); } f.thenAccept(value -> { @@ -248,7 +248,6 @@ public class AccessorInterceptor { "if oldArg == false then " + "return; " + "end;" + - "redis.call('hdel', KEYS[2], ARGV[2]); " + "local hash = redis.call('hget', KEYS[1], oldArg); " + "local setName = KEYS[1] .. ':' .. hash; " + "local res = redis.call('srem', setName, ARGV[1]); " + diff --git a/redisson/src/test/java/org/redisson/RedissonLiveObjectServiceTest.java b/redisson/src/test/java/org/redisson/RedissonLiveObjectServiceTest.java index 67cbbb852..a9e3d0d3e 100644 --- a/redisson/src/test/java/org/redisson/RedissonLiveObjectServiceTest.java +++ b/redisson/src/test/java/org/redisson/RedissonLiveObjectServiceTest.java @@ -601,7 +601,47 @@ public class RedissonLiveObjectServiceTest extends RedisDockerTest { Conditions.and(Conditions.eq("name1", "test41"), Conditions.lt("num1", 43)))); assertThat(objects6.iterator().next().getId()).isEqualTo("4"); } - + + @Test + public void testIndexRemoval2() throws InterruptedException { + RLiveObjectService liveObjectService = redisson.getLiveObjectService(); + + TestIndexed myEntity = new TestIndexed("id"); + myEntity.setName1("1"); + + liveObjectService.persist(myEntity); + + CountDownLatch latch = new CountDownLatch(1); + + Runnable setterRunnable = () -> { + while (true) { + TestIndexed liveEntity = liveObjectService.get(TestIndexed.class, "id"); + liveEntity.setName1("2"); + } + }; + Runnable getterRunnable = () -> { + int steps = 1; + while (true) { + final TestIndexed liveEntity = liveObjectService.get(TestIndexed.class, "id"); + if (liveEntity.getName1() == null) { + System.out.println("IS NULL ON STEP " + steps); + latch.countDown(); + } + steps++; + } + }; + + try (ExecutorService pool = Executors.newFixedThreadPool(2)) { + pool.submit(setterRunnable); + pool.submit(getterRunnable); + + assertThat(latch.await(5, TimeUnit.SECONDS)).isFalse(); + + pool.shutdownNow(); + } + } + + @Test public void testFindGe() { RLiveObjectService s = redisson.getLiveObjectService();