Skip to content

Commit eb6106c

Browse files
feat: micro fix
1 parent 4385fe6 commit eb6106c

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

shedlock-ydb/src/main/java/tech/ydb/lock/provider/YdbCoordinationServiceLockProvider.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ public class YdbCoordinationServiceLockProvider implements LockProvider {
2626
private static final Logger logger = LoggerFactory.getLogger(YdbCoordinationServiceLockProvider.class);
2727
private static final String YDB_LOCK_NODE_NAME = "shared-lock-ydb";
2828
private static final int ATTEMPT_CREATE_NODE = 10;
29-
private static final String INSTANCE_INFO =
30-
"Hostname=" + Utils.getHostname() + ", " + "Current PID=" + ProcessHandle.current().pid();
31-
private static final byte[] INSTANCE_INFO_BYTES = INSTANCE_INFO.getBytes(StandardCharsets.UTF_8);
3229

3330
private final YdbConnection ydbConnection;
3431
private final CoordinationClient coordinationClient;
@@ -102,26 +99,26 @@ public Optional<SimpleLock> lock(LockConfiguration lockConfiguration) {
10299
Result<SemaphoreLease> semaphoreLease = coordinationSession.acquireEphemeralSemaphore(
103100
lockConfiguration.getName(),
104101
true,
105-
INSTANCE_INFO_BYTES,
102+
instanceInfo.getBytes(StandardCharsets.UTF_8),
106103
lockConfiguration.getLockAtMostFor()
107104
).join();
108105

109106
if (semaphoreLease.isSuccess()) {
110-
logger.info("Instance[{}] acquired semaphore[SemaphoreName={}]", INSTANCE_INFO,
107+
logger.info("Instance[{}] acquired semaphore[SemaphoreName={}]", instanceInfo,
111108
semaphoreLease.getValue().getSemaphoreName());
112109

113-
return Optional.of(new YdbSimpleLock(semaphoreLease.getValue()));
110+
return Optional.of(new YdbSimpleLock(semaphoreLease.getValue(), instanceInfo));
114111
} else {
115-
logger.info("Instance[{}] did not acquire semaphore", INSTANCE_INFO);
112+
logger.info("Instance[{}] did not acquire semaphore", instanceInfo);
116113

117114
return Optional.empty();
118115
}
119116
}
120117

121-
private record YdbSimpleLock(SemaphoreLease semaphoreLease) implements SimpleLock {
118+
private record YdbSimpleLock(SemaphoreLease semaphoreLease, String metaInfo) implements SimpleLock {
122119
@Override
123120
public void unlock() {
124-
logger.info("Instance[{}] released semaphore[SemaphoreName={}]", INSTANCE_INFO, semaphoreLease.getSemaphoreName());
121+
logger.info("Instance[{}] released semaphore[SemaphoreName={}]", metaInfo, semaphoreLease.getSemaphoreName());
125122

126123
semaphoreLease.release().join();
127124
}

0 commit comments

Comments
 (0)