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

fixes for enforce final fields checkstyle rule - Azure Storage #5010

Conversation

vhvb1989
Copy link
Member

No description provided.

tg-msft and others added 2 commits August 15, 2019 11:40
* Move Storage to official swagger files

There are no (meaningful) code changes except the attribute in
BlobHierarchyListSegment that I can't trace to the swagger

* Upgrade blobs swagger to 2019-02-02

Note that additional work will have to be done to patch our higher level code to
pass new parameters to existing APIs

* Fixes to Swagger generation and updating to use new protocol layer

* Fixed appendBlock content-type, added SpotBug exclusions for autogen code

* Update README.md

* Fixed incorrect exclude
* Migrate queue to spock test framework

* Remove all Junit tests and dependencies
}

this.internalWriteThreshold = (int) BlockBlobAsyncClient.BLOB_DEFAULT_UPLOAD_BLOCK_SIZE;
this(parentBlob, accessCondition != null ? new BlobAccessConditions().modifiedAccessConditions(
Copy link
Member

Choose a reason for hiding this comment

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

This is hard to discern. I wouldn't add the constructor above.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, this was one of the most annoying classes to fix XD

Constructor sets fields based on multiple conditions.
I added the private constructor to make sure all fields are always assigned so fields can be final without duplicating the code in each constructor.

The other option is to add private method that set fields but that would make fields not final

Options here are:

  1. Update code to make fields not final by adding private methods to set fields. This will simplify constructor logic
  2. Add some code duplicity for assigning fields in two constructors to enhance readability for this constructor.
  3. Avoid code duplicity by adding hard-to-discern calls (like it is right now)
  4. Create a ticket and assign to some code owner to decide what he/she wants to do and assign a suppress rule for it
  5. Any other idea is welcome

what do you think @conniey

Copy link
Member

Choose a reason for hiding this comment

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

This makes it hard to read. There are several ternary operators here and not clear what it's doing. Given that it's calling another overloaded constructor, you can't have any other statements before calling this() either. So, I would lean towards making it readable/maintainable even if that results in a tiny bit of code duplication.

Copy link
Member

Choose a reason for hiding this comment

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

This could be a case to break this down into four classes, one which handles the interface/abstract methods, and three more which implement that for each individual use case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Taking number #4 after talking to Conniey.
Tiket created: #5021

Rule to be supressed in this file until issue is fixed

Copy link
Member Author

Choose a reason for hiding this comment

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

I made a mistake while trying to fix this PR and had it all wrong.
PR got closed after deleting branch from origin
I created a new one as this one should have been #5022

@vhvb1989 vhvb1989 requested a review from conniey August 15, 2019 22:10
Copy link
Member

@JonathanGiles JonathanGiles left a comment

Choose a reason for hiding this comment

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

LGTM, ignoring the issue Connie raises. Once that is fixed to her satisfaction, this can be merged.

this.streamType = BlobType.BLOCK_BLOB;
this.internalWriteThreshold = (int) BlockBlobAsyncClient.BLOB_DEFAULT_UPLOAD_BLOCK_SIZE;
this(parentBlob, accessCondition, null, UUID.randomUUID().toString() + "-", new TreeMap<>(), 0,
BlobType.BLOCK_BLOB, BlockBlobAsyncClient.BLOB_DEFAULT_UPLOAD_BLOCK_SIZE);
Copy link
Member

Choose a reason for hiding this comment

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

The last argument is BlockBlobAsyncClient.BLOB_DEFAULT_UPLOAD_BLOCK_SIZE, but the argument name is internalWriteThreshold. I can see this is what used to be there, but it is weird naming? // @alzimmermsft

Copy link
Member

Choose a reason for hiding this comment

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

It's the threshold used until another page, block, etc is requested. Maybe this could be renamed to bufferSize? Could just remove the internal and have writeThreshold.

// .doOnComplete(() -> completionSink.complete());
private BlobOutputStream(final BlobAsyncClient blobClient, final BlobAccessConditions accessCondition,
final AppendPositionAccessConditions appendPositionAccessConditions,
final String blockIdPrefix, final TreeMap<Long, String> blockList,
Copy link
Member

Choose a reason for hiding this comment

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

Does it have to be a TreeMap? Can a Map be used instead?

Copy link
Member

Choose a reason for hiding this comment

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

@jianghaolu was TreeMap used to maintain some ordering?


/**
* Used for block blobs, holds the block list.
*/
private TreeMap<Long, String> blockList;
private final TreeMap<Long, String> blockList;
Copy link
Member

Choose a reason for hiding this comment

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

It's not related to this PR but curious if Map can be used instead? Also, why is it called a list?

Copy link
Member

Choose a reason for hiding this comment

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

It's called blockList given that it is used by BlockBlob's Put Blob List method. Given that this is the property on the class this can be changed to Map.

Copy link
Member Author

Choose a reason for hiding this comment

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

How do we like to handle this? Do you want me to update the name as part of this same PR? or should we create a new issue to request this change to have an independent commit for that refactoring?

Copy link
Member Author

@vhvb1989 vhvb1989 Aug 16, 2019

Choose a reason for hiding this comment

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

Issue created. Since there is more things to address than just names or type updating
#5021

}

this.internalWriteThreshold = (int) BlockBlobAsyncClient.BLOB_DEFAULT_UPLOAD_BLOCK_SIZE;
this(parentBlob, accessCondition != null ? new BlobAccessConditions().modifiedAccessConditions(
Copy link
Member

Choose a reason for hiding this comment

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

This makes it hard to read. There are several ternary operators here and not clear what it's doing. Given that it's calling another overloaded constructor, you can't have any other statements before calling this() either. So, I would lean towards making it readable/maintainable even if that results in a tiny bit of code duplication.

Copy link
Member

@alzimmermsft alzimmermsft left a comment

Choose a reason for hiding this comment

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

LGTM, just need to resolve the questions.

@vhvb1989 vhvb1989 closed this Aug 16, 2019
@vhvb1989 vhvb1989 deleted the enforce-final-fields-azure-storage branch August 16, 2019 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants