Cleanly Handle S3 SDK Exceptions in Request Counting (#61686) (#61698)

It looks like it is possible for a request to throw an exception early
before any API interaciton has happened. This can lead to the request count
map containing a `null` for the request count key.
The assertion is not correct and we should not NPE here
(as that might also hide the original exception since we are running this code in
a `finally` block from within the S3 SDK).

Closes #61670
This commit is contained in:
Armin Braun 2020-08-31 11:05:59 +02:00 committed by GitHub
parent 22e4d759c3
commit 0da20579ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,6 +25,8 @@ import com.amazonaws.metrics.RequestMetricCollector;
import com.amazonaws.services.s3.model.CannedAccessControlList;
import com.amazonaws.services.s3.model.StorageClass;
import com.amazonaws.util.AWSRequestMetrics;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.cluster.metadata.RepositoryMetadata;
import org.elasticsearch.common.blobstore.BlobContainer;
import org.elasticsearch.common.blobstore.BlobPath;
@ -40,6 +42,8 @@ import java.util.concurrent.atomic.AtomicLong;
class S3BlobStore implements BlobStore {
private static final Logger logger = LogManager.getLogger(S3BlobStore.class);
private final S3Service service;
private final String bucket;
@ -105,8 +109,10 @@ class S3BlobStore implements BlobStore {
private long getRequestCount(Request<?> request) {
Number requestCount = request.getAWSRequestMetrics().getTimingInfo()
.getCounter(AWSRequestMetrics.Field.RequestCount.name());
assert requestCount != null;
if (requestCount == null) {
logger.warn("Expected request count to be tracked for request [{}] but found not count.", request);
return 0L;
}
return requestCount.longValue();
}