From 7682a1d1a092f9b7db3bae32b0aaf9afe2b141e8 Mon Sep 17 00:00:00 2001 From: Kirill Kurdyukov Date: Thu, 14 Nov 2024 19:59:28 +0300 Subject: [PATCH] feat: micro fix --- .../YdbCoordinationServiceLockProvider.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/shedlock-ydb/src/main/java/tech/ydb/lock/provider/YdbCoordinationServiceLockProvider.java b/shedlock-ydb/src/main/java/tech/ydb/lock/provider/YdbCoordinationServiceLockProvider.java index d198486..4ef66c6 100644 --- a/shedlock-ydb/src/main/java/tech/ydb/lock/provider/YdbCoordinationServiceLockProvider.java +++ b/shedlock-ydb/src/main/java/tech/ydb/lock/provider/YdbCoordinationServiceLockProvider.java @@ -16,6 +16,7 @@ import tech.ydb.coordination.CoordinationSession; import tech.ydb.coordination.SemaphoreLease; import tech.ydb.coordination.settings.CoordinationSessionSettings; +import tech.ydb.coordination.settings.DescribeSemaphoreMode; import tech.ydb.core.Result; import tech.ydb.jdbc.YdbConnection; @@ -64,12 +65,27 @@ public Optional lock(LockConfiguration lockConfiguration) { var statusCS = coordinationSession.connect().join(); if (!statusCS.isSuccess()) { - logger.info("Failed creating coordination session [{}]", coordinationSession); + logger.warn("Failed creating coordination session [{}]", coordinationSession); return Optional.empty(); } - logger.info("Created coordination node session [{}]", coordinationSession); + logger.debug("Created coordination node session [{}]", coordinationSession); + + var describeResult = coordinationSession.describeSemaphore( + lockConfiguration.getName(), + DescribeSemaphoreMode.WITH_OWNERS + ).join(); + + if (describeResult.isSuccess()) { + var describe = describeResult.getValue(); + + if (!describe.getOwnersList().isEmpty()) { + var describePayload = new String(describe.getOwnersList().get(0).getData(), StandardCharsets.UTF_8); + + logger.info("Received DescribeSemaphore[Name={}, Data={}]", describe.getName(), describePayload); + } + } Result semaphoreLease = coordinationSession.acquireEphemeralSemaphore( lockConfiguration.getName(), @@ -81,12 +97,12 @@ public Optional lock(LockConfiguration lockConfiguration) { logger.debug(coordinationSession.toString()); if (semaphoreLease.isSuccess()) { - logger.info("Instance[{}] acquired semaphore[SemaphoreName={}]", instanceInfo, + logger.debug("Instance[{}] acquired semaphore [SemaphoreName={}]", instanceInfo, semaphoreLease.getValue().getSemaphoreName()); return Optional.of(new YdbSimpleLock(semaphoreLease.getValue(), instanceInfo, coordinationSession)); } else { - logger.info("Instance[{}] did not acquire semaphore", instanceInfo); + logger.debug("Instance[{}] did not acquire semaphore", instanceInfo); return Optional.empty(); } @@ -96,7 +112,7 @@ private record YdbSimpleLock(SemaphoreLease semaphoreLease, String metaInfo, CoordinationSession coordinationSession) implements SimpleLock { @Override public void unlock() { - logger.info("Instance[{}] released semaphore[SemaphoreName={}]", metaInfo, semaphoreLease.getSemaphoreName()); + logger.info("Instance[{}] released semaphore [SemaphoreName={}]", metaInfo, semaphoreLease.getSemaphoreName()); semaphoreLease.release().join();