4
4
import java .sql .SQLException ;
5
5
import java .time .Instant ;
6
6
import java .util .Optional ;
7
- import javax .annotation .PostConstruct ;
8
7
import javax .annotation .PreDestroy ;
9
8
import net .javacrumbs .shedlock .core .LockConfiguration ;
10
9
import net .javacrumbs .shedlock .core .LockProvider ;
15
14
import tech .ydb .coordination .CoordinationClient ;
16
15
import tech .ydb .coordination .CoordinationSession ;
17
16
import tech .ydb .coordination .SemaphoreLease ;
18
- import tech .ydb .coordination .settings .DescribeSemaphoreMode ;
19
17
import tech .ydb .core .Result ;
20
18
import tech .ydb .jdbc .YdbConnection ;
21
19
@@ -37,7 +35,6 @@ public YdbCoordinationServiceLockProvider(YdbConnection ydbConnection) {
37
35
this .coordinationClient = CoordinationClient .newClient (ydbConnection .getCtx ().getGrpcTransport ());
38
36
}
39
37
40
- @ PostConstruct
41
38
public void init () {
42
39
for (int i = 0 ; i < ATTEMPT_CREATE_NODE ; i ++) {
43
40
var status = coordinationClient .createNode (YDB_LOCK_NODE_NAME ).join ();
@@ -73,29 +70,6 @@ public Optional<SimpleLock> lock(LockConfiguration lockConfiguration) {
73
70
74
71
logger .info ("Instance[{}] is trying to become a leader..." , instanceInfo );
75
72
76
- var describeResult = coordinationSession .describeSemaphore (
77
- lockConfiguration .getName (),
78
- DescribeSemaphoreMode .WITH_OWNERS
79
- ).join ();
80
-
81
- if (describeResult .isSuccess ()) {
82
- var describe = describeResult .getValue ();
83
- var describePayload = new String (describe .getData (), StandardCharsets .UTF_8 );
84
-
85
- logger .debug ("Received DescribeSemaphore[Name={}, Data={}]" , describe .getName (), describePayload );
86
-
87
- Instant createdLeaderTimestampUTC = Instant .parse (describePayload .split ("," )[2 ].split ("=" )[1 ]);
88
-
89
- if (now .isAfter (createdLeaderTimestampUTC .plus (lockConfiguration .getLockAtMostFor ()))) {
90
- var deleteResult = coordinationSession .deleteSemaphore (describe .getName (), true ).join ();
91
- logger .debug ("Delete semaphore[Name={}] result: {}" , describe .getName (), deleteResult );
92
- }
93
- } else {
94
- // no success, ephemeral semaphore is not created
95
-
96
- logger .debug ("Semaphore[Name={}] not found" , lockConfiguration .getName ());
97
- }
98
-
99
73
Result <SemaphoreLease > semaphoreLease = coordinationSession .acquireEphemeralSemaphore (
100
74
lockConfiguration .getName (),
101
75
true ,
0 commit comments