New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HDDS-8489. Refactor GET request to POST for OM DB snapshot #4695
Conversation
…Snapshot DB checkpoint
@@ -76,7 +81,7 @@ public class OmRatisSnapshotProvider extends RDBSnapshotProvider { | |||
private final Map<String, OMNodeDetails> peerNodesMap; | |||
private final HttpConfig.Policy httpPolicy; | |||
private final boolean spnegoEnabled; | |||
private final URLConnectionFactory connectionFactory; | |||
private URLConnectionFactory connectionFactory; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When possible, I prefer not to remove the final modifier just to make tests work. Could we change the setConnectionFactory() to a getConnectionFactory() method, and mock that method in the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I could not find any other way. I need to mock connectionFactory
field which is not a part of constructor parameters. I tried using @Mock
/@IncjectMock
combination, Reflection
and Unsafe
, but without results. Another idea would be to create constructor specificly for testing purposes, but I do not like that approach.
Do you have an idea how this could be handled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just meant something like this: https://github.com/GeorgeJahad/ozone/compare/da4e99768a..urlConnectionFactory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that is totally a different story. Sure thing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When possible, I prefer not to remove the final modifier just to make tests work. Could we change the setConnectionFactory() to a getConnectionFactory() method, and mock that method in the test?
+1 on using final.
Don't have very strong opinion but I think it would be nicer to pass URLConnectionFactory
as constructor parameter to achieve deterministic behavior for testing. Also aligns with Dependency injection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @hemantk-12 for the review! I added constructor which could be used for testing but also alligns with DI.
"Content-Disposition: form-data; name=\"" + | ||
OZONE_DB_CHECKPOINT_REQUEST_TO_EXCLUDE_SST + "[]\"" + crNl + | ||
crNl + | ||
sstFileName + crNl + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use 2 sst files. (Sometimes testing an array of size 1 hides flaws in loop code.)
|
||
OmRatisSnapshotProvider.writeFormData(connection, sstFiles); | ||
|
||
sb.append(fileName).append(CR_NL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use 2 files
responseMock); | ||
|
||
doCallRealMethod().when(omDbCheckpointServletMock) | ||
.writeDbDataToStream(any(), any(), any(), any(), any()); | ||
} | ||
|
||
@Test | ||
public void testDoGet() throws Exception { | ||
public void testDoPost() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are keeping doGet() around for recon, we need to keep the doGet() test working as well. The test is long and there is not much difference between the two versions, so I would prefer to parameterize this test so it runs twice, once with doGet() and once with doPost(). Is that difficult?
hey @Xushaohong these are the doPost() changes I discussed with you. Please take a look. |
Hi @mladjan-gadzic, thanks for the work on refactoring. |
Hi @Xushaohong, thanks for the review! I rerun it immediately after it failed and it was a success. Please have a look https://github.com/mladjan-gadzic/ozone/actions/runs/5174385281. |
Your link branch is HDDS-7922. |
Mistakenly I pasted wrong url. Please, have a look at https://github.com/mladjan-gadzic/ozone/actions/runs/5066045581. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good to me.
Left couple of minor comments.
continue; | ||
} | ||
|
||
if (!item.getFieldName().equals(fieldName)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: if conditions can be combined to one.
if (!item.getFieldName().equals(fieldName)) { | |
if (!fieldName.equals(item.getFieldName()) |
to avoid NPE because we know fieldName is constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditions are combined and comparation is reversed.
* @return array of parsed sst form data parameters for exclusion | ||
*/ | ||
private static String[] parseFormDataParameters(HttpServletRequest request) { | ||
String fieldName = OZONE_DB_CHECKPOINT_REQUEST_TO_EXCLUDE_SST + "[]"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be a constant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIELD_NAME
constant is created.
Hi @mladjan-gadzic , would you fix the build failure: https://github.com/apache/ozone/actions/runs/5066046001/jobs/9137638263?pr=4695 Thx! |
Hi @smengcl, thanks for checking out this PR. I pushed the latest changes and CI succeeded. |
# Conflicts: # hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/TestOMDbCheckpointServlet.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the patch @mladjan-gadzic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mladjan-gadzic for the patch.
And thanks @GeorgeJahad and @hemantk-12 for reviewing this. |
What changes were proposed in this pull request?
The om snapshot subsystem will require long arrays of http parameters which will no longer work as url parameters, so we need to change the om bootstrap http request from a http-get to http-post in order to allow form based parameters.
Recon has not yet been modified to support incremental checkpointing and so will not require the long excludeList, so it continues to use http get.
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-8489
How was this patch tested?