Skip to content

Commit 30b9301

Browse files
committed
Acquire the lock only when the timerWheelSnapshotFlush is true
Change-Id: I1c7c2895efebfef0185411c0630bbd2da23ce3c7
1 parent d59ee1e commit 30b9301

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

store/src/main/java/org/apache/rocketmq/store/timer/TimerMessageStore.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,7 +1500,11 @@ protected void fetchAndPutTimerRequest() throws Exception {
15001500
CountDownLatch latch = new CountDownLatch(trs.size());
15011501
for (TimerRequest req : trs) {
15021502
req.setLatch(latch);
1503-
synchronized (lockWhenFlush) {
1503+
if (storeConfig.isTimerWheelSnapshotFlush()) {
1504+
synchronized (lockWhenFlush) {
1505+
this.putMessageToTimerWheel(req);
1506+
}
1507+
} else {
15041508
this.putMessageToTimerWheel(req);
15051509
}
15061510
}
@@ -1845,17 +1849,20 @@ public void run() {
18451849
long lastSnapshotTime = System.currentTimeMillis();
18461850

18471851
public void flush() throws IOException {
1848-
synchronized (lockWhenFlush) {
1849-
prepareTimerCheckPoint();
1850-
timerLog.getMappedFileQueue().flush(0);
1851-
if (storeConfig.isTimerWheelSnapshotFlush()) {
1852+
if (storeConfig.isTimerWheelSnapshotFlush()) {
1853+
synchronized (lockWhenFlush) {
1854+
prepareTimerCheckPoint();
1855+
timerLog.getMappedFileQueue().flush(0);
18521856
if (System.currentTimeMillis() - lastSnapshotTime > storeConfig.getTimerWheelSnapshotIntervalMs()) {
18531857
lastSnapshotTime = System.currentTimeMillis();
18541858
timerWheel.backup(timerLog.getMappedFileQueue().getFlushedWhere());
18551859
}
1856-
} else {
1857-
timerWheel.flush();
1860+
timerCheckpoint.flush();
18581861
}
1862+
} else {
1863+
prepareTimerCheckPoint();
1864+
timerLog.getMappedFileQueue().flush(0);
1865+
timerWheel.flush();
18591866
timerCheckpoint.flush();
18601867
}
18611868
if (System.currentTimeMillis() - start > storeConfig.getTimerProgressLogIntervalMs()) {

0 commit comments

Comments
 (0)