zymap commented on code in PR #3998:
URL: https://github.com/apache/bookkeeper/pull/3998#discussion_r1238260404


##########
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);

Review Comment:
   Shouldn't the default value be a boolean? If it is null, it would be easy to 
cause NPE in the inner code. We can use Boolean.parseBoolean() to make sure it 
is a boolean and avoid a cast error happening.



##########
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:
   The status should be NOT_ALLOWED, see here 
https://httpwg.org/specs/rfc9110.html#status.405



-- 
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]

Reply via email to