diff --git a/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java b/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java index 8b9750464f12790dcd01ddf75f0c786648df190a..ddae12effa392ceb07f461fc3c6a27e0402d3075 100644 --- a/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java +++ b/store/src/main/java/org/apache/rocketmq/store/ha/HAConnection.java @@ -300,6 +300,8 @@ public class HAConnection { } } + HAConnection.this.haService.getWaitNotifyObject().removeFromWaitingThreadTable(); + if (this.selectMappedBufferResult != null) { this.selectMappedBufferResult.release(); } diff --git a/store/src/main/java/org/apache/rocketmq/store/ha/WaitNotifyObject.java b/store/src/main/java/org/apache/rocketmq/store/ha/WaitNotifyObject.java index 6aba37529a4bc22eddd4c11762877df3b4115615..a4c34cb08144af4be93f9c8c18e441096991c1bb 100644 --- a/store/src/main/java/org/apache/rocketmq/store/ha/WaitNotifyObject.java +++ b/store/src/main/java/org/apache/rocketmq/store/ha/WaitNotifyObject.java @@ -96,4 +96,11 @@ public class WaitNotifyObject { } } } + + public void removeFromWaitingThreadTable() { + long currentThreadId = Thread.currentThread().getId(); + synchronized (this) { + this.waitingThreadTable.remove(currentThreadId); + } + } } diff --git a/store/src/test/java/org/apache/rocketmq/store/ha/WaitNotifyObjectTest.java b/store/src/test/java/org/apache/rocketmq/store/ha/WaitNotifyObjectTest.java new file mode 100644 index 0000000000000000000000000000000000000000..99e44320b3c9db1a0479337e78ae04b4d7b561f2 --- /dev/null +++ b/store/src/test/java/org/apache/rocketmq/store/ha/WaitNotifyObjectTest.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.rocketmq.store.ha; + +import org.junit.Assert; +import org.junit.Test; + +import static org.junit.Assert.*; + +public class WaitNotifyObjectTest { + @Test + public void removeFromWaitingThreadTable() throws Exception { + final WaitNotifyObject waitNotifyObject = new WaitNotifyObject(); + for (int i = 0; i < 5; i++) { + Thread t = new Thread(new Runnable() { + @Override + public void run() { + waitNotifyObject.allWaitForRunning(100); + waitNotifyObject.removeFromWaitingThreadTable(); + } + }); + t.start(); + t.join(); + } + Assert.assertEquals(0, waitNotifyObject.waitingThreadTable.size()); + } + +}