ZHr-UChiHa opened a new issue, #18536:
URL: https://github.com/apache/pulsar/issues/18536

   ### Search before asking
   
   - [X] I searched in the [issues](https://github.com/apache/pulsar/issues) 
and found nothing similar.
   
   
   ### Version
   
   2.10.1
   
   ### Minimal reproduce step
   
   S3 service use huawei cloud obs service,
   BlobStoreManagedLedgerOffloader#offload      line: 214 
   when trigger offload, blockStream will close both 
writeBlobStore.uploadMultipartPart(mpu, partId, partPayload) and try 
(BlockAwareSegmentInputStream blockStream = new 
BlockAwareSegmentInputStreamImpl(
                           readHandle, startEntry, blockSize)) will close 
blockStream, when finish try blockStream.close will throw exception
   Illegal ReferenceCountException: refCnt: 0, decrement: 1
   code:
        try {
                   long startEntry = 0;
                   int partId = 1;
                   long entryBytesWritten = 0;
                   while (startEntry <= readHandle.getLastAddConfirmed()) {
                       int blockSize = BlockAwareSegmentInputStreamImpl
                           .calculateBlockSize(config.getMaxBlockSizeInBytes(), 
readHandle, startEntry, entryBytesWritten);
   
                       try (BlockAwareSegmentInputStream blockStream = new 
BlockAwareSegmentInputStreamImpl(
                           readHandle, startEntry, blockSize)) {
   
                           Payload partPayload = 
Payloads.newInputStreamPayload(blockStream);
                           
partPayload.getContentMetadata().setContentLength((long) blockSize);
                           
partPayload.getContentMetadata().setContentType("application/octet-stream");
                           parts.add(writeBlobStore.uploadMultipartPart(mpu, 
partId, partPayload));
                           log.debug("UploadMultipartPart. container: {}, 
blobName: {}, partId: {}, mpu: {}",
                                   config.getBucket(), dataBlockKey, partId, 
mpu.id());
   
                           indexBuilder.addBlock(startEntry, partId, blockSize);
   
                           if (blockStream.getEndEntryId() != -1) {
                               startEntry = blockStream.getEndEntryId() + 1;
                           } else {
                               // could not read entry from ledger.
                               break;
                           }
                           entryBytesWritten += 
blockStream.getBlockEntryBytesCount();
                           partId++;
                       }
   
                       dataObjectLength += blockSize;
                   }
   
                   writeBlobStore.completeMultipartUpload(mpu, parts);
                   mpu = null;
               } catch (Throwable t) {
                   try {
                       if (mpu != null) {
                           writeBlobStore.abortMultipartUpload(mpu);
                       }
                   } catch (Throwable throwable) {
                       log.error("Failed abortMultipartUpload in bucket - {} 
with key - {}, uploadId - {}.",
                               config.getBucket(), dataBlockKey, mpu.id(), 
throwable);
                   }
                   promise.completeExceptionally(t);
                   return;
               }
   
![image](https://user-images.githubusercontent.com/54945799/202666728-7d2ed7a7-4099-438a-9d74-12b98b40262c.png)
   
   
   ### What did you expect to see?
   
   no exception occurs, ledger log send to obs file success, but actually when 
send part file sucess once, code throw exception lead to delete uploaded file 
in catch exception code.
   
   ### What did you see instead?
   
   no exception occurs, ledger log send to obs file success, but actually when 
send part file sucess once, code throw exception lead to delete uploaded file 
in catch exception code.
   
   ### Anything else?
   
   _No response_
   
   ### Are you willing to submit a PR?
   
   - [X] I'm willing to submit a PR!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to