-
Notifications
You must be signed in to change notification settings - Fork 594
HDDS-6455. Adding a Builder class to Freon ContentGenerator, so as to avoid Constructor Telescoping. #3242
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
Conversation
… avoid Constructor Telescoping.
hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/freon/TestContentGenerator.java
Outdated
Show resolved
Hide resolved
hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/freon/TestContentGenerator.java
Outdated
Show resolved
Hide resolved
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/HadoopDirTreeGenerator.java
Outdated
Show resolved
Hide resolved
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/ContentGenerator.java
Outdated
Show resolved
Hide resolved
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/ContentGenerator.java
Show resolved
Hide resolved
|
Thanks for the patch @ArafatKhan2198, I have left some comments for you to check. |
@kaijchen all changes done !! |
hadoop-ozone/tools/src/test/java/org/apache/hadoop/ozone/freon/TestContentGenerator.java
Outdated
Show resolved
Hide resolved
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/HadoopDirTreeGenerator.java
Outdated
Show resolved
Hide resolved
hadoop-ozone/tools/src/main/java/org/apache/hadoop/ozone/freon/ContentGenerator.java
Outdated
Show resolved
Hide resolved
| ContentGenerator contentgenerator = new ContentGenerator(this); | ||
| return contentgenerator; |
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.
Builder's build method should verify that the object being constructed is valid. Here hflush and hsync are not applicable at the same time. Please add a check for that.
Nit: no need for local variable, return directly.
| ContentGenerator contentgenerator = new ContentGenerator(this); | |
| return contentgenerator; | |
| return new ContentGenerator(this); |
|
|
||
| contentGenerator = | ||
| new ContentGenerator(fileSize, bufferSize, copyBufferSize); | ||
| new Builder() |
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: I think it's more readable if builder is qualified where it is being used (and also more consistent with usage in other generator classes).
| new Builder() | |
| new ContentGenerator.Builder() |
| import org.apache.hadoop.hdds.conf.OzoneConfiguration; | ||
|
|
||
| import com.codahale.metrics.Timer; | ||
| import org.apache.hadoop.ozone.freon.ContentGenerator.Builder; |
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.
| import org.apache.hadoop.ozone.freon.ContentGenerator.Builder; |
adoroszlai
left a comment
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 @ArafatKhan2198 for updating the PR with the enum from #3192.
| public Builder setFlushMode(String flushmode) { | ||
| this.flushMode = flushmode; | ||
| Flags type = Flags.valueOf(flushmode); |
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 think it would be better to pass an instance of the enum to this method, enforcing type safety.
| /** | ||
| * Issue Hsync after every write ( Cannot be used with Hflush ). | ||
| */ | ||
| private final boolean hSync; | ||
|
|
||
| /** | ||
| * Issue Hflush after every write ( Cannot be used with Hsync ). | ||
| */ | ||
| private final boolean hFlush; |
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.
Replacing these with a single instance of Flags would simplify the code.
| /** | ||
| * Type of flags. | ||
| */ | ||
| public enum Flags { |
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 think FlushMode would be a better name.
| hSync, | ||
| hFlush, | ||
| None, |
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.
Constants are usually preferred in CAPS.
|
/pending |
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.
Marking this issue as un-mergeable as requested.
Please use /ready comment when it's resolved.
Please note that the PR will be closed after 21 days of inactivity from now. (But can be re-opened anytime later...)
/pending
|
Thank you very much for the patch. I am closing this PR temporarily as there was no activity recently and it is waiting for response from its author. It doesn't mean that this PR is not important or ignored: feel free to reopen the PR at any time. It only means that attention of committers is not required. We prefer to keep the review queue clean. This ensures PRs in need of review are more visible, which results in faster feedback for all PRs. If you need ANY help to finish this PR, please contact the community on the mailing list or the slack channel." |
What changes were proposed in this pull request?
The ContentGenerator class of the freon suite has multiple Parametrised Constructors each having various different arguments that have to be initialised, this affects the readability of the code. One way to solve this is to incorporate a builder class for ContentGenerator class so that any new parameters added in the future can be seamlessly added without the need of creating a new constructor.
When a file was closed or flushed, the file contents were written from the DataNode into the operating system using the normal close() and write() system calls.
The data may not be immediately persisted to the underlying physical storage, but may still reside in-memory in the operating system's file cache. This creates a window of vulnerability where if multiple DataNode machines fail simultaneously (e.g. loss of power to a rack), then previously written data may be lost. To combat this problem, HDFS (as of Hadoop 2.0) has introduced new APIs to provide a way to guarantee that written data will be immediately persisted to the underlying physical storage. These APIs are described in the following table.
Hence I have added a method that would implement Hsync or Hflush after every write if the user wants !
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-6455
How was this patch tested?
Existing UTs for ContentGeneratorClass ran successfully