Skip to content

cloud-storage-contrib-nio: Add support for newFileChannel#4718

Merged
olavloite merged 11 commits into
googleapis:masterfrom
olavloite:nio-filechannel
Apr 12, 2019
Merged

cloud-storage-contrib-nio: Add support for newFileChannel#4718
olavloite merged 11 commits into
googleapis:masterfrom
olavloite:nio-filechannel

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Adds support for the method FileSystemProvider.newFileChannel(Path, Set, FileAttribute...) to Google Cloud Storage nio. This enables, among others, users to use google-cloud-storage-nio with Webflux and MultipartFile upload.

Fixes #4702

@olavloite olavloite requested a review from a team March 22, 2019 06:39
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 22, 2019
@sduskis

sduskis commented Mar 22, 2019

Copy link
Copy Markdown
Contributor

Can you please run this: mvn com.coveo:fmt-maven-plugin:format

@codecov

codecov Bot commented Mar 22, 2019

Copy link
Copy Markdown

Codecov Report

Merging #4718 into master will increase coverage by 0.69%.
The diff coverage is 63.47%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #4718      +/-   ##
============================================
+ Coverage     49.66%   50.35%   +0.69%     
- Complexity    22706    23667     +961     
============================================
  Files          2158     2233      +75     
  Lines        213520   225890   +12370     
  Branches      24206    24958     +752     
============================================
+ Hits         106045   113758    +7713     
- Misses        99183   103533    +4350     
- Partials       8292     8599     +307
Impacted Files Coverage Δ Complexity Δ
...ge/contrib/nio/CloudStorageFileSystemProvider.java 61.26% <30.76%> (-1.21%) 70 <1> (+1)
...rage/contrib/nio/CloudStorageWriteFileChannel.java 64.91% <64.91%> (ø) 13 <13> (?)
...orage/contrib/nio/CloudStorageReadFileChannel.java 71.11% <71.11%> (ø) 10 <10> (?)
...cloud/iam/credentials/v1/IamCredentialsClient.java 46.22% <0%> (-32.26%) 23% <0%> (+3%)
...oud/automl/v1beta1/stub/PredictionServiceStub.java 20% <0%> (-30%) 1% <0%> (ø)
...ava/com/google/cloud/storage/BlobWriteChannel.java 71.66% <0%> (-19.51%) 9% <0%> (+4%)
...urityscanner/v1alpha/WebSecurityScannerClient.java 66.5% <0%> (-16.04%) 55% <0%> (+7%)
...d/storage/CanonicalExtensionHeadersSerializer.java 88.88% <0%> (-11.12%) 12% <0%> (+4%)
...va/com/google/cloud/redis/v1/CloudRedisClient.java 53.33% <0%> (-7.03%) 27% <0%> (-8%)
.../cloud/monitoring/v3/UptimeCheckServiceClient.java 54.45% <0%> (-4.44%) 23% <0%> (ø)
... and 234 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db18d86...5c2c732. Read the comment docs.

@yoshi-automation yoshi-automation added the 🚨 critical P0 critical issue. Requires immediate fix label Mar 29, 2019
* @param path The path to the file to open or create
* @param options The options specifying how the file should be opened, and whether the {@link
* FileChannel} should be read-only or write-only.
* @param attrs (not supported, the values will be ignored)

@JesseLovelace JesseLovelace Apr 5, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why the null check for attrs below if this is the case? attrs is optional in File.createFile

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I chose to do so to keep it consistent with the other methods in CloudStorageFileSystemProvider that accept an array of FileAtributes as an input parameter. These do the exact same check, even though the input value is ignored.

(See newByteChannel(...)``createDirectory(...))

Furthermore, newFileChannel method can also be used to read an existing file, so it does not always call File.createFile.

(CloudStorageWriteChannel) newWriteChannel(path, options);
return new CloudStorageWriteFileChannel(writeChannel);
} else {
CloudStorageReadChannel readChannel = (CloudStorageReadChannel) newReadChannel(path, options);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you need to cast to a CloudStorageReadChannel here? if not perhaps just do this: new CloudStorageReadFileChannel(newReadChannel(path, options));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, changed.

@Override
public long read(ByteBuffer[] dsts, int offset, int length) throws IOException {
long res = 0L;
synchronized (this) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You might as well jut put synchronized in the signature.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed.

@Override
public long transferTo(long position, long count, WritableByteChannel target) throws IOException {
long res = 0L;
synchronized (this) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

synchronized in the signature might be clearer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed.


@Override
public int read(ByteBuffer dst, long position) throws IOException {
synchronized (this) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed.

public int read(ByteBuffer dst, long position) throws IOException {
synchronized (this) {
long originalPosition = position();
position(position);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't this redundant?

      long originalPosition = position();
      position(position);

Do we actually need position(position);?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, we need to position the channel where the read should begin. I've changed the name of the parameter to make it clearer.

public FileChannel position(long newPosition) throws IOException {
synchronized (this) {
checkValid();
if (newPosition != position()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's a call to checkValid() in position(). We don't need two calls. Perhaps just use writeChannel.position()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are other places where the double check happens as well, further down.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I removed the redundant validation checks and changed the method signatures in this class as well to synchronized.

@sduskis sduskis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking good. I think that my last couple request ought to be done, but once they are, please merge this.

res += bytesRead;
}
}
position(originalPosition);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please put position(originalPosition) in a finally block.

long originalPosition = position();
position(readFromPosition);
int res = readChannel.read(dst);
position(originalPosition);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please put position(originalPosition) in a finally block.

@sduskis sduskis added 🚨 critical P0 critical issue. Requires immediate fix and removed 🚨 critical P0 critical issue. Requires immediate fix labels Apr 11, 2019
@olavloite olavloite merged commit b697a8b into googleapis:master Apr 12, 2019
@olavloite olavloite deleted the nio-filechannel branch April 12, 2019 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement. 🚨 critical P0 critical issue. Requires immediate fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

google-cloud-nio: CloudStorageFileSystemProvider throws UnsupportedException when used with Webflux + MultipartFile upload

7 participants