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

Storage: FakeStorageRpc states it supports generations, but generationMatch option unsupported on Blob creation. #775

Open
SanjayVas opened this issue Dec 14, 2021 · 3 comments
Assignees
Labels
api: storage Issues related to the googleapis/java-storage-nio API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@SanjayVas
Copy link

Environment details

  1. Specify the API at the beginning of the title. For example, "BigQuery: ...").
    General, Core, and Other are also allowed as types
  2. OS type and version: Debian 11
  3. Java version: 11
  4. storage_nio version(s): HEAD

Steps to reproduce

  1. Init Storage using LocalStorageHelper.
  2. Call create with BlobInfo and BlobTargetOption.generationMatch.

Code example

val bucketName = "bucket"
val blobKey = "blob-key"
val storage = LocalStorageHelper.getOptions().service
storage.create(
  BlobInfo.newBuilder(bucketName, blobKey, 0L).build(),
  Storage.BlobTargetOption.generationMatch()
)

Stack trace

java.lang.UnsupportedOperationException
com.google.cloud.storage.StorageException: 
	at com.google.cloud.storage.StorageException.translateAndThrow(StorageException.java:81)
	at com.google.cloud.storage.StorageImpl.internalCreate(StorageImpl.java:229)
	at com.google.cloud.storage.StorageImpl.create(StorageImpl.java:157)
Caused by: 
	at com.google.cloud.storage.contrib.nio.testing.FakeStorageRpc.potentiallyThrow(FakeStorageRpc.java:446)
	at com.google.cloud.storage.contrib.nio.testing.FakeStorageRpc.create(FakeStorageRpc.java:96)
	at com.google.cloud.storage.StorageImpl$3.call(StorageImpl.java:221)
	at com.google.cloud.storage.StorageImpl$3.call(StorageImpl.java:218)
	at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105)
	at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
	at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
	at com.google.cloud.storage.StorageImpl.internalCreate(StorageImpl.java:217)
	... 40 more

External references such as API reference guides

https://github.com/googleapis/java-storage-nio/blob/main/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java

Any additional information below

FakeStorageRpc appears to handle generations for some operations using the checkGeneration private method. For Blob create however, it just calls potentiallyThrow. It seems like it should be a relatively simple change to check the generation if the appropriate option is set, with two wrinkles:

  1. What should the behavior be w.r.t. throwIfOption? Should it still throw for any option, or just unsupported ones?
  2. What's the right error code? Currently checkGeneration uses 404, but that's likely not correct for create. Does the real Cloud Storage implementation return 412 - Precondition failed in this case?
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/java-storage-nio API. label Dec 14, 2021
@cojenco
Copy link
Contributor

cojenco commented Dec 15, 2021

Thanks for the detailed report! As noted in our readme, this is a known limitation and is considered a feature request. We welcome pull requests in case you want to add support 😄

The error code that is returned by live GCS, in this case, is 412 Precondition Failed. There are specific cases where the server returns 404, more details here. I’m not sure what the behavior throwIfOption should be and will check with the team.

@cojenco cojenco added the type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. label Dec 15, 2021
@SanjayVas
Copy link
Author

Thanks for the info.

Does the class documentation for FakeStorageRpc need to be fixed then? It states generations are supported there.

@cojenco
Copy link
Contributor

cojenco commented Dec 15, 2021

I'll update the documentation shortly. Thanks for bringing this to our attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/java-storage-nio API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

3 participants