This is an automated email from the ASF dual-hosted git repository.
xingtanzjr pushed a commit to branch ml_0729_test
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/ml_0729_test by this push:
new 40d07763c3 add synchronized
40d07763c3 is described below
commit 40d07763c32c08bf5a5a563887b253d722e5263a
Author: Jinrui.Zhang <[email protected]>
AuthorDate: Fri Jul 29 15:37:19 2022 +0800
add synchronized
---
.../db/consensus/statemachine/DataRegionStateMachine.java | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git
a/server/src/main/java/org/apache/iotdb/db/consensus/statemachine/DataRegionStateMachine.java
b/server/src/main/java/org/apache/iotdb/db/consensus/statemachine/DataRegionStateMachine.java
index b56586ee80..8bf7e77923 100644
---
a/server/src/main/java/org/apache/iotdb/db/consensus/statemachine/DataRegionStateMachine.java
+++
b/server/src/main/java/org/apache/iotdb/db/consensus/statemachine/DataRegionStateMachine.java
@@ -61,7 +61,7 @@ public class DataRegionStateMachine extends BaseStateMachine {
private DataRegion region;
private static final int MAX_REQUEST_CACHE_SIZE = 50;
- private PriorityQueue<InsertNodeWrapper> requestCache;
+ private final PriorityQueue<InsertNodeWrapper> requestCache;
public DataRegionStateMachine(DataRegion region) {
this.region = region;
@@ -111,11 +111,13 @@ public class DataRegionStateMachine extends
BaseStateMachine {
}
private InsertNode cacheAndGetLatestInsertNode(long syncIndex, InsertNode
insertNode) {
- requestCache.add(new InsertNodeWrapper(syncIndex, insertNode));
- if (requestCache.size() >= MAX_REQUEST_CACHE_SIZE) {
- return requestCache.poll().getInsertNode();
- } else {
- return null;
+ synchronized (requestCache) {
+ requestCache.add(new InsertNodeWrapper(syncIndex, insertNode));
+ if (requestCache.size() >= MAX_REQUEST_CACHE_SIZE) {
+ return requestCache.poll().getInsertNode();
+ } else {
+ return null;
+ }
}
}