This is an automated email from the ASF dual-hosted git repository.

szetszwo pushed a commit to branch branch-2
in repository https://gitbox.apache.org/repos/asf/ratis.git


The following commit(s) were added to refs/heads/branch-2 by this push:
     new c013bb5bf RATIS-1885. Incorrect clientWriteRequest timer usage (#916)
c013bb5bf is described below

commit c013bb5bfc27c80b002b473aad2ae853a26cafb3
Author: Wei-Chiu Chuang <[email protected]>
AuthorDate: Sat Sep 9 03:29:42 2023 -0700

    RATIS-1885. Incorrect clientWriteRequest timer usage (#916)
---
 .../src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java     | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
index 295ddbc61..8d88f1151 100644
--- 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
+++ 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
@@ -838,6 +838,7 @@ class RaftServerImpl implements RaftServer.Division,
     assertLifeCycleState(LifeCycle.States.RUNNING);
     LOG.debug("{}: receive client request({})", getMemberId(), request);
     final Optional<Timer> timer = 
Optional.ofNullable(raftServerMetrics.getClientRequestTimer(request.getType()));
+    final Optional<Timer.Context> timerContext = timer.map(Timer::time);
 
     final CompletableFuture<RaftClientReply> replyFuture;
 
@@ -897,7 +898,7 @@ class RaftServerImpl implements RaftServer.Division,
 
     final RaftClientRequest.Type type = request.getType();
     replyFuture.whenComplete((clientReply, exception) -> {
-      timer.map(Timer::time).ifPresent(Timer.Context::stop);
+      timerContext.ifPresent(Timer.Context::stop);
       if (exception != null || clientReply.getException() != null) {
         raftServerMetrics.incFailedRequestCount(type);
       }

Reply via email to