diff --git a/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/s3partition/S3PartitionCreatorScheduler.java b/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/s3partition/S3PartitionCreatorScheduler.java index e7c5841332..6e46dd8a54 100644 --- a/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/s3partition/S3PartitionCreatorScheduler.java +++ b/data-prepper-plugins/mongodb/src/main/java/org/opensearch/dataprepper/plugins/mongo/s3partition/S3PartitionCreatorScheduler.java @@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Optional; @@ -46,12 +47,14 @@ public void run() { break; } - collections.forEach(collection -> { + final Iterator iterator = collections.iterator(); + while(iterator.hasNext()) { + final String collection = iterator.next(); final Optional s3PartitionStatus = getGlobalS3FolderCreationStatus(collection); if (s3PartitionStatus.isPresent()) { - collections.remove(collection); + iterator.remove(); } - }); + } if (collections.isEmpty()) { LOG.info("The S3 folder partition global state created for all collections."); @@ -68,7 +71,6 @@ public void run() { } } } - LOG.warn("S3 partition creator scheduler interrupted, looks like shutdown has triggered"); } private List createS3BucketPartitions(int partitionCount) {