Skip to content

Commit

Permalink
*Fix graceful shutdown notify failure
Browse files Browse the repository at this point in the history
Signed-off-by: provenceee <[email protected]>
  • Loading branch information
provenceee committed Sep 24, 2024
1 parent b50e080 commit 0e18da2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.sermant.registry.services.GraceService;
import io.sermant.registry.utils.CommonUtils;

import java.time.LocalDateTime;
import java.util.Locale;
import java.util.logging.Logger;

Expand Down Expand Up @@ -72,7 +73,8 @@ private void graceShutDown() {
CommonUtils.sleep(shutdownCheckTimeUnit);
shutdownWaitTime -= shutdownCheckTimeUnit;
}
System.out.println("shutdown: " + graceService.isCompleteNotify());
System.out.println(Thread.currentThread().getName() + LocalDateTime.now() + "shutdown: "
+ graceService.isCompleteNotify());
final int requestCount = GraceContext.INSTANCE.getGraceShutDownManager().getRequestCount();
if (requestCount > 0) {
LOGGER.warning(String.format(Locale.ENGLISH, "Request num that does not completed is [%s] ", requestCount));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,19 @@ public void shutdown() {
Arrays.asList(clientInfo.getIp() + ":" + clientInfo.getPort(),
clientInfo.getHost() + ":" + clientInfo.getPort()));
latch = new CountDownLatch(AddressCache.INSTANCE.getAddressSet().size());
System.out.println(LocalDateTime.now() + "latch count is " + latch.getCount());
System.out.println(
Thread.currentThread().getName() + LocalDateTime.now() + "latch count is " + latch.getCount());
AddressCache.INSTANCE.getAddressSet().forEach(address -> notifyToGraceHttpServer(address, header));
}
}

@Override
public boolean isCompleteNotify() {
if (latch == null) {
System.out.println(LocalDateTime.now() + "latch is null.");
System.out.println(Thread.currentThread().getName() + LocalDateTime.now() + "latch is null.");
} else {
System.out.println(LocalDateTime.now() + "isCompleteNotify: " + latch.getCount());
System.out.println(
Thread.currentThread().getName() + LocalDateTime.now() + "isCompleteNotify: " + latch.getCount());
}
return latch != null && latch.getCount() == 0;
}
Expand All @@ -107,11 +109,12 @@ private void notifyToGraceHttpServer(String address, Map<String, Collection<Stri
try {
latch.await();
} catch (InterruptedException e) {
System.out.println(LocalDateTime.now() + "Failed to wait notification.");
System.out.println(Thread.currentThread().getName() + LocalDateTime.now() + "Failed to wait notification.");
LOGGER.log(Level.SEVERE, "Failed to wait notification.", e);
return;
}
System.out.println(LocalDateTime.now() + "Notify before shutdown successful.");
System.out.println(
Thread.currentThread().getName() + LocalDateTime.now() + "Notify before shutdown successful.");
LOGGER.log(Level.INFO, "Notify before shutdown successful.");
}

Expand All @@ -123,6 +126,7 @@ private void execute(String address, Map<String, Collection<String>> header) {
if (result.getCode() == GraceConstants.GRACE_HTTP_SUCCESS_CODE) {
break;
}
System.out.println("Failed to notify before shutdown, address: " + address);
LOGGER.log(Level.WARNING, "Failed to notify before shutdown, address: {0}", address);
}
latch.countDown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ public HttpClientResult doPost(String url, String json, Map<String, Collection<S
return result;
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Request submit error.Error info: ", e);
System.out.println("Request submit error.Error info");
e.printStackTrace();
return new HttpClientResult(HttpStatus.SC_INTERNAL_SERVER_ERROR);
} catch (Exception e) {
System.out.println("Request submit error.EEError info");
e.printStackTrace();
return new HttpClientResult(HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
}
Expand Down

0 comments on commit 0e18da2

Please sign in to comment.