Skip to content

Commit

Permalink
FIX: Infinity waiting with get method in BulkGetFuture.
Browse files Browse the repository at this point in the history
  • Loading branch information
brido4125 committed Aug 10, 2023
1 parent d731a06 commit bbe2cfb
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main/java/net/spy/memcached/internal/BulkGetFuture.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import net.spy.memcached.ops.Operation;
import net.spy.memcached.ops.OperationState;

import static net.spy.memcached.DefaultConnectionFactory.DEFAULT_OPERATION_TIMEOUT;

/**
* Future for handling results from bulk gets.
*
Expand All @@ -43,7 +45,7 @@ public class BulkGetFuture<T> implements BulkFuture<Map<String, T>> {
private final Map<String, Future<T>> rvMap;
private final Collection<Operation> ops;
private final CountDownLatch latch;
private boolean timeout = false;
private boolean isTimeout = false;

public BulkGetFuture(Map<String, Future<T>> m,
Collection<Operation> getOps, CountDownLatch l) {
Expand Down Expand Up @@ -72,7 +74,7 @@ public boolean cancel(boolean ign) {
@Override
public Map<String, T> get() throws InterruptedException, ExecutionException {
try {
return get(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
return get(DEFAULT_OPERATION_TIMEOUT * ops.size(), TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
throw new OperationTimeoutException(e);
}
Expand All @@ -84,7 +86,7 @@ public Map<String, T> getSome(long duration, TimeUnit units)
Collection<Operation> timedoutOps = new HashSet<Operation>();
Map<String, T> ret = internalGet(duration, units, timedoutOps);
if (timedoutOps.size() > 0) {
timeout = true;
isTimeout = true;
LoggerFactory.getLogger(getClass()).warn(
new CheckedOperationTimeoutException(duration, units, timedoutOps).getMessage());
}
Expand All @@ -104,7 +106,7 @@ public Map<String, T> get(long duration, TimeUnit units)
Collection<Operation> timedoutOps = new HashSet<Operation>();
Map<String, T> ret = internalGet(duration, units, timedoutOps);
if (timedoutOps.size() > 0) {
this.timeout = true;
this.isTimeout = true;
throw new CheckedOperationTimeoutException(duration, units, timedoutOps);
}
return ret;
Expand Down Expand Up @@ -177,6 +179,6 @@ private Map<String, T> internalGet(long to, TimeUnit unit,
* @see net.spy.memcached.internal.BulkFuture#isTimeout()
*/
public boolean isTimeout() {
return timeout;
return isTimeout;
}
}

0 comments on commit bbe2cfb

Please sign in to comment.