Skip to content
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

Merged
merged 15 commits into from Jun 20, 2023

Conversation

mladjan-gadzic
Copy link
Contributor

@mladjan-gadzic mladjan-gadzic commented May 10, 2023

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?

  • Unit tests
  • Integration tests
  • Manual tests

@@ -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;
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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!

Copy link
Contributor

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.

Copy link
Contributor Author

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 +
Copy link
Contributor

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);
Copy link
Contributor

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 {
Copy link
Contributor

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?

@neils-dev neils-dev added gr snapshot https://issues.apache.org/jira/browse/HDDS-6517 labels May 11, 2023
@mladjan-gadzic mladjan-gadzic marked this pull request as ready for review May 12, 2023 07:04
@GeorgeJahad
Copy link
Contributor

GeorgeJahad commented May 20, 2023

hey @Xushaohong these are the doPost() changes I discussed with you. Please take a look.

@Xushaohong
Copy link
Contributor

Hi @mladjan-gadzic, thanks for the work on refactoring.
Could you resolve the failing CI first?

@mladjan-gadzic
Copy link
Contributor Author

Hi @mladjan-gadzic, thanks for the work on refactoring. Could you resolve the failing CI first?

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.

@Xushaohong
Copy link
Contributor

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.
You need to update this branch mladjan-gadzic:HDDS-8489

@mladjan-gadzic
Copy link
Contributor Author

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. You need to update this branch mladjan-gadzic:HDDS-8489

Mistakenly I pasted wrong url. Please, have a look at https://github.com/mladjan-gadzic/ozone/actions/runs/5066045581.

Copy link
Contributor

@hemantk-12 hemantk-12 left a 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)) {
Copy link
Contributor

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.

Suggested change
if (!item.getFieldName().equals(fieldName)) {
if (!fieldName.equals(item.getFieldName())

to avoid NPE because we know fieldName is constant.

Copy link
Contributor Author

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 + "[]";
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@smengcl
Copy link
Contributor

smengcl commented Jun 8, 2023

@mladjan-gadzic
Copy link
Contributor Author

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
@mladjan-gadzic
Copy link
Contributor Author

Hi @smengcl. I fixed missing import, merged upstream/master and resolved conflicts. After all of that remote CI passed.

Copy link
Contributor

@hemantk-12 hemantk-12 left a 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

Copy link
Contributor

@smengcl smengcl left a 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.

@smengcl smengcl merged commit 80ba150 into apache:master Jun 20, 2023
28 checks passed
@smengcl
Copy link
Contributor

smengcl commented Jun 20, 2023

And thanks @GeorgeJahad and @hemantk-12 for reviewing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
snapshot https://issues.apache.org/jira/browse/HDDS-6517
Projects
None yet
6 participants