Skip to content

Commit a871011

Browse files
metanetmdogan
authored andcommitted
More on RaftLock operation timeout fixes
1 parent fdd134c commit a871011

13 files changed

Lines changed: 210 additions & 139 deletions

File tree

hazelcast-raft-client/src/main/java/com/hazelcast/raft/service/lock/client/RaftLockProxy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import com.hazelcast.raft.impl.RaftGroupIdImpl;
3131
import com.hazelcast.raft.impl.session.SessionExpiredException;
3232
import com.hazelcast.raft.service.lock.RaftLockService;
33-
import com.hazelcast.raft.service.lock.exception.LockRequestCancelledException;
33+
import com.hazelcast.raft.service.exception.WaitKeyCancelledException;
3434
import com.hazelcast.raft.service.session.SessionAwareProxy;
3535
import com.hazelcast.raft.service.session.SessionManagerProvider;
3636
import com.hazelcast.spi.InternalCompletableFuture;
@@ -133,7 +133,7 @@ public boolean tryLock(long time, TimeUnit unit) {
133133
releaseSession(sessionId);
134134
}
135135
return locked;
136-
} catch (LockRequestCancelledException e) {
136+
} catch (WaitKeyCancelledException e) {
137137
return false;
138138
} catch (SessionExpiredException e) {
139139
invalidateSession(sessionId);

hazelcast-raft-client/src/test/java/com/hazelcast/raft/service/lock/client/RaftFencedLockClientBasicTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.hazelcast.raft.impl.session.SessionExpiredException;
77
import com.hazelcast.raft.service.lock.FencedLock;
88
import com.hazelcast.raft.service.lock.RaftFencedLockBasicTest;
9-
import com.hazelcast.raft.service.lock.exception.LockRequestCancelledException;
9+
import com.hazelcast.raft.service.exception.WaitKeyCancelledException;
1010
import com.hazelcast.raft.service.session.AbstractSessionManager;
1111
import com.hazelcast.raft.service.session.SessionManagerProvider;
1212
import com.hazelcast.test.HazelcastSerialClassRunner;
@@ -34,7 +34,7 @@ protected HazelcastInstance[] createInstances() {
3434
lockInstance = f.newHazelcastClient();
3535
HazelcastClientInstanceImpl client = getClient(lockInstance);
3636
SessionExpiredException.register(client.getClientExceptionFactory());
37-
LockRequestCancelledException.register(client.getClientExceptionFactory());
37+
WaitKeyCancelledException.register(client.getClientExceptionFactory());
3838
return instances;
3939
}
4040

hazelcast-raft-client/src/test/java/com/hazelcast/raft/service/lock/client/RaftLockClientBasicTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import com.hazelcast.raft.RaftGroupId;
77
import com.hazelcast.raft.impl.session.SessionExpiredException;
88
import com.hazelcast.raft.service.lock.RaftLockBasicTest;
9-
import com.hazelcast.raft.service.lock.exception.LockRequestCancelledException;
9+
import com.hazelcast.raft.service.exception.WaitKeyCancelledException;
1010
import com.hazelcast.raft.service.session.AbstractSessionManager;
1111
import com.hazelcast.raft.service.session.SessionManagerProvider;
1212
import com.hazelcast.test.HazelcastSerialClassRunner;
@@ -36,7 +36,7 @@ protected HazelcastInstance[] createInstances() {
3636
TestHazelcastFactory f = (TestHazelcastFactory) factory;
3737
client = f.newHazelcastClient();
3838
SessionExpiredException.register(getClient(client).getClientExceptionFactory());
39-
LockRequestCancelledException.register(getClient(client).getClientExceptionFactory());
39+
WaitKeyCancelledException.register(getClient(client).getClientExceptionFactory());
4040
return instances;
4141
}
4242

hazelcast-raft-dataservices/src/main/java/com/hazelcast/raft/service/atomiclong/proxy/RaftAtomicLongProxy.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ public class RaftAtomicLongProxy implements IAtomicLong {
5050

5151
private final String name;
5252
private final RaftGroupId groupId;
53-
private final RaftInvocationManager raftInvocationManager;
53+
private final RaftInvocationManager invocationManager;
5454

5555
public RaftAtomicLongProxy(RaftInvocationManager invocationManager, RaftGroupId groupId, String name) {
5656
this.name = name;
5757
this.groupId = groupId;
58-
this.raftInvocationManager = invocationManager;
58+
this.invocationManager = invocationManager;
5959
}
6060

6161
@Override
@@ -105,7 +105,7 @@ public void set(long newValue) {
105105

106106
@Override
107107
public InternalCompletableFuture<Long> addAndGetAsync(final long delta) {
108-
return raftInvocationManager.invoke(groupId, new AddAndGetOp(name, delta));
108+
return invocationManager.invoke(groupId, new AddAndGetOp(name, delta));
109109
}
110110

111111
@Override
@@ -120,12 +120,12 @@ public InternalCompletableFuture<Long> decrementAndGetAsync() {
120120

121121
@Override
122122
public InternalCompletableFuture<Boolean> compareAndSetAsync(final long expect, final long update) {
123-
return raftInvocationManager.invoke(groupId, new CompareAndSetOp(name, expect, update));
123+
return invocationManager.invoke(groupId, new CompareAndSetOp(name, expect, update));
124124
}
125125

126126
@Override
127127
public InternalCompletableFuture<Long> getAndAddAsync(final long delta) {
128-
return raftInvocationManager.invoke(groupId, new GetAndAddOp(name, delta));
128+
return invocationManager.invoke(groupId, new GetAndAddOp(name, delta));
129129
}
130130

131131
@Override
@@ -140,7 +140,7 @@ public InternalCompletableFuture<Long> getAndIncrementAsync() {
140140

141141
@Override
142142
public InternalCompletableFuture<Long> getAndSetAsync(final long newValue) {
143-
return raftInvocationManager.invoke(groupId, new GetAndSetOp(name, newValue));
143+
return invocationManager.invoke(groupId, new GetAndSetOp(name, newValue));
144144
}
145145

146146
@Override
@@ -169,7 +169,7 @@ private long doAlter(IFunction<Long, Long> function, AlterResultType alterResult
169169
}
170170

171171
private InternalCompletableFuture<Long> doAlterAsync(IFunction<Long, Long> function, AlterResultType alterResultType) {
172-
return raftInvocationManager.invoke(groupId, new AlterOp(name, function, alterResultType));
172+
return invocationManager.invoke(groupId, new AlterOp(name, function, alterResultType));
173173
}
174174

175175
@Override
@@ -195,7 +195,7 @@ public InternalCompletableFuture<Long> getAndAlterAsync(IFunction<Long, Long> fu
195195

196196
@Override
197197
public <R> InternalCompletableFuture<R> applyAsync(final IFunction<Long, R> function) {
198-
return raftInvocationManager.invoke(groupId, new ApplyOp<R>(name, function));
198+
return invocationManager.invoke(groupId, new ApplyOp<R>(name, function));
199199
}
200200

201201
public long localGet(QueryPolicy queryPolicy) {
@@ -210,7 +210,7 @@ public long localGet(QueryPolicy queryPolicy) {
210210
public ICompletableFuture<Long> localGetAsync(final QueryPolicy queryPolicy) {
211211
final SimpleCompletableFuture<Long> resultFuture = new SimpleCompletableFuture<Long>(null, null);
212212
ICompletableFuture<Long> localFuture =
213-
raftInvocationManager.queryOnLocal(groupId, new LocalGetOp(name), queryPolicy);
213+
invocationManager.queryOnLocal(groupId, new LocalGetOp(name), queryPolicy);
214214

215215
localFuture.andThen(new ExecutionCallback<Long>() {
216216
@Override
@@ -220,7 +220,7 @@ public void onResponse(Long response) {
220220

221221
@Override
222222
public void onFailure(Throwable t) {
223-
ICompletableFuture<Long> future = raftInvocationManager.query(groupId, new LocalGetOp(name), queryPolicy);
223+
ICompletableFuture<Long> future = invocationManager.query(groupId, new LocalGetOp(name), queryPolicy);
224224
future.andThen(new ExecutionCallback<Long>() {
225225
@Override
226226
public void onResponse(Long response) {
@@ -255,7 +255,7 @@ public String getServiceName() {
255255

256256
@Override
257257
public void destroy() {
258-
raftInvocationManager.invoke(groupId, new DestroyRaftObjectOp(getServiceName(), name)).join();
258+
invocationManager.invoke(groupId, new DestroyRaftObjectOp(getServiceName(), name)).join();
259259
}
260260

261261
public RaftGroupId getGroupId() {

hazelcast-raft-dataservices/src/main/java/com/hazelcast/raft/service/atomicref/proxy/RaftAtomicRefProxy.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ public class RaftAtomicRefProxy<T> implements IAtomicReference<T> {
4343

4444
private final String name;
4545
private final RaftGroupId groupId;
46-
private final RaftInvocationManager raftInvocationManager;
46+
private final RaftInvocationManager invocationManager;
4747
private final SerializationService serializationService;
4848

4949
public RaftAtomicRefProxy(RaftInvocationManager invocationManager, SerializationService serializationService,
5050
RaftGroupId groupId, String name) {
5151
this.name = name;
5252
this.groupId = groupId;
53-
this.raftInvocationManager = invocationManager;
53+
this.invocationManager = invocationManager;
5454
this.serializationService = serializationService;
5555
}
5656

@@ -117,22 +117,22 @@ public <R> R apply(IFunction<T, R> function) {
117117

118118
@Override
119119
public InternalCompletableFuture<Boolean> compareAndSetAsync(T expect, T update) {
120-
return raftInvocationManager.invoke(groupId, new CompareAndSetOp(name, toData(expect), toData(update)));
120+
return invocationManager.invoke(groupId, new CompareAndSetOp(name, toData(expect), toData(update)));
121121
}
122122

123123
@Override
124124
public InternalCompletableFuture<T> getAsync() {
125-
return raftInvocationManager.invoke(groupId, new GetOp(name));
125+
return invocationManager.invoke(groupId, new GetOp(name));
126126
}
127127

128128
@Override
129129
public InternalCompletableFuture<Void> setAsync(T newValue) {
130-
return raftInvocationManager.invoke(groupId, new SetOp(name, toData(newValue), false));
130+
return invocationManager.invoke(groupId, new SetOp(name, toData(newValue), false));
131131
}
132132

133133
@Override
134134
public InternalCompletableFuture<T> getAndSetAsync(T newValue) {
135-
return raftInvocationManager.invoke(groupId, new SetOp(name, toData(newValue), true));
135+
return invocationManager.invoke(groupId, new SetOp(name, toData(newValue), true));
136136
}
137137

138138
@Override
@@ -147,31 +147,31 @@ public InternalCompletableFuture<Void> clearAsync() {
147147

148148
@Override
149149
public InternalCompletableFuture<Boolean> containsAsync(T expected) {
150-
return raftInvocationManager.invoke(groupId, new ContainsOp(name, toData(expected)));
150+
return invocationManager.invoke(groupId, new ContainsOp(name, toData(expected)));
151151
}
152152

153153
@Override
154154
public InternalCompletableFuture<Void> alterAsync(IFunction<T, T> function) {
155155
checkTrue(function != null, "Function cannot be null");
156-
return raftInvocationManager.invoke(groupId, new ApplyOp(name, toData(function), NO_RETURN_VALUE, true));
156+
return invocationManager.invoke(groupId, new ApplyOp(name, toData(function), NO_RETURN_VALUE, true));
157157
}
158158

159159
@Override
160160
public InternalCompletableFuture<T> alterAndGetAsync(IFunction<T, T> function) {
161161
checkTrue(function != null, "Function cannot be null");
162-
return raftInvocationManager.invoke(groupId, new ApplyOp(name, toData(function), RETURN_NEW_VALUE, true));
162+
return invocationManager.invoke(groupId, new ApplyOp(name, toData(function), RETURN_NEW_VALUE, true));
163163
}
164164

165165
@Override
166166
public InternalCompletableFuture<T> getAndAlterAsync(IFunction<T, T> function) {
167167
checkTrue(function != null, "Function cannot be null");
168-
return raftInvocationManager.invoke(groupId, new ApplyOp(name, toData(function), RETURN_OLD_VALUE, true));
168+
return invocationManager.invoke(groupId, new ApplyOp(name, toData(function), RETURN_OLD_VALUE, true));
169169
}
170170

171171
@Override
172172
public <R> InternalCompletableFuture<R> applyAsync(IFunction<T, R> function) {
173173
checkTrue(function != null, "Function cannot be null");
174-
return raftInvocationManager.invoke(groupId, new ApplyOp(name, toData(function), RETURN_NEW_VALUE, false));
174+
return invocationManager.invoke(groupId, new ApplyOp(name, toData(function), RETURN_NEW_VALUE, false));
175175
}
176176

177177
@Override
@@ -191,7 +191,7 @@ public String getServiceName() {
191191

192192
@Override
193193
public void destroy() {
194-
raftInvocationManager.invoke(groupId, new DestroyRaftObjectOp(getServiceName(), name)).join();
194+
invocationManager.invoke(groupId, new DestroyRaftObjectOp(getServiceName(), name)).join();
195195
}
196196

197197
public RaftGroupId getGroupId() {

hazelcast-raft-dataservices/src/main/java/com/hazelcast/raft/service/countdownlatch/proxy/RaftCountDownLatchProxy.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public class RaftCountDownLatchProxy implements ICountDownLatch {
3939

4040
private final RaftGroupId groupId;
4141
private final String name;
42-
private final RaftInvocationManager raftInvocationManager;
42+
private final RaftInvocationManager invocationManager;
4343

4444
public RaftCountDownLatchProxy(RaftInvocationManager invocationManager, RaftGroupId groupId, String name) {
45-
this.raftInvocationManager = invocationManager;
45+
this.invocationManager = invocationManager;
4646
this.groupId = groupId;
4747
this.name = name;
4848
}
@@ -52,23 +52,23 @@ public boolean await(long timeout, TimeUnit unit) throws InterruptedException {
5252
checkNotNull(unit);
5353

5454
long timeoutMillis = Math.max(0, unit.toMillis(timeout));
55-
return raftInvocationManager.<Boolean>invoke(groupId, new AwaitOp(name, timeoutMillis)).join();
55+
return invocationManager.<Boolean>invoke(groupId, new AwaitOp(name, timeoutMillis)).join();
5656
}
5757

5858
@Override
5959
public void countDown() {
60-
int round = raftInvocationManager.<Integer>invoke(groupId, new GetRoundOp(name)).join();
61-
raftInvocationManager.invoke(groupId, new CountDownOp(name, round, newUnsecureUUID())).join();
60+
int round = invocationManager.<Integer>invoke(groupId, new GetRoundOp(name)).join();
61+
invocationManager.invoke(groupId, new CountDownOp(name, round, newUnsecureUUID())).join();
6262
}
6363

6464
@Override
6565
public int getCount() {
66-
return raftInvocationManager.<Integer>invoke(groupId, new GetRemainingCountOp(name)).join();
66+
return invocationManager.<Integer>invoke(groupId, new GetRemainingCountOp(name)).join();
6767
}
6868

6969
@Override
7070
public boolean trySetCount(int count) {
71-
return raftInvocationManager.<Boolean>invoke(groupId, new TrySetCountOp(name, count)).join();
71+
return invocationManager.<Boolean>invoke(groupId, new TrySetCountOp(name, count)).join();
7272
}
7373

7474
@Override
@@ -92,7 +92,7 @@ public RaftGroupId getGroupId() {
9292

9393
@Override
9494
public void destroy() {
95-
raftInvocationManager.invoke(groupId, new DestroyRaftObjectOp(getServiceName(), name)).join();
95+
invocationManager.invoke(groupId, new DestroyRaftObjectOp(getServiceName(), name)).join();
9696
}
9797

9898
}

hazelcast-raft-dataservices/src/main/java/com/hazelcast/raft/service/lock/exception/LockRequestCancelledException.java renamed to hazelcast-raft-dataservices/src/main/java/com/hazelcast/raft/service/exception/WaitKeyCancelledException.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,36 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.hazelcast.raft.service.lock.exception;
17+
package com.hazelcast.raft.service.exception;
1818

1919
import com.hazelcast.client.impl.protocol.ClientExceptionFactory;
2020
import com.hazelcast.core.HazelcastException;
2121

2222
/**
2323
* TODO: Javadoc Pending...
2424
*/
25-
public class LockRequestCancelledException extends HazelcastException {
25+
public class WaitKeyCancelledException extends HazelcastException {
2626

2727
// TODO [basri] fixit
2828
public static final int ERROR_CODE = 6768;
2929

3030

31-
public LockRequestCancelledException() {
31+
public WaitKeyCancelledException() {
3232
}
3333

34-
public LockRequestCancelledException(String message) {
34+
public WaitKeyCancelledException(String message) {
3535
super(message);
3636
}
3737

38-
public LockRequestCancelledException(String message, Throwable cause) {
38+
public WaitKeyCancelledException(String message, Throwable cause) {
3939
super(message, cause);
4040
}
4141

4242
public static void register(ClientExceptionFactory factory) {
43-
factory.register(ERROR_CODE, LockRequestCancelledException.class, new ClientExceptionFactory.ExceptionFactory() {
43+
factory.register(ERROR_CODE, WaitKeyCancelledException.class, new ClientExceptionFactory.ExceptionFactory() {
4444
@Override
4545
public Throwable createException(String message, Throwable cause) {
46-
return new LockRequestCancelledException(message, cause);
46+
return new WaitKeyCancelledException(message, cause);
4747
}
4848
});
4949
}

hazelcast-raft-dataservices/src/main/java/com/hazelcast/raft/service/lock/LockRegistry.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected RaftLock createNewResource(RaftGroupId groupId, String name) {
4646
AcquireResult acquire(String name, LockEndpoint endpoint, long commitIndex, UUID invocationUid) {
4747
AcquireResult result = getOrInitResource(name).acquire(endpoint, commitIndex, invocationUid, true);
4848

49-
for (LockInvocationKey waitKey : result.notifications) {
49+
for (LockInvocationKey waitKey : result.cancelled) {
5050
removeWaitKey(waitKey);
5151
}
5252

@@ -58,7 +58,7 @@ AcquireResult tryAcquire(String name, LockEndpoint endpoint, long commitIndex, U
5858
AcquireResult result = getOrInitResource(name).acquire(endpoint, commitIndex, invocationUid, wait);
5959
long fence = result.fence;
6060

61-
for (LockInvocationKey waitKey : result.notifications) {
61+
for (LockInvocationKey waitKey : result.cancelled) {
6262
removeWaitKey(waitKey);
6363
}
6464

@@ -72,7 +72,7 @@ AcquireResult tryAcquire(String name, LockEndpoint endpoint, long commitIndex, U
7272
ReleaseResult release(String name, LockEndpoint endpoint, UUID invocationUid) {
7373
RaftLock lock = getResourceOrNull(name);
7474
if (lock == null) {
75-
return ReleaseResult.NOT_RELEASED;
75+
return ReleaseResult.FAILED;
7676
}
7777

7878
ReleaseResult result = lock.release(endpoint, invocationUid);
@@ -86,7 +86,7 @@ ReleaseResult release(String name, LockEndpoint endpoint, UUID invocationUid) {
8686
ReleaseResult forceRelease(String name, long expectedFence, UUID invocationUid) {
8787
RaftLock lock = getResourceOrNull(name);
8888
if (lock == null) {
89-
return ReleaseResult.NOT_RELEASED;
89+
return ReleaseResult.FAILED;
9090
}
9191

9292
ReleaseResult result = lock.forceRelease(expectedFence, invocationUid);

0 commit comments

Comments
 (0)