This is an automated email from the ASF dual-hosted git repository.

ningjiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-pack.git

commit 26d89422521cd85f191ae4fda7aa1adb639a6edf
Author: Lei Zhang <coolbee...@gmail.com>
AuthorDate: Thu Aug 15 22:25:49 2019 +0800

    SCB-1438 Fix queries concurrent access error
---
 .../elasticsearch/ElasticsearchTransactionRepository.java  | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git 
a/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/repository/elasticsearch/ElasticsearchTransactionRepository.java
 
b/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/repository/elasticsearch/ElasticsearchTransactionRepository.java
index 8d49757..15c9cbd 100644
--- 
a/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/repository/elasticsearch/ElasticsearchTransactionRepository.java
+++ 
b/alpha/alpha-fsm/src/main/java/org/apache/servicecomb/pack/alpha/fsm/repository/elasticsearch/ElasticsearchTransactionRepository.java
@@ -70,7 +70,7 @@ public class ElasticsearchTransactionRepository implements 
TransactionRepository
   private int batchSizeCounter;
   private int refreshTime;
   private final List<IndexQuery> queries = new ArrayList<>();
-  private final static Boolean lock = true;
+  private final Boolean lock = true;
 
   public ElasticsearchTransactionRepository(
       ElasticsearchTemplate template, MetricsService metricsService, int 
batchSize,
@@ -89,12 +89,12 @@ public class ElasticsearchTransactionRepository implements 
TransactionRepository
 
   @Override
   public void send(GlobalTransaction transaction) throws Exception {
-    long begin = System.currentTimeMillis();
-    queries.add(convert(transaction));
-    batchSizeCounter++;
-    metricsService.metrics().doRepositoryReceived();
-    if (batchSize == 0 || batchSizeCounter == batchSize) {
-      synchronized (lock) {
+    synchronized (lock) {
+      long begin = System.currentTimeMillis();
+      queries.add(convert(transaction));
+      batchSizeCounter++;
+      metricsService.metrics().doRepositoryReceived();
+      if (batchSize == 0 || batchSizeCounter == batchSize) {
         save(begin);
         batchSizeCounter = 0;
       }

Reply via email to