jtuglu1 commented on code in PR #18891: URL: https://github.com/apache/druid/pull/18891#discussion_r2792457074
########## extensions-core/s3-extensions/src/main/java/org/apache/druid/storage/s3/ObjectSummaryWithBucketIterator.java: ########## @@ -0,0 +1,170 @@ +/* + * 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; + +import org.apache.druid.java.util.common.RE; +import software.amazon.awssdk.services.s3.model.ListObjectsV2Request; +import software.amazon.awssdk.services.s3.model.ListObjectsV2Response; +import software.amazon.awssdk.services.s3.model.S3Exception; +import software.amazon.awssdk.services.s3.model.S3Object; + +import java.net.URI; +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + * Iterator that returns S3 objects along with their bucket names. + * This is needed because AWS SDK v2's S3Object doesn't include the bucket name. + */ +public class ObjectSummaryWithBucketIterator implements Iterator<S3Utils.S3ObjectWithBucket> +{ + private final ServerSideEncryptingAmazonS3 s3Client; + private final Iterator<URI> prefixesIterator; + private final int maxListingLength; + private final int maxRetries; + + private String currentBucket; + private String currentPrefix; + private String continuationToken; + private ListObjectsV2Response result; + private Iterator<S3Object> objectSummaryIterator; + private S3Utils.S3ObjectWithBucket currentObjectSummary; + + ObjectSummaryWithBucketIterator( + final ServerSideEncryptingAmazonS3 s3Client, + final Iterable<URI> prefixes, + final int maxListingLength, + final int maxRetries + ) + { + this.s3Client = s3Client; + this.prefixesIterator = prefixes.iterator(); + this.maxListingLength = maxListingLength; + this.maxRetries = maxRetries; + + prepareNextRequest(); Review Comment: I've moved out of ctor and into an initialize method. Iterators are expected to be single-threaded access, I'll make it thread-safe just in case. ########## extensions-core/s3-extensions/src/main/java/org/apache/druid/storage/s3/ObjectSummaryWithBucketIterator.java: ########## @@ -0,0 +1,170 @@ +/* + * 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; + +import org.apache.druid.java.util.common.RE; +import software.amazon.awssdk.services.s3.model.ListObjectsV2Request; +import software.amazon.awssdk.services.s3.model.ListObjectsV2Response; +import software.amazon.awssdk.services.s3.model.S3Exception; +import software.amazon.awssdk.services.s3.model.S3Object; + +import java.net.URI; +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + * Iterator that returns S3 objects along with their bucket names. + * This is needed because AWS SDK v2's S3Object doesn't include the bucket name. + */ +public class ObjectSummaryWithBucketIterator implements Iterator<S3Utils.S3ObjectWithBucket> +{ + private final ServerSideEncryptingAmazonS3 s3Client; + private final Iterator<URI> prefixesIterator; + private final int maxListingLength; + private final int maxRetries; + + private String currentBucket; + private String currentPrefix; + private String continuationToken; + private ListObjectsV2Response result; + private Iterator<S3Object> objectSummaryIterator; + private S3Utils.S3ObjectWithBucket currentObjectSummary; + + ObjectSummaryWithBucketIterator( + final ServerSideEncryptingAmazonS3 s3Client, + final Iterable<URI> prefixes, + final int maxListingLength, + final int maxRetries + ) + { + this.s3Client = s3Client; + this.prefixesIterator = prefixes.iterator(); + this.maxListingLength = maxListingLength; + this.maxRetries = maxRetries; + + prepareNextRequest(); Review Comment: I've moved out of ctor and into an initialize method. Iterators are expected to be single-threaded access, I'll make the initialized indicator thread-safe just in case. -- 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]
