hangc0276 commented on code in PR #3998:
URL: https://github.com/apache/bookkeeper/pull/3998#discussion_r1239259610
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/server/http/service/TriggerGCService.java:
##########
@@ -61,40 +62,46 @@ public TriggerGCService(ServerConfiguration conf,
BookieServer bookieServer) {
@Override
public HttpServiceResponse handle(HttpServiceRequest request) throws
Exception {
HttpServiceResponse response = new HttpServiceResponse();
+ try {
+ if (HttpServer.Method.PUT == request.getMethod()) {
+ String requestBody = request.getBody();
+ if (StringUtils.isBlank(requestBody)) {
+ bookieServer.getBookie().getLedgerStorage().forceGC();
+ } else {
+ @SuppressWarnings("unchecked")
+ Map<String, Object> configMap =
JsonUtil.fromJson(requestBody, HashMap.class);
+ Boolean forceMajor = (Boolean)
configMap.getOrDefault("forceMajor", null);
+ Boolean forceMinor = (Boolean)
configMap.getOrDefault("forceMinor", null);
+
bookieServer.getBookie().getLedgerStorage().forceGC(forceMajor, forceMinor);
+ }
- if (HttpServer.Method.PUT == request.getMethod()) {
- String requestBody = request.getBody();
- if (null == requestBody) {
- bookieServer.getBookie().getLedgerStorage().forceGC();
+ String output = "Triggered GC on BookieServer: " +
bookieServer.getBookieId();
+ String jsonResponse = JsonUtil.toJson(output);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("output body:" + jsonResponse);
+ }
+ response.setBody(jsonResponse);
+ response.setCode(HttpServer.StatusCode.OK);
+ return response;
+ } else if (HttpServer.Method.GET == request.getMethod()) {
+ Boolean isInForceGC =
bookieServer.getBookie().getLedgerStorage().isInForceGC();
+ Pair<String, String> output = Pair.of("is_in_force_gc",
isInForceGC.toString());
+ String jsonResponse = JsonUtil.toJson(output);
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("output body:" + jsonResponse);
+ }
+ response.setBody(jsonResponse);
+ response.setCode(HttpServer.StatusCode.OK);
+ return response;
} else {
- @SuppressWarnings("unchecked")
- Map<String, Object> configMap = JsonUtil.fromJson(requestBody,
HashMap.class);
- Boolean forceMajor = (Boolean)
configMap.getOrDefault("forceMajor", null);
- Boolean forceMinor = (Boolean)
configMap.getOrDefault("forceMinor", null);
-
bookieServer.getBookie().getLedgerStorage().forceGC(forceMajor, forceMinor);
+ response.setCode(HttpServer.StatusCode.NOT_FOUND);
Review Comment:
Updated. It will change the current status code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]