Skip to content

Commit a9e3532

Browse files
authored
Add the configuration of topicQueueLock number to better support different scenarios (#7317)
1 parent 0dbd077 commit a9e3532

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

store/src/main/java/org/apache/rocketmq/store/CommitLog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ protected PutMessageThreadLocal initialValue() {
122122

123123
this.flushDiskWatcher = new FlushDiskWatcher();
124124

125-
this.topicQueueLock = new TopicQueueLock();
125+
this.topicQueueLock = new TopicQueueLock(messageStore.getMessageStoreConfig().getTopicQueueLockNum());
126126

127127
this.commitLogSize = messageStore.getMessageStoreConfig().getMappedFileSizeCommitLog();
128128
}

store/src/main/java/org/apache/rocketmq/store/TopicQueueLock.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@ public TopicQueueLock() {
3434
}
3535
}
3636

37+
public TopicQueueLock(int size) {
38+
this.size = size;
39+
this.lockList = new ArrayList<>(size);
40+
for (int i = 0; i < this.size; i++) {
41+
this.lockList.add(new ReentrantLock());
42+
}
43+
}
44+
3745
public void lock(String topicQueueKey) {
3846
Lock lock = this.lockList.get((topicQueueKey.hashCode() & 0x7fffffff) % this.size);
3947
lock.lock();

store/src/main/java/org/apache/rocketmq/store/config/MessageStoreConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ public class MessageStoreConfig {
401401
private long memTableFlushInterval = 60 * 60 * 1000L;
402402
private boolean enableRocksDBLog = false;
403403

404+
private int topicQueueLockNum = 32;
405+
404406
public boolean isDebugLockEnable() {
405407
return debugLockEnable;
406408
}
@@ -1751,4 +1753,12 @@ public boolean isEnableRocksDBLog() {
17511753
public void setEnableRocksDBLog(boolean enableRocksDBLog) {
17521754
this.enableRocksDBLog = enableRocksDBLog;
17531755
}
1756+
1757+
public int getTopicQueueLockNum() {
1758+
return topicQueueLockNum;
1759+
}
1760+
1761+
public void setTopicQueueLockNum(int topicQueueLockNum) {
1762+
this.topicQueueLockNum = topicQueueLockNum;
1763+
}
17541764
}

0 commit comments

Comments
 (0)