]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Add some debug for GraphClientImpl2 for deadlocks 14/3614/1
authorjsimomaa <jani.simomaa@gmail.com>
Mon, 25 Nov 2019 08:14:40 +0000 (10:14 +0200)
committerjsimomaa <jani.simomaa@gmail.com>
Mon, 25 Nov 2019 08:14:40 +0000 (10:14 +0200)
gitlab #426

Change-Id: I1438bd52782848b4d9edc7477283194a0e8f3ee2

bundles/org.simantics.acorn/src/org/simantics/acorn/GraphClientImpl2.java

index 172fdd103150f28b88fac4ce604a74723e49b504..d8b6552ffc68bbc40c90788766142ff687ccba08 100644 (file)
@@ -17,8 +17,6 @@ import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.LinkedList;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
@@ -286,6 +284,11 @@ public class GraphClientImpl2 implements Database.Session {
                        this.state = state;
                        this.semaphore = semaphore;
                }
+               
+               @Override
+               public String toString() {
+                       return getClass().getSimpleName() + "[state=" + state + ", semaphore=" + semaphore + "]";
+               }
        }
 
        private class TransactionManager {
@@ -388,6 +391,7 @@ public class GraphClientImpl2 implements Database.Session {
                        return req;
                }
 
+               private long askWriteTransactionCount = 0;
                /*
                 * This method cannot be synchronized since it waits and must support multiple entries
                 * by query thread(s) and internal transactions such as snapshot saver
@@ -398,7 +402,25 @@ public class GraphClientImpl2 implements Database.Session {
                        TransactionRequest req = queue(TransactionState.WRITE, semaphore);
 
                        try {
-                               semaphore.acquire();
+                               while (true) {
+                                       boolean acquired = semaphore.tryAcquire(1, TimeUnit.MINUTES);
+                                       if (!acquired) {
+                                               if (askWriteTransactionCount < 10) {
+                                                       LOGGER.error("Could not acquire semaphore for askWriteTransaction for TransactionRequest {}", req);
+                                                       LOGGER.error("Current clusters.state.headChangeSetId is {}", clusters.state.headChangeSetId);
+                                                       LOGGER.error("Current clusters.state.transactionId is {}", clusters.state.transactionId);
+                                                       LOGGER.error("Current amount of requests is {}", requests.size());
+                                                       if (requests.size() < 100) {
+                                                               LOGGER.error("Current requests {}", requests);
+                                                       }
+                                                       LOGGER.error("Current transaction state is {}", currentTransactionState);
+                                                       askWriteTransactionCount++;
+                                               }
+                                       } else {
+                                               askWriteTransactionCount = 0;
+                                               break;
+                                       }
+                               }
                        } catch (InterruptedException e) {
                                throw new IllegalAcornStateException(e);
                        }