@@ -26,9 +26,6 @@ public class YdbCoordinationServiceLockProvider implements LockProvider {
26
26
private static final Logger logger = LoggerFactory .getLogger (YdbCoordinationServiceLockProvider .class );
27
27
private static final String YDB_LOCK_NODE_NAME = "shared-lock-ydb" ;
28
28
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 );
32
29
33
30
private final YdbConnection ydbConnection ;
34
31
private final CoordinationClient coordinationClient ;
@@ -102,26 +99,26 @@ public Optional<SimpleLock> lock(LockConfiguration lockConfiguration) {
102
99
Result <SemaphoreLease > semaphoreLease = coordinationSession .acquireEphemeralSemaphore (
103
100
lockConfiguration .getName (),
104
101
true ,
105
- INSTANCE_INFO_BYTES ,
102
+ instanceInfo . getBytes ( StandardCharsets . UTF_8 ) ,
106
103
lockConfiguration .getLockAtMostFor ()
107
104
).join ();
108
105
109
106
if (semaphoreLease .isSuccess ()) {
110
- logger .info ("Instance[{}] acquired semaphore[SemaphoreName={}]" , INSTANCE_INFO ,
107
+ logger .info ("Instance[{}] acquired semaphore[SemaphoreName={}]" , instanceInfo ,
111
108
semaphoreLease .getValue ().getSemaphoreName ());
112
109
113
- return Optional .of (new YdbSimpleLock (semaphoreLease .getValue ()));
110
+ return Optional .of (new YdbSimpleLock (semaphoreLease .getValue (), instanceInfo ));
114
111
} else {
115
- logger .info ("Instance[{}] did not acquire semaphore" , INSTANCE_INFO );
112
+ logger .info ("Instance[{}] did not acquire semaphore" , instanceInfo );
116
113
117
114
return Optional .empty ();
118
115
}
119
116
}
120
117
121
- private record YdbSimpleLock (SemaphoreLease semaphoreLease ) implements SimpleLock {
118
+ private record YdbSimpleLock (SemaphoreLease semaphoreLease , String metaInfo ) implements SimpleLock {
122
119
@ Override
123
120
public void unlock () {
124
- logger .info ("Instance[{}] released semaphore[SemaphoreName={}]" , INSTANCE_INFO , semaphoreLease .getSemaphoreName ());
121
+ logger .info ("Instance[{}] released semaphore[SemaphoreName={}]" , metaInfo , semaphoreLease .getSemaphoreName ());
125
122
126
123
semaphoreLease .release ().join ();
127
124
}
0 commit comments