Reason for failure in MultipartObjectAssembler OCI object storage

454 Views Asked by At

I'm using MultipartObjectAssembler to upload data from a Database to OCI object storage. Is there a way to know the reason for failure when using multipart upload?

When I try to commit assembler I'm getting IllegalStateException with the message "One or more parts were have not completed upload successfully". I would like to know why any part got failed? I couldn't find a way to get this information from SDK.

try {
    assembler.addPart(new ByteArrayInputStream(part, 0, length),
                    length,
                    null);

    assembler.commit();
} catch (Exception e) {
    assembler.abort();
    throw new RuntimeException(e.getMessage());
} 

Edit: I need to get an Exception thrown by a failed part and propagate the error message.

1

There are 1 best solutions below

4
Mathias Ricken On

Is there a reason you are not using the UploadManager? It should do everything for you, including adding parts and committing. Here's an end-to-end example: https://github.com/oracle/oci-java-sdk/blob/master/bmc-examples/src/main/java/UploadObjectExample.java

If, for some reason, you cannot use UploadManager, please take a look at its source code nonetheless, since it demonstrates the intended usage of MultipartObjectAssembler: https://github.com/oracle/oci-java-sdk/blob/master/bmc-objectstorage/bmc-objectstorage-extensions/src/main/java/com/oracle/bmc/objectstorage/transfer/UploadManager.java#L175-L249

  1. You create the MultipartObjectAssembler:
MultipartObjectAssembler assembler =
                createAssembler(request, uploadRequest, executorServiceToUse);
  1. You create a new request. This gives you back a MultipartManifest, which will later let you check if parts failed.
manifest =
                    assembler.newRequest(
                            request.getContentType(),
                            request.getContentLanguage(),
                            request.getContentEncoding(),
                            request.getOpcMeta());
  1. Then you add all the parts:
                    assembler.addPart(
                            ProgressTrackingInputStreamFactory.create(
                                    chunk, progressTrackerFactory.getProgressTracker()),
                            chunk.length(),
                            null);
  1. Then you commit. This is where your code currently throws. I suspect not all parts have been added.
CommitMultipartUploadResponse response = assembler.commit();
  1. If something goes wrong, check MultipartManifest.listCompletedParts(), MultipartManifest.listFailedParts(), and MultipartManifest.listInProgressParts(). The manifest should tell you what parts failed. Unfortunately not why; for that, you can enable ERROR level logging for com.oracle.bmc.objectstorage.transfer (for the class com.oracle.bmc.objectstorage.transfer.internal.MultipartTransferManager in particular).

If I have misunderstood something, please let me know. In that case, a larger, more complete code snippet would help me debug. Thanks!