From 130c85c3cdc8c0a72552b1b65e711213493a8071 Mon Sep 17 00:00:00 2001 From: Li Zhanhui Date: Mon, 28 May 2018 17:10:33 +0800 Subject: [PATCH] Revert "Fix Concurrent issue of StoreStatsService" This reverts commit fdc6e87cbe7adb8bc8f5991e06392eee73bc5151. --- .../rocketmq/store/StoreStatsService.java | 15 +--- .../rocketmq/store/StoreStatsServiceTest.java | 77 ------------------- 2 files changed, 4 insertions(+), 88 deletions(-) delete mode 100644 store/src/test/java/org/apache/rocketmq/store/StoreStatsServiceTest.java diff --git a/store/src/main/java/org/apache/rocketmq/store/StoreStatsService.java b/store/src/main/java/org/apache/rocketmq/store/StoreStatsService.java index 8862fd7e..586947ce 100644 --- a/store/src/main/java/org/apache/rocketmq/store/StoreStatsService.java +++ b/store/src/main/java/org/apache/rocketmq/store/StoreStatsService.java @@ -21,7 +21,6 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantLock; import org.apache.rocketmq.common.ServiceThread; @@ -43,9 +42,9 @@ public class StoreStatsService extends ServiceThread { private final AtomicLong putMessageFailedTimes = new AtomicLong(0); - private final ConcurrentMap putMessageTopicTimesTotal = + private final Map putMessageTopicTimesTotal = new ConcurrentHashMap(128); - private final ConcurrentMap putMessageTopicSizeTotal = + private final Map putMessageTopicSizeTotal = new ConcurrentHashMap(128); private final AtomicLong getMessageTimesTotalFound = new AtomicLong(0); @@ -546,10 +545,7 @@ public class StoreStatsService extends ServiceThread { AtomicLong rs = putMessageTopicSizeTotal.get(topic); if (null == rs) { rs = new AtomicLong(0); - AtomicLong previous = putMessageTopicSizeTotal.putIfAbsent(topic, rs); - if(previous != null){ - rs = previous; - } + putMessageTopicSizeTotal.put(topic, rs); } return rs; } @@ -558,10 +554,7 @@ public class StoreStatsService extends ServiceThread { AtomicLong rs = putMessageTopicTimesTotal.get(topic); if (null == rs) { rs = new AtomicLong(0); - AtomicLong previous = putMessageTopicTimesTotal.putIfAbsent(topic, rs); - if(previous != null){ - rs = previous; - } + putMessageTopicTimesTotal.put(topic, rs); } return rs; } diff --git a/store/src/test/java/org/apache/rocketmq/store/StoreStatsServiceTest.java b/store/src/test/java/org/apache/rocketmq/store/StoreStatsServiceTest.java deleted file mode 100644 index bb39bf95..00000000 --- a/store/src/test/java/org/apache/rocketmq/store/StoreStatsServiceTest.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.apache.rocketmq.store; - -import java.util.concurrent.BrokenBarrierException; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.CyclicBarrier; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; -import org.junit.Test; - -/** - * @author song - */ -public class StoreStatsServiceTest { - - @Test - public void getSinglePutMessageTopicSizeTotal() throws Exception { - final StoreStatsService storeStatsService = new StoreStatsService(); - int num = Runtime.getRuntime().availableProcessors() * 2; - for (int j = 0; j < 100; j++) { - final AtomicReference reference = new AtomicReference<>(null); - final CountDownLatch latch = new CountDownLatch(num); - final CyclicBarrier barrier = new CyclicBarrier(num); - for (int i = 0; i < num; i++) { - new Thread(new Runnable() { - @Override - public void run() { - try { - barrier.await(); - AtomicLong atomicLong = storeStatsService.getSinglePutMessageTopicSizeTotal("test"); - if(reference.compareAndSet(null,atomicLong)){ - }else if (reference.get() != atomicLong){ - throw new RuntimeException("Reference should be same!"); - } - } catch (InterruptedException | BrokenBarrierException e) { - e.printStackTrace(); - }finally { - latch.countDown(); - } - } - }).start(); - } - latch.await(); - } - } - - @Test - public void getSinglePutMessageTopicTimesTotal() throws Exception { - final StoreStatsService storeStatsService = new StoreStatsService(); - int num = Runtime.getRuntime().availableProcessors() * 2; - for (int j = 0; j < 100; j++) { - final AtomicReference reference = new AtomicReference<>(null); - final CountDownLatch latch = new CountDownLatch(num); - final CyclicBarrier barrier = new CyclicBarrier(num); - for (int i = 0; i < num; i++) { - new Thread(new Runnable() { - @Override - public void run() { - try { - barrier.await(); - AtomicLong atomicLong = storeStatsService.getSinglePutMessageTopicTimesTotal("test"); - if(reference.compareAndSet(null,atomicLong)){ - }else if (reference.get() != atomicLong){ - throw new RuntimeException("Reference should be same!"); - } - } catch (InterruptedException | BrokenBarrierException e) { - e.printStackTrace(); - }finally { - latch.countDown(); - } - } - }).start(); - } - latch.await(); - } - } - -} \ No newline at end of file -- GitLab