mirror of https://github.com/apache/jclouds.git
Some handles were not properly closed
This commit is contained in:
parent
7cde28a4d2
commit
de68c2a1b0
|
@ -41,6 +41,7 @@ import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
|
@ -76,6 +77,7 @@ import org.jclouds.io.ContentMetadata;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.io.PayloadSlicer;
|
import org.jclouds.io.PayloadSlicer;
|
||||||
import org.jclouds.io.payloads.ByteSourcePayload;
|
import org.jclouds.io.payloads.ByteSourcePayload;
|
||||||
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.openstack.swift.v1.SwiftApi;
|
import org.jclouds.openstack.swift.v1.SwiftApi;
|
||||||
import org.jclouds.openstack.swift.v1.blobstore.functions.ToBlobMetadata;
|
import org.jclouds.openstack.swift.v1.blobstore.functions.ToBlobMetadata;
|
||||||
import org.jclouds.openstack.swift.v1.blobstore.functions.ToListContainerOptions;
|
import org.jclouds.openstack.swift.v1.blobstore.functions.ToListContainerOptions;
|
||||||
|
@ -89,6 +91,7 @@ import org.jclouds.openstack.swift.v1.features.BulkApi;
|
||||||
import org.jclouds.openstack.swift.v1.features.ObjectApi;
|
import org.jclouds.openstack.swift.v1.features.ObjectApi;
|
||||||
import org.jclouds.openstack.swift.v1.options.UpdateContainerOptions;
|
import org.jclouds.openstack.swift.v1.options.UpdateContainerOptions;
|
||||||
import org.jclouds.openstack.swift.v1.reference.SwiftHeaders;
|
import org.jclouds.openstack.swift.v1.reference.SwiftHeaders;
|
||||||
|
import org.jclouds.util.Closeables2;
|
||||||
|
|
||||||
import com.google.common.annotations.Beta;
|
import com.google.common.annotations.Beta;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
@ -152,6 +155,9 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
|
||||||
protected final PayloadSlicer slicer;
|
protected final PayloadSlicer slicer;
|
||||||
protected final ListeningExecutorService userExecutor;
|
protected final ListeningExecutorService userExecutor;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
protected Logger logger = Logger.NULL;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends Location> listAssignableLocations() {
|
public Set<? extends Location> listAssignableLocations() {
|
||||||
return ImmutableSet.of(region);
|
return ImmutableSet.of(region);
|
||||||
|
@ -701,14 +707,11 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
|
||||||
Futures.getUnchecked(Futures.allAsList(results));
|
Futures.getUnchecked(Futures.allAsList(results));
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// cleanup, attempt to delete large file
|
Closeables2.closeQuietly(raf);
|
||||||
if (raf != null) {
|
|
||||||
try {
|
|
||||||
raf.close();
|
|
||||||
} catch (IOException e1) {}
|
|
||||||
}
|
|
||||||
destination.delete();
|
destination.delete();
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
Closeables2.closeQuietly(raf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -798,7 +801,7 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
|
||||||
long from;
|
long from;
|
||||||
for (from = 0; from < contentLength; from = from + partSize) {
|
for (from = 0; from < contentLength; from = from + partSize) {
|
||||||
try {
|
try {
|
||||||
System.out.println(Thread.currentThread() + " writing to output");
|
logger.debug(Thread.currentThread() + " writing to output");
|
||||||
result = results.take();
|
result = results.take();
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
output.close();
|
output.close();
|
||||||
|
@ -807,7 +810,7 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
|
||||||
}
|
}
|
||||||
output.write(result.get());
|
output.write(result.get());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(e);
|
logger.debug(e.toString());
|
||||||
try {
|
try {
|
||||||
// close pipe so client is notified of an exception
|
// close pipe so client is notified of an exception
|
||||||
input.close();
|
input.close();
|
||||||
|
@ -819,10 +822,7 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Finished writing results to stream
|
// Finished writing results to stream
|
||||||
try {
|
Closeables2.closeQuietly(output);
|
||||||
output.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -866,7 +866,7 @@ public class RegionScopedSwiftBlobStore implements BlobStore {
|
||||||
byte[] downloadedBlock = ByteStreams.toByteArray(object.getPayload().openStream());
|
byte[] downloadedBlock = ByteStreams.toByteArray(object.getPayload().openStream());
|
||||||
return downloadedBlock;
|
return downloadedBlock;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.out.println(e);
|
logger.debug(e.toString());
|
||||||
lastException = e;
|
lastException = e;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ import org.jclouds.blobstore.BlobStore;
|
||||||
import org.jclouds.blobstore.domain.Blob;
|
import org.jclouds.blobstore.domain.Blob;
|
||||||
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
import org.jclouds.blobstore.integration.internal.BaseBlobStoreIntegrationTest;
|
||||||
import org.jclouds.io.payloads.FilePayload;
|
import org.jclouds.io.payloads.FilePayload;
|
||||||
|
import org.jclouds.util.Closeables2;
|
||||||
import org.testng.annotations.AfterClass;
|
import org.testng.annotations.AfterClass;
|
||||||
import org.testng.annotations.BeforeClass;
|
import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -147,24 +148,28 @@ public class RegionScopedSwiftBlobStoreParallelLiveTest extends BaseBlobStoreInt
|
||||||
|
|
||||||
// Reserve space for performance reasons
|
// Reserve space for performance reasons
|
||||||
raf = new RandomAccessFile(file.getAbsoluteFile(), "rw");
|
raf = new RandomAccessFile(file.getAbsoluteFile(), "rw");
|
||||||
raf.seek(size - 1);
|
try {
|
||||||
raf.write(0);
|
raf.seek(size - 1);
|
||||||
|
raf.write(0);
|
||||||
|
|
||||||
// Loop through ranges within the file
|
// Loop through ranges within the file
|
||||||
long from;
|
long from;
|
||||||
long to;
|
long to;
|
||||||
long partSize = 1000000;
|
long partSize = 1000000;
|
||||||
|
|
||||||
ExecutorService threadPool = Executors.newFixedThreadPool(16);
|
ExecutorService threadPool = Executors.newFixedThreadPool(16);
|
||||||
|
|
||||||
for (from = 0; from < size; from = from + partSize) {
|
for (from = 0; from < size; from = from + partSize) {
|
||||||
to = (from + partSize >= size) ? size - 1 : from + partSize - 1;
|
to = (from + partSize >= size) ? size - 1 : from + partSize - 1;
|
||||||
RandomFileWriter writer = new RandomFileWriter(raf, from, to);
|
RandomFileWriter writer = new RandomFileWriter(raf, from, to);
|
||||||
threadPool.submit(writer);
|
threadPool.submit(writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
threadPool.shutdown();
|
||||||
|
threadPool.awaitTermination(1, TimeUnit.DAYS);
|
||||||
|
} finally {
|
||||||
|
Closeables2.closeQuietly(raf);
|
||||||
}
|
}
|
||||||
|
|
||||||
threadPool.shutdown();
|
|
||||||
threadPool.awaitTermination(1, TimeUnit.DAYS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private final class RandomFileWriter implements Runnable {
|
private final class RandomFileWriter implements Runnable {
|
||||||
|
|
Loading…
Reference in New Issue