adarshsanjeev commented on code in PR #12874: URL: https://github.com/apache/druid/pull/12874#discussion_r941141475
########## extensions-core/s3-extensions/src/main/java/org/apache/druid/storage/s3/output/RetriableS3OutputStream.java: ########## @@ -0,0 +1,432 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.storage.s3.output; + +import com.amazonaws.AmazonServiceException; +import com.amazonaws.services.s3.model.AbortMultipartUploadRequest; +import com.amazonaws.services.s3.model.CompleteMultipartUploadRequest; +import com.amazonaws.services.s3.model.InitiateMultipartUploadRequest; +import com.amazonaws.services.s3.model.InitiateMultipartUploadResult; +import com.amazonaws.services.s3.model.ObjectMetadata; +import com.amazonaws.services.s3.model.PartETag; +import com.amazonaws.services.s3.model.UploadPartRequest; +import com.amazonaws.services.s3.model.UploadPartResult; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Joiner; +import com.google.common.base.Stopwatch; +import com.google.common.io.CountingOutputStream; +import it.unimi.dsi.fastutil.io.FastBufferedOutputStream; +import org.apache.druid.java.util.common.FileUtils; +import org.apache.druid.java.util.common.IAE; +import org.apache.druid.java.util.common.IOE; +import org.apache.druid.java.util.common.RetryUtils; +import org.apache.druid.java.util.common.io.Closer; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.storage.s3.S3Utils; +import org.apache.druid.storage.s3.ServerSideEncryptingAmazonS3; + +import java.io.Closeable; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +/** + * A retriable output stream for s3. How it works is, + * <p> + * 1) When new data is written, it first creates a chunk in local disk. + * 2) New data is written to the local chunk until it is full. + * 3) When the chunk is full, it uploads the chunk to s3 using the multipart upload API. + * Since this happens synchronously, {@link #write(byte[], int, int)} can be blocked until the upload is done. + * The upload can be retries when it fails with transient errors. + * 4) Once the upload succeeds, it creates a new chunk and continue. + * 5) When the stream is closed, it uploads the last chunk and finalize the multipart upload. + * {@link #close()} can be blocked until upload is done. + * <p> + * For compression format support, this output stream supports compression formats if they are <i>concatenatable</i>, + * such as ZIP or GZIP. + * <p> + * This class is not thread-safe. + * <p> + * This class can be moved to the s3 extension as a low-level API, + * whereas it currently provides only high-level APIs such as S3DataSegmentPuller. + */ +public class RetriableS3OutputStream extends OutputStream Review Comment: nit: I think we can stick to "Retryable" everywhere since that seems to be the current convention -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
