client lock should not be static
@@ -55,13 +55,12 @@ import org.apache.tika.utils.StringUtils;
* Fetches files from s3. Example file: s3://my_bucket/path/to/my_file.pdf
* The bucket must be specified via the tika-config or before
* initialization, and the fetch key is "path/to/my_file.pdf".
- * This will parse the bucket out of that string and retrieve the path.
*/
public class S3Fetcher extends AbstractFetcher implements Initializable, RangeFetcher {
private static final Logger LOGGER = LoggerFactory.getLogger(S3Fetcher.class);
private static final String PREFIX = "s3";
- private static final Object[] LOCK = new Object[0];
+ private final Object[] clientLock = new Object[0];
private String region;
private String bucket;
private String profile;
@@ -106,7 +105,11 @@ public class S3Fetcher extends AbstractFetcher implements Initializable, RangeFe
initialize(new HashMap<>());
}
try {
- return _fetch(theFetchKey, metadata, startRange, endRange);
+ long start = System.currentTimeMillis();
+ InputStream is = _fetch(theFetchKey, metadata, startRange, endRange);
+ long elapsed = System.currentTimeMillis() - start;
+ LOGGER.debug("total to fetch {}", elapsed);
+ return is;
} catch (AmazonClientException e ) {
//TODO -- filter exceptions -- if the file doesn't exist, don't retry
LOGGER.warn("client exception fetching on retry=" + tries, e);
@@ -124,15 +127,17 @@ public class S3Fetcher extends AbstractFetcher implements Initializable, RangeFe
Long startRange, Long endRange) throws IOException {
TemporaryResources tmp = null;
try {
+ long start = System.currentTimeMillis();
GetObjectRequest objectRequest = new GetObjectRequest(bucket, fetchKey);
if (startRange != null && endRange != null
&& startRange > -1 && endRange > -1) {
objectRequest.withRange(startRange, endRange);
}
S3Object s3Object = null;
- synchronized (LOCK) {
+ synchronized (clientLock) {
s3Object = s3Client.getObject(objectRequest);
}
+
if (extractUserMetadata) {
for (Map.Entry<String, String> e : s3Object.getObjectMetadata().getUserMetadata()
.entrySet()) {
@@ -142,13 +147,12 @@ public class S3Fetcher extends AbstractFetcher implements Initializable, RangeFe
if (!spoolToTemp) {
return TikaInputStream.get(s3Object.getObjectContent());
} else {
- long start = System.currentTimeMillis();
+ start = System.currentTimeMillis();
tmp = new TemporaryResources();
Path tmpPath = tmp.createTempFile();
Files.copy(s3Object.getObjectContent(), tmpPath, StandardCopyOption.REPLACE_EXISTING);
TikaInputStream tis = TikaInputStream.get(tmpPath, metadata, tmp);
- long elapsed = System.currentTimeMillis() - start;
- LOGGER.debug("took {} ms to copy to local tmp file", elapsed);
+ LOGGER.debug("took {} ms to copy to local tmp file", System.currentTimeMillis() - start);
return tis;
}
} catch (Throwable e) {
@@ -243,7 +247,7 @@ public class S3Fetcher extends AbstractFetcher implements Initializable, RangeFe
ClientConfiguration clientConfiguration = new ClientConfiguration()
.withMaxConnections(maxConnections);
try {
- synchronized (LOCK) {
+ synchronized (clientLock) {
s3Client = AmazonS3ClientBuilder.standard()
.withClientConfiguration(clientConfiguration)
.withRegion(region)
