|
@@ -21,13 +21,13 @@ package org.apache.hadoop.fs.common;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.nio.ByteBuffer;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.Future;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.function.Supplier;
|
|
|
|
|
|
-import com.twitter.util.Await;
|
|
|
-import com.twitter.util.ExceptionalFunction0;
|
|
|
-import com.twitter.util.Future;
|
|
|
-import com.twitter.util.FuturePool;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
@@ -37,9 +37,10 @@ import org.slf4j.LoggerFactory;
|
|
|
*/
|
|
|
public abstract class CachingBlockManager extends BlockManager {
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(CachingBlockManager.class);
|
|
|
+ private static final int TIMEOUT_MINUTES = 60;
|
|
|
|
|
|
// Asynchronous tasks are performed in this pool.
|
|
|
- private final FuturePool futurePool;
|
|
|
+ private final ExecutorServiceFuturePool futurePool;
|
|
|
|
|
|
// Pool of shared ByteBuffer instances.
|
|
|
private BufferPool bufferPool;
|
|
@@ -78,7 +79,7 @@ public abstract class CachingBlockManager extends BlockManager {
|
|
|
* @throws IllegalArgumentException if bufferPoolSize is zero or negative.
|
|
|
*/
|
|
|
public CachingBlockManager(
|
|
|
- FuturePool futurePool,
|
|
|
+ ExecutorServiceFuturePool futurePool,
|
|
|
BlockData blockData,
|
|
|
int bufferPoolSize) {
|
|
|
super(blockData);
|
|
@@ -247,7 +248,7 @@ public abstract class CachingBlockManager extends BlockManager {
|
|
|
|
|
|
BlockOperations.Operation op = this.ops.requestPrefetch(blockNumber);
|
|
|
PrefetchTask prefetchTask = new PrefetchTask(data, this);
|
|
|
- Future<Void> prefetchFuture = this.futurePool.apply(prefetchTask);
|
|
|
+ Future<Void> prefetchFuture = this.futurePool.executeFunction(prefetchTask);
|
|
|
data.setPrefetch(prefetchFuture);
|
|
|
this.ops.end(op);
|
|
|
}
|
|
@@ -344,7 +345,7 @@ public abstract class CachingBlockManager extends BlockManager {
|
|
|
/**
|
|
|
* Read task that is submitted to the future pool.
|
|
|
*/
|
|
|
- private static class PrefetchTask extends ExceptionalFunction0<Void> {
|
|
|
+ private static class PrefetchTask implements Supplier<Void> {
|
|
|
private final BufferData data;
|
|
|
private final CachingBlockManager blockManager;
|
|
|
|
|
@@ -354,7 +355,7 @@ public abstract class CachingBlockManager extends BlockManager {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Void applyE() {
|
|
|
+ public Void get() {
|
|
|
try {
|
|
|
this.blockManager.prefetch(data);
|
|
|
} catch (Exception e) {
|
|
@@ -412,11 +413,13 @@ public abstract class CachingBlockManager extends BlockManager {
|
|
|
if (state == BufferData.State.PREFETCHING) {
|
|
|
blockFuture = data.getActionFuture();
|
|
|
} else {
|
|
|
- blockFuture = Future.value(null);
|
|
|
+ CompletableFuture<Void> cf = new CompletableFuture<>();
|
|
|
+ cf.complete(null);
|
|
|
+ blockFuture = cf;
|
|
|
}
|
|
|
|
|
|
CachePutTask task = new CachePutTask(data, blockFuture, this);
|
|
|
- Future<Void> actionFuture = this.futurePool.apply(task);
|
|
|
+ Future<Void> actionFuture = this.futurePool.executeFunction(task);
|
|
|
data.setCaching(actionFuture);
|
|
|
this.ops.end(op);
|
|
|
}
|
|
@@ -433,14 +436,13 @@ public abstract class CachingBlockManager extends BlockManager {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
- Await.result(blockFuture);
|
|
|
+ blockFuture.get(TIMEOUT_MINUTES, TimeUnit.MINUTES);
|
|
|
if (data.stateEqualsOneOf(BufferData.State.DONE)) {
|
|
|
// There was an error during prefetch.
|
|
|
return;
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- String message = String.format("error waitng on blockFuture: %s", data);
|
|
|
- LOG.error(message, e);
|
|
|
+ LOG.error("error waiting on blockFuture: {}", data, e);
|
|
|
data.setDone();
|
|
|
return;
|
|
|
}
|
|
@@ -500,7 +502,7 @@ public abstract class CachingBlockManager extends BlockManager {
|
|
|
this.cache.put(blockNumber, buffer);
|
|
|
}
|
|
|
|
|
|
- private static class CachePutTask extends ExceptionalFunction0<Void> {
|
|
|
+ private static class CachePutTask implements Supplier<Void> {
|
|
|
private final BufferData data;
|
|
|
|
|
|
// Block being asynchronously fetched.
|
|
@@ -519,7 +521,7 @@ public abstract class CachingBlockManager extends BlockManager {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Void applyE() {
|
|
|
+ public Void get() {
|
|
|
this.blockManager.addToCacheAndRelease(this.data, this.blockFuture);
|
|
|
return null;
|
|
|
}
|