You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bookkeeper.apache.org by "Apurva007 (via GitHub)" <gi...@apache.org> on 2023/04/12 21:52:41 UTC

[GitHub] [bookkeeper] Apurva007 opened a new pull request, #3914: [Bug] Fix internal server error when GC is triggered with forcemajor or forceminor flags

Apurva007 opened a new pull request, #3914:
URL: https://github.com/apache/bookkeeper/pull/3914

   
   
   Descriptions of the changes in this PR:
   This PR fixes the internal server error when the GC is triggered via the REST API. The reason this error occurs is because the code is trying to perform a String to boolean casting which is failing.
   The code change is to make this conversion work.
   
   
   ### Motivation
   Fixes #3845 
   
   ### Changes
   
   Modified the code to perform a safer string to boolean conversion when trying to find the values in the JSON payload. Also converted the map from a <String, Object> to <String, String>.
   
   Master Issue: #3845 
   
   > ---
   > In order to uphold a high standard for quality for code contributions, Apache BookKeeper runs various precommit
   > checks for pull requests. A pull request can only be merged when it passes precommit checks.
   >
   > ---
   > Be sure to do all of the following to help us incorporate your contribution
   > quickly and easily:
   >
   > If this PR is a BookKeeper Proposal (BP):
   >
   > - [ ] Make sure the PR title is formatted like:
   >     `<BP-#>: Description of bookkeeper proposal`
   >     `e.g. BP-1: 64 bits ledger is support`
   > - [ ] Attach the master issue link in the description of this PR.
   > - [ ] Attach the google doc link if the BP is written in Google Doc.
   >
   > Otherwise:
   > 
   > - [ ] Make sure the PR title is formatted like:
   >     `<Issue #>: Description of pull request`
   >     `e.g. Issue 123: Description ...`
   > - [ ] Make sure tests pass via `mvn clean apache-rat:check install spotbugs:check`.
   > - [ ] Replace `<Issue #>` in the title with the actual Issue number.
   > 
   > ---
   


-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Apurva007 commented on pull request #3914: [Bug] Fix internal server error when GC is triggered with forcemajor or forceminor flags

Posted by "Apurva007 (via GitHub)" <gi...@apache.org>.
Apurva007 commented on PR #3914:
URL: https://github.com/apache/bookkeeper/pull/3914#issuecomment-1506010356

   Post Fix:
   <img width="933" alt="Screenshot 2023-04-12 at 12 49 30 AM" src="https://user-images.githubusercontent.com/10327630/231594357-100b0cc3-2054-44ce-b904-f2c4fc266220.png">
   


-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Apurva007 commented on a diff in pull request #3914: [Bug] Fix internal server error when GC is triggered with forcemajor or forceminor flags

Posted by "Apurva007 (via GitHub)" <gi...@apache.org>.
Apurva007 commented on code in PR #3914:
URL: https://github.com/apache/bookkeeper/pull/3914#discussion_r1164892084


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/server/http/service/TriggerGCService.java:
##########
@@ -68,9 +68,9 @@ public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
                 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);
+                Map<String, String> configMap = JsonUtil.fromJson(requestBody, HashMap.class);

Review Comment:
   @hangc0276 Thanks for the review. I will add the respective tests.



-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Apurva007 closed pull request #3914: [Bug] Fix internal server error when unexpected json inputs are sent to Bookkeeper HTTP Services

Posted by "Apurva007 (via GitHub)" <gi...@apache.org>.
Apurva007 closed pull request #3914: [Bug] Fix internal server error when unexpected json inputs are sent to Bookkeeper HTTP Services
URL: https://github.com/apache/bookkeeper/pull/3914


-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Apurva007 commented on pull request #3914: [Bug] Fix internal server error when GC is triggered with forcemajor or forceminor flags

Posted by "Apurva007 (via GitHub)" <gi...@apache.org>.
Apurva007 commented on PR #3914:
URL: https://github.com/apache/bookkeeper/pull/3914#issuecomment-1506009623

   Root cause:
   ![Screenshot 2023-04-12 at 12 47 48 AM](https://user-images.githubusercontent.com/10327630/231594255-19d76990-8ced-4b1b-99da-5301e25b77e1.png)
   


-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Apurva007 commented on pull request #3914: [Bug] Fix internal server error when GC is triggered with forcemajor or forceminor flags

Posted by "Apurva007 (via GitHub)" <gi...@apache.org>.
Apurva007 commented on PR #3914:
URL: https://github.com/apache/bookkeeper/pull/3914#issuecomment-1506012234

   @hangc0276 / @BewareMyPower Please can you help review the PR.


-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Apurva007 commented on pull request #3914: [Bug] Fix internal server error when unexpected json inputs are sent to Bookkeeper HTTP Services

Posted by "Apurva007 (via GitHub)" <gi...@apache.org>.
Apurva007 commented on PR #3914:
URL: https://github.com/apache/bookkeeper/pull/3914#issuecomment-1513344731

   @hangc0276 I have made the suggested changes. Please can you review again when you get a chance.


-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] eolivelli commented on a diff in pull request #3914: [Bug] Fix internal server error when unexpected json inputs are sent to Bookkeeper HTTP Services

Posted by "eolivelli (via GitHub)" <gi...@apache.org>.
eolivelli commented on code in PR #3914:
URL: https://github.com/apache/bookkeeper/pull/3914#discussion_r1187868995


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/server/http/service/TriggerGCService.java:
##########
@@ -69,8 +69,15 @@ public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
             } 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);
+                Object forceMajorObj = configMap.getOrDefault("forceMajor", null);
+                Object forceMinorObj = configMap.getOrDefault("forceMinor", null);
+                boolean forceMajor = false, forceMinor = false;
+                if (forceMajorObj instanceof Boolean) {
+                    forceMajor = (Boolean) forceMajorObj;

Review Comment:
   We should throw an error if it is not a boolean, otherwise the result is unpredictable 



-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Apurva007 commented on pull request #3914: [Bug] Fix internal server error when unexpected json inputs are sent to Bookkeeper HTTP Services

Posted by "Apurva007 (via GitHub)" <gi...@apache.org>.
Apurva007 commented on PR #3914:
URL: https://github.com/apache/bookkeeper/pull/3914#issuecomment-1524692477

   @hangc0276 Please can you help re-review this PR when you get a chance.


-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] hangc0276 commented on a diff in pull request #3914: [Bug] Fix internal server error when GC is triggered with forcemajor or forceminor flags

Posted by "hangc0276 (via GitHub)" <gi...@apache.org>.
hangc0276 commented on code in PR #3914:
URL: https://github.com/apache/bookkeeper/pull/3914#discussion_r1164833873


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/server/http/service/TriggerGCService.java:
##########
@@ -68,9 +68,9 @@ public HttpServiceResponse handle(HttpServiceRequest request) throws Exception {
                 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);
+                Map<String, String> configMap = JsonUtil.fromJson(requestBody, HashMap.class);

Review Comment:
   If the `requestBody` doesn't pass a String, the JsonUtil.fromJson will throw an exception. 
   Would you please add a test for this change?



-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Apurva007 commented on pull request #3914: [Bug] Fix internal server error when GC is triggered with forcemajor or forceminor flags

Posted by "Apurva007 (via GitHub)" <gi...@apache.org>.
Apurva007 commented on PR #3914:
URL: https://github.com/apache/bookkeeper/pull/3914#issuecomment-1506009380

   Issue:
   <img width="965" alt="Screenshot 2023-04-12 at 12 48 10 AM" src="https://user-images.githubusercontent.com/10327630/231594200-c7d437e1-246c-4731-803a-a101b89ab6b1.png">
   


-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Apurva007 commented on pull request #3914: [Bug] Fix internal server error when GC is triggered with forcemajor or forceminor flags

Posted by "Apurva007 (via GitHub)" <gi...@apache.org>.
Apurva007 commented on PR #3914:
URL: https://github.com/apache/bookkeeper/pull/3914#issuecomment-1506010117

   Post fix:
   ![Screenshot 2023-04-12 at 12 49 21 AM](https://user-images.githubusercontent.com/10327630/231594325-9f7780fb-b7f8-479d-b651-60b03aff599c.png)
   


-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [bookkeeper] Apurva007 commented on pull request #3914: [Bug] Fix internal server error when GC is triggered with forcemajor or forceminor flags

Posted by "Apurva007 (via GitHub)" <gi...@apache.org>.
Apurva007 commented on PR #3914:
URL: https://github.com/apache/bookkeeper/pull/3914#issuecomment-1506011848

   Forked Repo PR where test results passed: https://github.com/Apurva007/bookkeeper/pull/1
   


-- 
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: commits-unsubscribe@bookkeeper.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org