You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by "lizhimins (via GitHub)" <gi...@apache.org> on 2023/06/30 02:58:08 UTC
[GitHub] [rocketmq] lizhimins commented on a diff in pull request #6783: [ISSUE #6782]Optimize and streamline ConsumeQueueStore#doFindOrCreateConsumeQueue code
lizhimins commented on code in PR #6783:
URL: https://github.com/apache/rocketmq/pull/6783#discussion_r1247358914
##########
store/src/main/java/org/apache/rocketmq/store/queue/ConsumeQueueStore.java:
##########
@@ -314,50 +315,42 @@ public ConsumeQueueInterface findOrCreateConsumeQueue(String topic, int queueId)
return doFindOrCreateConsumeQueue(topic, queueId);
}
+ /**
+ * Finds or creates a ConsumeQueueInterface for the given topic and queue ID.
+ *
+ * @param topic The topic for which the ConsumeQueueInterface.
+ * @param queueId The ID of the queue for which the ConsumeQueueInterface.
+ * @return The found or newly created ConsumeQueueInterface.
+ */
private ConsumeQueueInterface doFindOrCreateConsumeQueue(String topic, int queueId) {
- ConcurrentMap<Integer, ConsumeQueueInterface> map = consumeQueueTable.get(topic);
- if (null == map) {
- ConcurrentMap<Integer, ConsumeQueueInterface> newMap = new ConcurrentHashMap<>(128);
- ConcurrentMap<Integer, ConsumeQueueInterface> oldMap = consumeQueueTable.putIfAbsent(topic, newMap);
- if (oldMap != null) {
- map = oldMap;
- } else {
- map = newMap;
- }
- }
+ ConcurrentMap<Integer, ConsumeQueueInterface> map = ConcurrentHashMapUtils.computeIfAbsent(consumeQueueTable, topic, k -> new ConcurrentHashMap<>(128));
Review Comment:
jdk8 的 computeIfAbsent 性能有问题
--
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: commits-unsubscribe@rocketmq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org