Add retry when checking s3 bucket

This commit is contained in:
xuzha 2015-08-04 00:25:04 -07:00
parent 8fe5d903b7
commit 333ca689d3
1 changed files with 18 additions and 5 deletions

View File

@ -77,11 +77,24 @@ public class S3BlobStore extends AbstractComponent implements BlobStore {
// Also, if invalid security credentials are used to execute this method, the // Also, if invalid security credentials are used to execute this method, the
// client is not able to distinguish between bucket permission errors and // client is not able to distinguish between bucket permission errors and
// invalid credential errors, and this method could return an incorrect result. // invalid credential errors, and this method could return an incorrect result.
if (!client.doesBucketExist(bucket)) { int retry = 0;
if (region != null) { while (retry <= maxRetries) {
client.createBucket(bucket, region); try {
} else { if (!client.doesBucketExist(bucket)) {
client.createBucket(bucket); if (region != null) {
client.createBucket(bucket, region);
} else {
client.createBucket(bucket);
}
}
break;
} catch (AmazonClientException e) {
if (shouldRetry(e) && retry < maxRetries) {
retry++;
} else {
logger.debug("S3 client create bucket failed");
throw e;
}
} }
} }
} }