Skip to content

[java-storage] Add abort() to writer #12653

Description

@frankyn

Feature request filed in google-cloud-java: #1232

Activity

  1. added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Mar 21, 2020
  2. self-assigned this
    on Apr 13, 2020
  3. dmitry-fa commented on May 19, 2020

    @dmitry-fa

    Hi @frankyn.

    I'd like to suggest an approach for resumable upload implementation. Before proper documenting and writing tests, I'd like to check with you if my approach is applicable.

    • extend com.google.cloud.storage.spi.v1.StorageRpc interface with
      /**
       * Aborts the given resumable upload.
       *
       * @throws StorageException upon failure
       */
      void abort(String uploadId);
    

    to send DELETE request on the given uploadId as suggested Issue-1232

    • add new method to package private class com.google.cloud.storage.BlobWriteChannel like:
    void abort() {
        getOptions().getStorageRpcV1() .abort(getUploadId());
    }
    
    • extend com.google.cloud.storage.Storage interface with:
      /**
       * Aborts resumeable upload. Further attempts to write to or close the channel will result in
       * StorageException with the code 499.
       *
       * @param channel an instance crated either by {@link #writer(BlobInfo, BlobWriteOption...)}
       *                or by {@link #writer(URL)} method.
       * @throws IllegalArgumentException if inappropriate channel is given
       * @throws StorageException upon failure
       */
      public void abort(WriteChannel channel) {
        if (!(channel instanceof BlobWriteChannel)) {
          throw new IllegalArgumentException("channel is not created by Storage");
        }
        BlobWriteChannel blobWriteChannel = (BlobWriteChannel)channel;
        blobWriteChannel.abort();
      }
    
  4. frankyn commented on Jun 24, 2020

    @frankyn
    ContributorAuthor

    I wanted abort to be part of WriteChannel interface but it may not make sense for all libraries that support this interface.

    Could you review this open question?

    Changes to StorageRpc do look okay, but would make the name specific to resumable upload sessions.

    // com.google.cloud.storage.spi.v1.StorageRpc
    void abortResumableUpload(String uploadId)
  5. dmitry-fa commented on Jun 24, 2020

    @dmitry-fa

    @frankyn,

    I wanted abort to be part of WriteChannel interface but it may not make sense for all libraries that support this interface.

    I thought WriteChannel is a too generic interface to contain abort() method and didn't plan to extend it.
    After your words, I reviewed the spec and found interesting facts:

    • WriteChannel implements Closable
    • Implementations of this class may further buffer data internally to reduce remote calls. Written data might not be visible until calling Channel.close().

    So adding abort() will make sense to tell close() that it's not needed anymore to flush buffered data when close() method is called on the channel.

  6. frankyn commented on Jun 25, 2020

    @frankyn
    ContributorAuthor

    I think you'll need to submit a proposal to the interface to see if it's acceptable to add abort(). Could you follow-up on that?

  7. dmitry-fa commented on Jun 25, 2020

    @dmitry-fa

    @frankyn Yes, I will work on this.

  8. dmitry-fa commented on Jun 26, 2020

    @dmitry-fa

    @frankyn, this is the proposal: #9101

  9. dmitry-fa commented on Oct 28, 2020

    @dmitry-fa

    Thoughts and suggestions:

    • Why abort is required?
      Aborting is required when the user decides in the middle of uploading that the blob should not be updated/created. Now when an instance of WriteChannel for a blob is created the close() method will be called eventually on the instance, this will cause the blob update/create. The server side already supports DELETE command on the upload URL, but this command is currently not available in the Java client.

    • How abort functionality could be added to the Java client?
      The StorageRpc interface should be extended with a new method like void abort(String uploadId). Then an abort() method should be added to the BlobWriteChannel class. The current problem is BlobWriteChannel has a package-private access and we need to decide how to make this method visible for users. Possible suggestions with pros/cons:

      • Extend global WriteChannel interface as suggested in feat: Add abort() to WriteChannel interface #9101
        +: seems the most logical solution
        -: extending interface is an incompatible change
        -: might take a while to get approval/implement
        -: could be not needed for other extensions of WriteChannel
      • Make BlobWriteChannel/BlobReaderChannel public
        +: doesn't break API
        -: exposes extra API
      • Temporary solution: declare Storage.abort(WriteChannel) method (as proposed in feat: Add abort() to writer java-storage#460)
        +: doesn't break API
        +: could be implemented quickly
        -: extends overloaded Storage interface
  10. changed the title [-]Add abort() to writer[/-] [+][java-storage] Add abort() to writer[/+] on Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api: storageIssues related to the Cloud Storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions