提交 43730b78 编写于 作者: J Jaskey 提交者: dongeforever

[ROCKETMQ-96]Rename some temp variable and field closes apache/rocketmq#60

上级 c6741374
...@@ -48,7 +48,10 @@ public class ProcessQueue { ...@@ -48,7 +48,10 @@ public class ProcessQueue {
private final AtomicLong msgCount = new AtomicLong(); private final AtomicLong msgCount = new AtomicLong();
private final AtomicLong msgSize = new AtomicLong(); private final AtomicLong msgSize = new AtomicLong();
private final Lock lockConsume = new ReentrantLock(); private final Lock lockConsume = new ReentrantLock();
private final TreeMap<Long, MessageExt> msgTreeMapTemp = new TreeMap<Long, MessageExt>(); /**
* A subset of msgTreeMap, will only be used when orderly consume
*/
private final TreeMap<Long, MessageExt> consumingMsgOrderlyTreeMap = new TreeMap<Long, MessageExt>();
private final AtomicLong tryUnlockTimes = new AtomicLong(0); private final AtomicLong tryUnlockTimes = new AtomicLong(0);
private volatile long queueOffsetMax = 0L; private volatile long queueOffsetMax = 0L;
private volatile boolean dropped = false; private volatile boolean dropped = false;
...@@ -243,8 +246,8 @@ public class ProcessQueue { ...@@ -243,8 +246,8 @@ public class ProcessQueue {
try { try {
this.lockTreeMap.writeLock().lockInterruptibly(); this.lockTreeMap.writeLock().lockInterruptibly();
try { try {
this.msgTreeMap.putAll(this.msgTreeMapTemp); this.msgTreeMap.putAll(this.consumingMsgOrderlyTreeMap);
this.msgTreeMapTemp.clear(); this.consumingMsgOrderlyTreeMap.clear();
} finally { } finally {
this.lockTreeMap.writeLock().unlock(); this.lockTreeMap.writeLock().unlock();
} }
...@@ -257,12 +260,12 @@ public class ProcessQueue { ...@@ -257,12 +260,12 @@ public class ProcessQueue {
try { try {
this.lockTreeMap.writeLock().lockInterruptibly(); this.lockTreeMap.writeLock().lockInterruptibly();
try { try {
Long offset = this.msgTreeMapTemp.lastKey(); Long offset = this.consumingMsgOrderlyTreeMap.lastKey();
msgCount.addAndGet(0 - this.msgTreeMapTemp.size()); msgCount.addAndGet(0 - this.consumingMsgOrderlyTreeMap.size());
for (MessageExt msg : this.msgTreeMapTemp.values()) { for (MessageExt msg : this.consumingMsgOrderlyTreeMap.values()) {
msgSize.addAndGet(0 - msg.getBody().length); msgSize.addAndGet(0 - msg.getBody().length);
} }
this.msgTreeMapTemp.clear(); this.consumingMsgOrderlyTreeMap.clear();
if (offset != null) { if (offset != null) {
return offset + 1; return offset + 1;
} }
...@@ -281,7 +284,7 @@ public class ProcessQueue { ...@@ -281,7 +284,7 @@ public class ProcessQueue {
this.lockTreeMap.writeLock().lockInterruptibly(); this.lockTreeMap.writeLock().lockInterruptibly();
try { try {
for (MessageExt msg : msgs) { for (MessageExt msg : msgs) {
this.msgTreeMapTemp.remove(msg.getQueueOffset()); this.consumingMsgOrderlyTreeMap.remove(msg.getQueueOffset());
this.msgTreeMap.put(msg.getQueueOffset(), msg); this.msgTreeMap.put(msg.getQueueOffset(), msg);
} }
} finally { } finally {
...@@ -304,7 +307,7 @@ public class ProcessQueue { ...@@ -304,7 +307,7 @@ public class ProcessQueue {
Map.Entry<Long, MessageExt> entry = this.msgTreeMap.pollFirstEntry(); Map.Entry<Long, MessageExt> entry = this.msgTreeMap.pollFirstEntry();
if (entry != null) { if (entry != null) {
result.add(entry.getValue()); result.add(entry.getValue());
msgTreeMapTemp.put(entry.getKey(), entry.getValue()); consumingMsgOrderlyTreeMap.put(entry.getKey(), entry.getValue());
} else { } else {
break; break;
} }
...@@ -343,7 +346,7 @@ public class ProcessQueue { ...@@ -343,7 +346,7 @@ public class ProcessQueue {
this.lockTreeMap.writeLock().lockInterruptibly(); this.lockTreeMap.writeLock().lockInterruptibly();
try { try {
this.msgTreeMap.clear(); this.msgTreeMap.clear();
this.msgTreeMapTemp.clear(); this.consumingMsgOrderlyTreeMap.clear();
this.msgCount.set(0); this.msgCount.set(0);
this.msgSize.set(0); this.msgSize.set(0);
this.queueOffsetMax = 0L; this.queueOffsetMax = 0L;
...@@ -402,10 +405,10 @@ public class ProcessQueue { ...@@ -402,10 +405,10 @@ public class ProcessQueue {
info.setCachedMsgSizeInMiB((int) (this.msgSize.get() / (1024 * 1024))); info.setCachedMsgSizeInMiB((int) (this.msgSize.get() / (1024 * 1024)));
} }
if (!this.msgTreeMapTemp.isEmpty()) { if (!this.consumingMsgOrderlyTreeMap.isEmpty()) {
info.setTransactionMsgMinOffset(this.msgTreeMapTemp.firstKey()); info.setTransactionMsgMinOffset(this.consumingMsgOrderlyTreeMap.firstKey());
info.setTransactionMsgMaxOffset(this.msgTreeMapTemp.lastKey()); info.setTransactionMsgMaxOffset(this.consumingMsgOrderlyTreeMap.lastKey());
info.setTransactionMsgCount(this.msgTreeMapTemp.size()); info.setTransactionMsgCount(this.consumingMsgOrderlyTreeMap.size());
} }
info.setLocked(this.locked); info.setLocked(this.locked);
......
...@@ -454,9 +454,9 @@ public class DefaultMQProducerImpl implements MQProducerInner { ...@@ -454,9 +454,9 @@ public class DefaultMQProducerImpl implements MQProducerInner {
String[] brokersSent = new String[timesTotal]; String[] brokersSent = new String[timesTotal];
for (; times < timesTotal; times++) { for (; times < timesTotal; times++) {
String lastBrokerName = null == mq ? null : mq.getBrokerName(); String lastBrokerName = null == mq ? null : mq.getBrokerName();
MessageQueue tmpmq = this.selectOneMessageQueue(topicPublishInfo, lastBrokerName); MessageQueue mqSelected = this.selectOneMessageQueue(topicPublishInfo, lastBrokerName);
if (tmpmq != null) { if (mqSelected != null) {
mq = tmpmq; mq = mqSelected;
brokersSent[times] = mq.getBrokerName(); brokersSent[times] = mq.getBrokerName();
try { try {
beginTimestampPrev = System.currentTimeMillis(); beginTimestampPrev = System.currentTimeMillis();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册