You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@celeborn.apache.org by GitBox <gi...@apache.org> on 2022/12/20 08:08:14 UTC
[GitHub] [incubator-celeborn] waitinfuture commented on a diff in pull request #1097: [CELEBORN-119] Add timeout for pushdata
waitinfuture commented on code in PR #1097:
URL: https://github.com/apache/incubator-celeborn/pull/1097#discussion_r1053013262
##########
client/src/main/java/org/apache/celeborn/client/write/PushState.java:
##########
@@ -29,42 +27,98 @@
import org.slf4j.LoggerFactory;
import org.apache.celeborn.common.CelebornConf;
+import org.apache.celeborn.common.network.client.RpcResponseCallback;
import org.apache.celeborn.common.protocol.PartitionLocation;
+import org.apache.celeborn.common.protocol.message.StatusCode;
public class PushState {
+ class BatchInfo {
+ PartitionLocation partitionLocation;
+ ChannelFuture channelFuture;
+ long pushTime;
+ RpcResponseCallback callback;
+ }
+
private static final Logger logger = LoggerFactory.getLogger(PushState.class);
private int pushBufferMaxSize;
+ private long pushTimeout;
public final AtomicInteger batchId = new AtomicInteger();
- public final ConcurrentHashMap<Integer, PartitionLocation> inFlightBatches =
+ private final ConcurrentHashMap<Integer, BatchInfo> inflightBatchInfos =
new ConcurrentHashMap<>();
- public final ConcurrentHashMap<Integer, ChannelFuture> futures = new ConcurrentHashMap<>();
public AtomicReference<IOException> exception = new AtomicReference<>();
public PushState(CelebornConf conf) {
pushBufferMaxSize = conf.pushBufferMaxSize();
+ pushTimeout = conf.pushDataTimeoutMs();
+ }
+
+ public void addBatch(int batchId, PartitionLocation partitionLocation) {
+ BatchInfo info = inflightBatchInfos.computeIfAbsent(batchId, id -> new BatchInfo());
+ info.partitionLocation = partitionLocation;
+ }
+
+ public synchronized void removeBatch(int batchId) {
+ BatchInfo info = inflightBatchInfos.remove(batchId);
+ if (info.channelFuture != null) {
+ info.channelFuture.cancel(true);
+ }
}
- public void addFuture(int batchId, ChannelFuture future) {
- futures.put(batchId, future);
+ public int inflightBatchCount() {
+ return inflightBatchInfos.size();
}
- public void removeFuture(int batchId) {
- futures.remove(batchId);
+ public synchronized void failExpiredBatch() {
+ long currentTime = System.currentTimeMillis();
+ inflightBatchInfos
+ .values()
+ .forEach(
+ info -> {
+ if (currentTime - info.pushTime > pushTimeout) {
+ if (info.channelFuture != null) {
+ info.channelFuture.cancel(true);
+ info.callback.onFailure(
+ new IOException(StatusCode.PUSH_DATA_TIMEOUT.getMessage()));
+ info.channelFuture = null;
+ info.callback = null;
+ }
+ }
+ });
+ }
+
+ public synchronized void addFuture(
+ int batchId, ChannelFuture future, RpcResponseCallback callback) {
+ BatchInfo info = inflightBatchInfos.get(batchId);
+ if (info != null) {
+ info.pushTime = System.currentTimeMillis();
+ info.channelFuture = future;
+ info.callback = callback;
+ }
+ }
+
+ public synchronized void removeFuture(int batchId) {
+ BatchInfo info = inflightBatchInfos.get(batchId);
+ if (info != null) {
Review Comment:
Currently only callback.onFailure will call removeFuture, and seems when it comes to onFailure, the future should be already complete. I just delete the method.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@celeborn.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org