diff --git a/SingularityService/src/main/java/com/hubspot/singularity/resources/S3LogResource.java b/SingularityService/src/main/java/com/hubspot/singularity/resources/S3LogResource.java index b97c964981..4f9afdb908 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/resources/S3LogResource.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/resources/S3LogResource.java @@ -328,12 +328,7 @@ public List call() throws Exception { continuationTokens.putIfAbsent(key, new ContinuationToken(result.getNextContinuationToken(), true)); return Collections.emptyList(); } else { - int newTotal = incrementIfLessThan(resultCount, result.getObjectSummaries().size(), targetResultCount); - if (newTotal != -1) { - if (newTotal > DEFAULT_TARGET_MAX_RESULTS) { - request.setMaxKeys(Math.abs(DEFAULT_TARGET_MAX_RESULTS - newTotal)); - result = s3Client.listObjectsV2(request); - } + if (incrementIfLessThan(resultCount, result.getObjectSummaries().size(), targetResultCount)) { continuationTokens.putIfAbsent(key, new ContinuationToken(result.getNextContinuationToken(), !result.isTruncated())); List objectSummaryHolders = new ArrayList<>(); for (S3ObjectSummary objectSummary : result.getObjectSummaries()) { @@ -420,14 +415,14 @@ public SingularityS3LogMetadata call() throws Exception { return Futures.allAsList(logFutures).get(s3Configuration.getWaitForS3LinksSeconds(), TimeUnit.SECONDS); } - private int incrementIfLessThan(AtomicInteger count, int add, int threshold) { + private boolean incrementIfLessThan(AtomicInteger count, int add, int threshold) { while (true) { int current = count.get(); if (current >= threshold) { - return -1; + return false; } if (count.compareAndSet(current, current + add)) { - return current + add; + return true; } } }