From f6fb0a91cda199e59cece4319cedad0befce8bdc Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Mon, 25 Nov 2019 10:14:40 +0200 Subject: [PATCH] Add some debug for GraphClientImpl2 for deadlocks gitlab #426 Change-Id: I1438bd52782848b4d9edc7477283194a0e8f3ee2 --- .../org/simantics/acorn/GraphClientImpl2.java | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/bundles/org.simantics.acorn/src/org/simantics/acorn/GraphClientImpl2.java b/bundles/org.simantics.acorn/src/org/simantics/acorn/GraphClientImpl2.java index 172fdd103..d8b6552ff 100644 --- a/bundles/org.simantics.acorn/src/org/simantics/acorn/GraphClientImpl2.java +++ b/bundles/org.simantics.acorn/src/org/simantics/acorn/GraphClientImpl2.java @@ -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); } -- 2.47.1