From 31639ac11cc90c554b5303199c2da6fedc008d7b Mon Sep 17 00:00:00 2001 From: PatrikBuhr Date: Thu, 10 Feb 2022 11:17:34 +0100 Subject: NONRTRIC Improved traces Improved traces Issue-ID: CCSDK-3560 Signed-off-by: PatrikBuhr Change-Id: I1ef76b859e24f4ea503c8e28e503528c98de4342 --- .../a1policymanagementservice/repository/Lock.java | 34 +++++++++++++++++----- .../a1policymanagementservice/repository/Ric.java | 3 +- .../repository/LockTest.java | 4 +-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java index 18507ac2..46033a4a 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Lock.java @@ -45,6 +45,7 @@ public class Lock { private int lockCounter = 0; final Queue lockRequestQueue = new LinkedList<>(); private static AsynchCallbackExecutor callbackProcessor = new AsynchCallbackExecutor(); + private final String label; public enum LockType { EXCLUSIVE, SHARED @@ -63,6 +64,7 @@ public class Lock { Grant(Lock lock, String label) { this.lock = lock; this.label = label; + logger.trace("Lock granted {}:{}", lock.label, this.label); } /** @@ -71,26 +73,41 @@ public class Lock { * @return the lock */ public Mono unlock() { - check(); - return this.lock.unlock(); + if (!isUnlocked()) { + logger.trace("Unlocking lock {}:{}", lock.label, this.label); + return this.lock.unlock(); + } + return Mono.just(this.lock); } /** * Synchronuous unlocking */ public void unlockBlocking() { - check(); - this.lock.unlockBlocking(); + if (!isUnlocked()) { + logger.trace("Unlocking lock {}:{}", lock.label, this.label); + this.lock.unlockBlocking(); + } } - private void check() { + private boolean isUnlocked() { if (unlocked) { - logger.error("Lock already unlocked"); + logger.debug("Lock {}:{} already unlocked", lock.label, this.label); + return true; } unlocked = true; + return false; } } + /** + * + * @param label a label attached to the lock. For troubleshooting. + */ + public Lock(String label) { + this.label = label; + } + /** * Reactive lock. The Lock will be emitted when the lock is granted * @@ -140,7 +157,7 @@ public class Lock { @Override public synchronized String toString() { - return "Lock cnt: " + this.lockCounter + " exclusive: " + this.isExclusive + " queued: " + return "Lock " + this.label + ", cnt: " + this.lockCounter + ", exclusive: " + this.isExclusive + ", queued: " + this.lockRequestQueue.size(); } @@ -164,6 +181,7 @@ public class Lock { } private synchronized void addToQueue(MonoSink callback, LockType lockType, String label) { + logger.trace("Lock request queued {}:{}", label, this.label); lockRequestQueue.add(new LockRequest(callback, lockType, this, label)); } @@ -172,7 +190,7 @@ public class Lock { try { this.wait(); } catch (InterruptedException e) { - logger.warn("waitForUnlock interrupted", e); + logger.warn("waitForUnlock interrupted " + this.label, e); Thread.currentThread().interrupt(); } } diff --git a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java index 8eca6be9..f43737f5 100644 --- a/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java +++ b/a1-policy-management/src/main/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/Ric.java @@ -45,7 +45,7 @@ public class Ric { private A1ProtocolType protocolVersion = A1ProtocolType.UNKNOWN; @Getter - private final Lock lock = new Lock(); + private final Lock lock; /** * Creates the Ric. Initial state is {@link RicState.UNDEFINED}. @@ -54,6 +54,7 @@ public class Ric { */ public Ric(RicConfig ricConfig) { this.ricConfig = ricConfig; + this.lock = new Lock(ricConfig.ricId()); } public String id() { diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/LockTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/LockTest.java index 79879446..3ea0fe53 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/LockTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/repository/LockTest.java @@ -65,7 +65,7 @@ class LockTest { @Test void testLock() throws IOException, ServiceException { - Lock lock = new Lock(); + Lock lock = new Lock("l1"); Lock.Grant grant = lock.lockBlocking(LockType.SHARED, "test"); grant.unlockBlocking(); assertThat(grant.getLabel()).isEqualTo("test"); @@ -81,7 +81,7 @@ class LockTest { @Test void testReactiveLock() { - Lock lock = new Lock(); + Lock lock = new Lock("l1"); Mono l0 = lock.lock(LockType.EXCLUSIVE, "1").doOnNext(grant -> asynchUnlock(grant, lock)); Mono l1 = lock.lock(LockType.SHARED, "2").doOnNext(grant -> asynchUnlock(grant, lock)); -- cgit 1.2.3-korg