Skip to content

Commit ec6beed

Browse files
committed
no need synchronized
no need synchronized no need synchronized
1 parent b278213 commit ec6beed

File tree

3 files changed

+22
-30
lines changed

3 files changed

+22
-30
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/ipc/Client.java

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,9 @@ void checkResponse(RpcResponseHeaderProto header) throws IOException {
305305
}
306306
}
307307

308-
Call createCall(RPC.RpcKind rpcKind, Writable rpcRequest) {
309-
return new Call(rpcKind, rpcRequest);
308+
Call createCall(RPC.RpcKind rpcKind, Writable rpcRequest,
309+
AlignmentContext alignmentContext) {
310+
return new Call(rpcKind, rpcRequest, alignmentContext);
310311
}
311312

312313
/**
@@ -319,11 +320,13 @@ static class Call {
319320
private final CompletableFuture<Writable> rpcResponseFuture;
320321
final RPC.RpcKind rpcKind; // Rpc EngineKind
321322
private final Object externalHandler;
322-
private AlignmentContext alignmentContext;
323+
private final AlignmentContext alignmentContext;
323324

324-
private Call(RPC.RpcKind rpcKind, Writable param) {
325+
private Call(RPC.RpcKind rpcKind, Writable param,
326+
AlignmentContext alignmentContext) {
325327
this.rpcKind = rpcKind;
326328
this.rpcRequest = param;
329+
this.alignmentContext = alignmentContext;
327330

328331
final Integer id = callId.get();
329332
if (id == null) {
@@ -351,44 +354,32 @@ public String toString() {
351354

352355
/** Indicate when the call is complete and the
353356
* value or error are available. Notifies by default. */
354-
protected synchronized void callComplete(Writable rpcResponse, IOException error) {
355-
if (error != null) {
356-
rpcResponseFuture.completeExceptionally(error);
357-
} else {
358-
rpcResponseFuture.complete(rpcResponse);
359-
}
357+
protected void callComplete() {
360358
if (externalHandler != null) {
361359
synchronized (externalHandler) {
362360
externalHandler.notify();
363361
}
364362
}
365363
}
366364

367-
/**
368-
* Set an AlignmentContext for the call to update when call is done.
369-
*
370-
* @param ac alignment context to update.
371-
*/
372-
public synchronized void setAlignmentContext(AlignmentContext ac) {
373-
this.alignmentContext = ac;
374-
}
375-
376365
/** Set the exception when there is an error.
377366
* Notify the caller the call is done.
378367
*
379368
* @param error exception thrown by the call; either local or remote
380369
*/
381-
public synchronized void setException(IOException error) {
382-
callComplete(null, error);
370+
public void setException(IOException error) {
371+
rpcResponseFuture.completeExceptionally(error);
372+
callComplete();
383373
}
384374

385375
/** Set the return value when there is no error.
386376
* Notify the caller the call is done.
387377
*
388378
* @param rpcResponse return value of the rpc call.
389379
*/
390-
public synchronized void setRpcResponse(Writable rpcResponse) {
391-
callComplete(rpcResponse, null);
380+
public void setRpcResponse(Writable rpcResponse) {
381+
rpcResponseFuture.complete(rpcResponse);
382+
callComplete();
392383
}
393384
}
394385

@@ -1503,8 +1494,7 @@ Writable call(RPC.RpcKind rpcKind, Writable rpcRequest,
15031494
ConnectionId remoteId, int serviceClass,
15041495
AtomicBoolean fallbackToSimpleAuth, AlignmentContext alignmentContext)
15051496
throws IOException {
1506-
final Call call = createCall(rpcKind, rpcRequest);
1507-
call.setAlignmentContext(alignmentContext);
1497+
final Call call = createCall(rpcKind, rpcRequest, alignmentContext);
15081498
final Connection connection = getConnection(remoteId, call, serviceClass,
15091499
fallbackToSimpleAuth);
15101500

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestAsyncIPC.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,13 @@ public void testCallIdAndRetry() throws IOException, InterruptedException,
422422
// Override client to store the call info and check response
423423
final Client client = new Client(LongWritable.class, conf) {
424424
@Override
425-
Call createCall(RpcKind rpcKind, Writable rpcRequest) {
425+
Call createCall(RpcKind rpcKind, Writable rpcRequest,
426+
AlignmentContext alignmentContext) {
426427
// Set different call id and retry count for the next call
427428
Client.setCallIdAndRetryCount(Client.nextCallId(),
428429
TestIPC.RANDOM.nextInt(255), null);
429430

430-
final Call call = super.createCall(rpcKind, rpcRequest);
431+
final Call call = super.createCall(rpcKind, rpcRequest, alignmentContext);
431432

432433
CallInfo info = new CallInfo();
433434
info.id = call.id;
@@ -629,4 +630,4 @@ public void testAsyncCallWithCompletableFuture() throws IOException,
629630
server.stop();
630631
}
631632
}
632-
}
633+
}

hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/ipc/TestIPC.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,8 +1301,9 @@ public void testCallIdAndRetry() throws IOException {
13011301
// Override client to store the call info and check response
13021302
final Client client = new Client(LongWritable.class, conf) {
13031303
@Override
1304-
Call createCall(RpcKind rpcKind, Writable rpcRequest) {
1305-
final Call call = super.createCall(rpcKind, rpcRequest);
1304+
Call createCall(RpcKind rpcKind, Writable rpcRequest,
1305+
AlignmentContext alignmentContext) {
1306+
final Call call = super.createCall(rpcKind, rpcRequest, alignmentContext);
13061307
info.id = call.id;
13071308
info.retry = call.retry;
13081309
return call;

0 commit comments

Comments
 (0)